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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|