Debian Codegraph @

tests/phpunit/maintenance/GrepPagesTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Maintenance;
4
5 use GrepPages;
6 use MediaWiki\WikiMap\WikiMap;
7
8 /**
9 * @covers GrepPages
10 * @group Database
11 * @author Dreamy Jazz
12 */
13 class GrepPagesTest extends MaintenanceBaseTestCase {
14
15 protected function getMaintenanceClass() {
16 return GrepPages::class;
17 }
18
19 private function getTestPageWithContent( $title, $content ) {
20 $testPage = $this->getExistingTestPage( $title );
21 $this->editPage( $testPage, $content );
22 }
23
24 public function addDBDataOnce() {
25 // Create a variety of pages for the test
26 $this->getTestPageWithContent( 'TestPage1', 'testingabcdef' );
27 $this->getTestPageWithContent( 'TestPage2', 'abcdef' );
28 $this->getTestPageWithContent( 'Talk:TestPage1', 'talk-testing' );
29 $this->getTestPageWithContent(
30 'Template:TestPage',
31 "template-test\n== Test ==\nTest section"
32 );
33 }
34
35 /** @dataProvider provideExecute */
36 public function testExecute( $regex, $options, $expectedOutputString ) {
37 $this->maintenance->setArg( 0, $regex );
38 foreach ( $options as $name => $value ) {
39 $this->maintenance->setOption( $name, $value );
40 }
41 $this->maintenance->execute();
42 $this->expectOutputString( $expectedOutputString );
43 }
44
45 public static function provideExecute() {
46 return [
47 'Regex defined to be all pages with --pages-with-matches defined' => [
48 '/.*/', [ 'pages-with-matches' => 1 ],
49 "TestPage1\nTestPage2\nTalk:TestPage1\nTemplate:TestPage\n",
50 ],
51 'Regex defined as no pages' => [ '/^$/', [], '' ],
52 'Regex defined as pages containing the word test' => [
53 'test', [],
54 "TestPage1:1:testingabcdef\nTalk:TestPage1:1:talk-testing\nTemplate:TestPage:1:template-test\n",
55 ],
56 '--prefix for template namespace and --pages-with-matches' => [
57 '', [ 'prefix' => [ 'Template:' ], 'pages-with-matches' => 1 ],
58 "Template:TestPage\n",
59 ],
60 '--prefix for template namespace' => [
61 '', [ 'prefix' => [ 'Template:' ] ],
62 "Template:TestPage:1:template-test\nTemplate:TestPage:2:== Test ==\nTemplate:TestPage:3:Test section\n",
63 ],
64 '--prefix without namespace and --pages-with-matches' => [
65 '', [ 'prefix' => [ 'TestPage' ], 'pages-with-matches' => 1 ], "TestPage1\nTestPage2\n",
66 ],
67 '--prefix specified twice and --pages-with-matches' => [
68 '', [ 'prefix' => [ 'TestPage', 'Talk:TestPage' ], 'pages-with-matches' => 1 ],
69 "TestPage1\nTestPage2\nTalk:TestPage1\n",
70 ],
71 ];
72 }
73
74 public function testExecuteForShowWiki() {
75 $wikiName = WikiMap::getCurrentWikiId();
76 $this->testExecute(
77 'test', [ 'show-wiki' => 1 ],
78 $wikiName . "\tTestPage1:1:testingabcdef\n" .
79 $wikiName . "\tTalk:TestPage1:1:talk-testing\n" .
80 $wikiName . "\tTemplate:TestPage:1:template-test\n",
81 );
82 }
83
84 public function testExecuteForShowWikiAndPageWithMatches() {
85 $wikiName = WikiMap::getCurrentWikiId();
86 $this->testExecute(
87 'test', [ 'show-wiki' => 1, 'pages-with-matches' => 1 ],
88 $wikiName . "\tTestPage1\n" .
89 $wikiName . "\tTalk:TestPage1\n" .
90 $wikiName . "\tTemplate:TestPage\n",
91 );
92 }
93 }