File: TemplateCategoriesTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (89 lines) | stat: -rw-r--r-- 2,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

use MediaWiki\Content\WikitextContent;
use MediaWiki\Deferred\DeferredUpdates;
use MediaWiki\Title\Title;

/**
 * @group Database
 */
class TemplateCategoriesTest extends MediaWikiIntegrationTestCase {

	protected function setUp(): void {
		parent::setUp();

		// Don't let PageStore hit WANObjectCache process cache for revision metadata
		$this->setMainCache( CACHE_NONE );
	}

	/**
	 * @covers \MediaWiki\Title\Title::getParentCategories
	 */
	public function testTemplateCategories() {
		$user = $this->getTestUser()->getUser();
		$this->overrideUserPermissions( $user, [ 'createpage', 'edit', 'purge', 'delete' ] );
		$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();

		$title = Title::makeTitle( NS_MAIN, "Categorized from template" );
		$page = $wikiPageFactory->newFromTitle( $title );
		$page->doUserEditContent(
			new WikitextContent( '{{Categorising template}}' ),
			$user,
			'Create a page with a template'
		);

		$this->assertEquals(
			[],
			$title->getParentCategories(),
			'Verify that the category doesn\'t contain the page before the template is created'
		);

		// Create template
		$template = $wikiPageFactory->newFromTitle( Title::makeTitle( NS_TEMPLATE, 'Categorising template' ) );
		$template->doUserEditContent(
			new WikitextContent( '[[Category:Solved bugs]]' ),
			$user,
			'Add a category through a template'
		);

		$this->runJobs();
		DeferredUpdates::doUpdates();

		// Make sure page is in the category
		$this->assertEquals(
			[ 'Category:Solved_bugs' => $title->getPrefixedText() ],
			$title->getParentCategories(),
			'Verify that the page is in the category after the template is created'
		);

		// Edit the template
		$template->doUserEditContent(
			new WikitextContent( '[[Category:Solved bugs 2]]' ),
			$user,
			'Change the category added by the template'
		);

		$this->runJobs();
		DeferredUpdates::doUpdates();

		// Make sure page is in the right category
		$this->assertEquals(
			[ 'Category:Solved_bugs_2' => $title->getPrefixedText() ],
			$title->getParentCategories(),
			'Verify that the page is in the right category after the template is edited'
		);

		// Now delete the template
		$this->deletePage( $template, 'Delete the template', $user );

		$this->runJobs();
		DeferredUpdates::doUpdates();

		// Make sure the page is no longer in the category
		$this->assertEquals(
			[],
			$title->getParentCategories(),
			'Verify that the page is no longer in the category after template deletion'
		);
	}
}