TemplateCategoriesTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. require __DIR__ . "/../../../maintenance/runJobs.php";
  3. /**
  4. * @group Database
  5. */
  6. class TemplateCategoriesTest extends MediaWikiLangTestCase {
  7. /**
  8. * Broken per T165099.
  9. *
  10. * @group Broken
  11. * @covers Title::getParentCategories
  12. */
  13. public function testTemplateCategories() {
  14. $user = new User();
  15. $user->mRights = [ 'createpage', 'edit', 'purge', 'delete' ];
  16. $title = Title::newFromText( "Categorized from template" );
  17. $page = WikiPage::factory( $title );
  18. $page->doEditContent(
  19. new WikitextContent( '{{Categorising template}}' ),
  20. 'Create a page with a template',
  21. 0,
  22. false,
  23. $user
  24. );
  25. $this->assertEquals(
  26. [],
  27. $title->getParentCategories(),
  28. 'Verify that the category doesn\'t contain the page before the template is created'
  29. );
  30. // Create template
  31. $template = WikiPage::factory( Title::newFromText( 'Template:Categorising template' ) );
  32. $template->doEditContent(
  33. new WikitextContent( '[[Category:Solved bugs]]' ),
  34. 'Add a category through a template',
  35. 0,
  36. false,
  37. $user
  38. );
  39. // Run the job queue
  40. JobQueueGroup::destroySingletons();
  41. $jobs = new RunJobs;
  42. $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
  43. $jobs->execute();
  44. // Make sure page is in the category
  45. $this->assertEquals(
  46. [ 'Category:Solved_bugs' => $title->getPrefixedText() ],
  47. $title->getParentCategories(),
  48. 'Verify that the page is in the category after the template is created'
  49. );
  50. // Edit the template
  51. $template->doEditContent(
  52. new WikitextContent( '[[Category:Solved bugs 2]]' ),
  53. 'Change the category added by the template',
  54. 0,
  55. false,
  56. $user
  57. );
  58. // Run the job queue
  59. JobQueueGroup::destroySingletons();
  60. $jobs = new RunJobs;
  61. $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
  62. $jobs->execute();
  63. // Make sure page is in the right category
  64. $this->assertEquals(
  65. [ 'Category:Solved_bugs_2' => $title->getPrefixedText() ],
  66. $title->getParentCategories(),
  67. 'Verify that the page is in the right category after the template is edited'
  68. );
  69. // Now delete the template
  70. $error = '';
  71. $template->doDeleteArticleReal( 'Delete the template', false, 0, true, $error, $user );
  72. // Run the job queue
  73. JobQueueGroup::destroySingletons();
  74. $jobs = new RunJobs;
  75. $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
  76. $jobs->execute();
  77. // Make sure the page is no longer in the category
  78. $this->assertEquals(
  79. [],
  80. $title->getParentCategories(),
  81. 'Verify that the page is no longer in the category after template deletion'
  82. );
  83. }
  84. }