MediaWiki REL1_30
TemplateCategoriesTest.php
Go to the documentation of this file.
1<?php
2
6require __DIR__ . "/../../../maintenance/runJobs.php";
7
9
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
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
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
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}
static destroySingletons()
Destroy the singleton instances.
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
Base class that store and restore the Language objects.
Maintenance script that runs pending jobs.
Definition runJobs.php:33
testTemplateCategories()
Broken per T165099.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
Content object for wiki text pages.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
Definition hooks.txt:829