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