3 namespace MediaWiki\Tests\Maintenance
;
6 use MediaWiki\WikiMap\WikiMap
;
13 class GrepPagesTest
extends MaintenanceBaseTestCase
{
15 protected function getMaintenanceClass() {
16 return GrepPages
::class;
19 private function getTestPageWithContent( $title, $content ) {
20 $testPage = $this->getExistingTestPage( $title );
21 $this->editPage( $testPage, $content );
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(
31 "template-test\n== Test ==\nTest section"
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 );
41 $this->maintenance
->execute();
42 $this->expectOutputString( $expectedOutputString );
45 public static function provideExecute() {
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",
51 'Regex defined as no pages' => [ '/^$/', [], '' ],
52 'Regex defined as pages containing the word test' => [
54 "TestPage1:1:testingabcdef\nTalk:TestPage1:1:talk-testing\nTemplate:TestPage:1:template-test\n",
56 '--prefix for template namespace and --pages-with-matches' => [
57 '', [ 'prefix' => [ 'Template:' ], 'pages-with-matches' => 1 ],
58 "Template:TestPage\n",
60 '--prefix for template namespace' => [
61 '', [ 'prefix' => [ 'Template:' ] ],
62 "Template:TestPage:1:template-test\nTemplate:TestPage:2:== Test ==\nTemplate:TestPage:3:Test section\n",
64 '--prefix without namespace and --pages-with-matches' => [
65 '', [ 'prefix' => [ 'TestPage' ], 'pages-with-matches' => 1 ], "TestPage1\nTestPage2\n",
67 '--prefix specified twice and --pages-with-matches' => [
68 '', [ 'prefix' => [ 'TestPage', 'Talk:TestPage' ], 'pages-with-matches' => 1 ],
69 "TestPage1\nTestPage2\nTalk:TestPage1\n",
74 public function testExecuteForShowWiki() {
75 $wikiName = WikiMap
::getCurrentWikiId();
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",
84 public function testExecuteForShowWikiAndPageWithMatches() {
85 $wikiName = WikiMap
::getCurrentWikiId();
87 'test', [ 'show-wiki' => 1, 'pages-with-matches' => 1 ],
88 $wikiName . "\tTestPage1\n" .
89 $wikiName . "\tTalk:TestPage1\n" .
90 $wikiName . "\tTemplate:TestPage\n",