Debian Codegraph @

tests/phpunit/includes/title/TemplateCategoriesTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Content\WikitextContent;
4 use MediaWiki\Deferred\DeferredUpdates;
5 use MediaWiki\Title\Title;
6
7 /**
8 * @group Database
9 */
10 class TemplateCategoriesTest extends MediaWikiIntegrationTestCase {
11
12 protected function setUp(): void {
13 parent::setUp();
14
15 // Don't let PageStore hit WANObjectCache process cache for revision metadata
16 $this->setMainCache( CACHE_NONE );
17 }
18
19 /**
20 * @covers \MediaWiki\Title\Title::getParentCategories
21 */
22 public function testTemplateCategories() {
23 $user = $this->getTestUser()->getUser();
24 $this->overrideUserPermissions( $user, [ 'createpage', 'edit', 'purge', 'delete' ] );
25 $wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();
26
27 $title = Title::makeTitle( NS_MAIN, "Categorized from template" );
28 $page = $wikiPageFactory->newFromTitle( $title );
29 $page->doUserEditContent(
30 new WikitextContent( '{{Categorising template}}' ),
31 $user,
32 'Create a page with a template'
33 );
34
35 $this->assertEquals(
36 [],
37 $title->getParentCategories(),
38 'Verify that the category doesn\'t contain the page before the template is created'
39 );
40
41 // Create template
42 $template = $wikiPageFactory->newFromTitle( Title::makeTitle( NS_TEMPLATE, 'Categorising template' ) );
43 $template->doUserEditContent(
44 new WikitextContent( '[[Category:Solved bugs]]' ),
45 $user,
46 'Add a category through a template'
47 );
48
49 $this->runJobs();
50 DeferredUpdates::doUpdates();
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->doUserEditContent(
61 new WikitextContent( '[[Category:Solved bugs 2]]' ),
62 $user,
63 'Change the category added by the template'
64 );
65
66 $this->runJobs();
67 DeferredUpdates::doUpdates();
68
69 // Make sure page is in the right category
70 $this->assertEquals(
71 [ 'Category:Solved_bugs_2' => $title->getPrefixedText() ],
72 $title->getParentCategories(),
73 'Verify that the page is in the right category after the template is edited'
74 );
75
76 // Now delete the template
77 $this->deletePage( $template, 'Delete the template', $user );
78
79 $this->runJobs();
80 DeferredUpdates::doUpdates();
81
82 // Make sure the page is no longer in the category
83 $this->assertEquals(
84 [],
85 $title->getParentCategories(),
86 'Verify that the page is no longer in the category after template deletion'
87 );
88 }
89 }