wiki.techinc.nl/tests/phpunit/includes/TemplateCategoriesTest.php

88 lines
2.3 KiB
PHP
Raw Normal View History

<?php
use MediaWiki\Title\Title;
/**
* @group Database
*/
class TemplateCategoriesTest extends MediaWikiIntegrationTestCase {
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 );
}
/**
* @covers Title::getParentCategories
*/
public function testTemplateCategories() {
$user = new User();
$this->overrideUserPermissions( $user, [ 'createpage', 'edit', 'purge', 'delete' ] );
$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();
$title = Title::makeTitle( NS_MAIN, "Categorized from template" );
$page = $wikiPageFactory->newFromTitle( $title );
$page->doUserEditContent(
new WikitextContent( '{{Categorising template}}' ),
$user,
'Create a page with a template'
);
$this->assertEquals(
[],
$title->getParentCategories(),
'Verify that the category doesn\'t contain the page before the template is created'
);
// Create template
$template = $wikiPageFactory->newFromTitle( Title::makeTitle( NS_TEMPLATE, 'Categorising template' ) );
$template->doUserEditContent(
new WikitextContent( '[[Category:Solved bugs]]' ),
$user,
'Add a category through a template'
);
$this->runJobs();
DeferredUpdates::doUpdates();
// Make sure page is in the category
$this->assertEquals(
[ 'Category:Solved_bugs' => $title->getPrefixedText() ],
$title->getParentCategories(),
'Verify that the page is in the category after the template is created'
);
// Edit the template
$template->doUserEditContent(
new WikitextContent( '[[Category:Solved bugs 2]]' ),
$user,
'Change the category added by the template'
);
$this->runJobs();
DeferredUpdates::doUpdates();
// Make sure page is in the right category
$this->assertEquals(
[ 'Category:Solved_bugs_2' => $title->getPrefixedText() ],
$title->getParentCategories(),
'Verify that the page is in the right category after the template is edited'
);
// Now delete the template
$this->deletePage( $template, 'Delete the template', $user );
$this->runJobs();
DeferredUpdates::doUpdates();
// Make sure the page is no longer in the category
$this->assertEquals(
[],
$title->getParentCategories(),
'Verify that the page is no longer in the category after template deletion'
);
}
}