MediaWiki  master
TemplateCategoriesTest.php
Go to the documentation of this file.
1 <?php
2 
3 require __DIR__ . "/../../../maintenance/runJobs.php";
4 
9 
16  public function testTemplateCategories() {
17  $user = new User();
18  $this->overrideUserPermissions( $user, [ '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 factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
testTemplateCategories()
Broken per T165099.
Maintenance script that runs pending jobs.
Definition: runJobs.php:39
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:767
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static destroySingletons()
Destroy the singleton instances.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:320