2011-11-27 16:12:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
|
|
2011-11-27 16:12:20 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2022-03-17 05:34:47 +00:00
|
|
|
class TemplateCategoriesTest extends MediaWikiIntegrationTestCase {
|
2011-11-27 16:12:20 +00:00
|
|
|
|
objectcache: Remove $wgMainWANCache and $wgWANObjectCaches
We always wrap the local cluster cache, and there are no subclasses
of WANObjectCache. It was never documented or recommended how these
would be used. It is a left-over from the original 2015 Multi-DC plan
in which WANObjectCache would work differently. See task for details.
Note that this requires no configuration changes, even in the
theoretical case of these variables being used, as the only
option is to use the main cache, and that's also the default.
* Update WAN overrides to override the underlying main cache
instead.
* Fix EditPageTest which was previously implicitly using a 'hash'
as main cache but also relying on wan cache to be 'none'.
The part that it actually needs is the 'none'. When WAN cache is
enabled, testUpdateNoMinor fails due to an edit conflict because
one of the edits it makes is made with a current timestamp whereas
it expects to simulate wpEdittime in the year 2012 which, when
caching is enabled, is ignored and becomes the current time instead.
I don't understand exactly why, but I'm going to conserve that
behaviour for now.
* Fix TemplateCategoriesTest, which was failing due to an unexpected
cache hit:
> [objectcache] fetchOrRegenerate(…:page:10:…): volatile hit
This could be solved in a more realistic way by splitting the test,
or by explicitly resetting services half-way the test to clear
WikiPageFactory, PageStore and WANCache process state.
For now, keep the prior behaviour of no cache in this test.
Bug: T305093
Bug: T329680
Depends-On: If890622eed0d0f8b4bd73d36ba1815a3d760ea05
Depends-On: Ie1def75208822bdf19bb2cfd7e6edf32c2000e6b
Depends-On: I35cce61dc3ee90dcee3dd6f0b36f84133be029ed
Change-Id: I53781a8c06ebb2583f6ca83dd91bbfe8a5c88b13
2023-02-14 21:43:12 +00:00
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// Don't let PageStore hit WANObjectCache process cache for revision metadata
|
|
|
|
|
$this->setMainCache( CACHE_NONE );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Title::getParentCategories
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testTemplateCategories() {
|
2012-02-12 15:22:01 +00:00
|
|
|
$user = new User();
|
2019-04-09 06:58:04 +00:00
|
|
|
$this->overrideUserPermissions( $user, [ 'createpage', 'edit', 'purge', 'delete' ] );
|
2022-09-01 21:18:41 +00:00
|
|
|
$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();
|
2011-11-27 16:12:20 +00:00
|
|
|
|
2022-09-23 19:53:11 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, "Categorized from template" );
|
2022-09-01 21:18:41 +00:00
|
|
|
$page = $wikiPageFactory->newFromTitle( $title );
|
2021-06-24 08:42:19 +00:00
|
|
|
$page->doUserEditContent(
|
2013-10-21 21:09:13 +00:00
|
|
|
new WikitextContent( '{{Categorising template}}' ),
|
2021-06-24 08:42:19 +00:00
|
|
|
$user,
|
|
|
|
|
'Create a page with a template'
|
2013-10-21 21:09:13 +00:00
|
|
|
);
|
|
|
|
|
|
2012-01-12 16:42:33 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2013-11-06 17:51:23 +00:00
|
|
|
$title->getParentCategories(),
|
|
|
|
|
'Verify that the category doesn\'t contain the page before the template is created'
|
2012-01-12 16:42:33 +00:00
|
|
|
);
|
2011-11-27 16:12:20 +00:00
|
|
|
|
2013-11-06 17:51:23 +00:00
|
|
|
// Create template
|
2022-09-23 19:53:11 +00:00
|
|
|
$template = $wikiPageFactory->newFromTitle( Title::makeTitle( NS_TEMPLATE, 'Categorising template' ) );
|
2021-06-24 08:42:19 +00:00
|
|
|
$template->doUserEditContent(
|
2013-10-21 21:09:13 +00:00
|
|
|
new WikitextContent( '[[Category:Solved bugs]]' ),
|
2021-06-24 08:42:19 +00:00
|
|
|
$user,
|
|
|
|
|
'Add a category through a template'
|
2013-10-21 21:09:13 +00:00
|
|
|
);
|
2011-11-27 16:12:20 +00:00
|
|
|
|
2021-04-28 02:13:58 +00:00
|
|
|
$this->runJobs();
|
2022-03-17 05:34:47 +00:00
|
|
|
DeferredUpdates::doUpdates();
|
2011-11-27 16:12:20 +00:00
|
|
|
|
2013-11-06 17:51:23 +00:00
|
|
|
// Make sure page is in the category
|
2012-01-12 16:42:33 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'Category:Solved_bugs' => $title->getPrefixedText() ],
|
2013-11-06 17:51:23 +00:00
|
|
|
$title->getParentCategories(),
|
|
|
|
|
'Verify that the page is in the category after the template is created'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Edit the template
|
2021-06-24 08:42:19 +00:00
|
|
|
$template->doUserEditContent(
|
2013-11-06 17:51:23 +00:00
|
|
|
new WikitextContent( '[[Category:Solved bugs 2]]' ),
|
2021-06-24 08:42:19 +00:00
|
|
|
$user,
|
|
|
|
|
'Change the category added by the template'
|
2012-01-12 16:42:33 +00:00
|
|
|
);
|
2013-11-06 17:51:23 +00:00
|
|
|
|
2021-04-28 02:13:58 +00:00
|
|
|
$this->runJobs();
|
2022-03-17 05:34:47 +00:00
|
|
|
DeferredUpdates::doUpdates();
|
2013-11-06 17:51:23 +00:00
|
|
|
|
|
|
|
|
// Make sure page is in the right category
|
|
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'Category:Solved_bugs_2' => $title->getPrefixedText() ],
|
2013-11-06 17:51:23 +00:00
|
|
|
$title->getParentCategories(),
|
|
|
|
|
'Verify that the page is in the right category after the template is edited'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Now delete the template
|
2021-10-30 15:45:49 +00:00
|
|
|
$this->deletePage( $template, 'Delete the template', $user );
|
2013-11-06 17:51:23 +00:00
|
|
|
|
2021-04-28 02:13:58 +00:00
|
|
|
$this->runJobs();
|
2022-03-17 05:34:47 +00:00
|
|
|
DeferredUpdates::doUpdates();
|
2013-11-06 17:51:23 +00:00
|
|
|
|
|
|
|
|
// Make sure the page is no longer in the category
|
|
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2013-11-06 17:51:23 +00:00
|
|
|
$title->getParentCategories(),
|
|
|
|
|
'Verify that the page is no longer in the category after template deletion'
|
|
|
|
|
);
|
2011-11-27 16:12:20 +00:00
|
|
|
}
|
|
|
|
|
}
|