X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTemplateCategoriesTest.php;h=b0d17267a056efe1ff34591ab966df933dbf02ab;hb=98a1602c28be44dd61ea6a703cd404d58b2243dc;hp=ffa8c428b3f1543d88ea2356e08eefe179e34428;hpb=9cd8ce5034b50a7f1a6570d7a6ac5bbeeb933be4;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TemplateCategoriesTest.php b/tests/phpunit/includes/TemplateCategoriesTest.php index ffa8c428b3..b0d17267a0 100644 --- a/tests/phpunit/includes/TemplateCategoriesTest.php +++ b/tests/phpunit/includes/TemplateCategoriesTest.php @@ -7,20 +7,38 @@ require __DIR__ . "/../../../maintenance/runJobs.php"; class TemplateCategoriesTest extends MediaWikiLangTestCase { - function testTemplateCategories() { + /** + * @covers Title::getParentCategories + */ + public function testTemplateCategories() { + $user = new User(); + $user->mRights = array( 'createpage', 'edit', 'purge', 'delete' ); + $title = Title::newFromText( "Categorized from template" ); $page = WikiPage::factory( $title ); - $user = new User(); - $user->mRights = array( 'createpage', 'edit', 'purge' ); + $page->doEditContent( + new WikitextContent( '{{Categorising template}}' ), + 'Create a page with a template', + 0, + false, + $user + ); - $page->doEditContent( new WikitextContent( '{{Categorising template}}' ), 'Create a page with a template', 0, false, $user ); $this->assertEquals( - array() - , $title->getParentCategories() + array(), + $title->getParentCategories(), + 'Verify that the category doesn\'t contain the page before the template is created' ); + // Create template $template = WikiPage::factory( Title::newFromText( 'Template:Categorising template' ) ); - $template->doEditContent( new WikitextContent( '[[Category:Solved bugs]]' ), 'Add a category through a template', 0, false, $user ); + $template->doEditContent( + new WikitextContent( '[[Category:Solved bugs]]' ), + 'Add a category through a template', + 0, + false, + $user + ); // Run the job queue JobQueueGroup::destroySingletons(); @@ -28,9 +46,51 @@ class TemplateCategoriesTest extends MediaWikiLangTestCase { $jobs->loadParamsAndArgs( null, array( 'quiet' => true ), null ); $jobs->execute(); + // Make sure page is in the category $this->assertEquals( - array( 'Category:Solved_bugs' => $title->getPrefixedText() ) - , $title->getParentCategories() + array( 'Category:Solved_bugs' => $title->getPrefixedText() ), + $title->getParentCategories(), + 'Verify that the page is in the category after the template is created' + ); + + // Edit the template + $template->doEditContent( + new WikitextContent( '[[Category:Solved bugs 2]]' ), + 'Change the category added by the template', + 0, + false, + $user ); + + // Run the job queue + JobQueueGroup::destroySingletons(); + $jobs = new RunJobs; + $jobs->loadParamsAndArgs( null, array( 'quiet' => true ), null ); + $jobs->execute(); + + // Make sure page is in the right category + $this->assertEquals( + array( '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 + $error = ''; + $template->doDeleteArticleReal( 'Delete the template', false, 0, true, $error, $user ); + + // Run the job queue + JobQueueGroup::destroySingletons(); + $jobs = new RunJobs; + $jobs->loadParamsAndArgs( null, array( 'quiet' => true ), null ); + $jobs->execute(); + + // Make sure the page is no longer in the category + $this->assertEquals( + array(), + $title->getParentCategories(), + 'Verify that the page is no longer in the category after template deletion' + ); + } }