| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use DummyNonTextContent; |
| 6 |
use DummyNonTextContentHandler; |
| 7 |
use MediaWiki\Content\TextContent; |
| 8 |
use MediaWiki\Revision\RevisionRecord; |
| 9 |
use ViewCLI; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class ViewCLITest extends MaintenanceBaseTestCase { |
| 17 |
|
| 18 |
protected function getMaintenanceClass() { |
| 19 |
return ViewCLI::class; |
| 20 |
} |
| 21 |
|
| 22 |
public function testExecute() { |
| 23 |
$testPage = $this->getExistingTestPage(); |
| 24 |
|
| 25 |
$this->maintenance->setArg( 'title', $testPage ); |
| 26 |
$this->maintenance->execute(); |
| 27 |
|
| 28 |
$content = $testPage->getContent( RevisionRecord::RAW ); |
| 29 |
$this->assertInstanceOf( TextContent::class, $content ); |
| 30 |
$expectedOutput = $content->getText(); |
| 31 |
$this->expectOutputString( $expectedOutput ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function testExecuteForInvalidTitles( string $title, string $expectedOutputRegex ) { |
| 36 |
$this->expectCallToFatalError(); |
| 37 |
$this->expectOutputRegex( $expectedOutputRegex ); |
| 38 |
|
| 39 |
$this->maintenance->setArg( 'title', $title ); |
| 40 |
$this->maintenance->execute(); |
| 41 |
} |
| 42 |
|
| 43 |
public static function provideExecuteForInvalidTitles() { |
| 44 |
return [ |
| 45 |
'Empty title' => [ '', '/Invalid title/' ], |
| 46 |
'Special page title' => [ 'Special:Test', '/Special Pages not supported/' ], |
| 47 |
'Non-existent title' => [ 'Non-existing-test-page-1234', '/Page does not exist/' ], |
| 48 |
]; |
| 49 |
} |
| 50 |
|
| 51 |
public function testExecuteForNonWikitextPage() { |
| 52 |
$this->mergeMwGlobalArrayValue( 'wgContentHandlers', [ |
| 53 |
'testing-nontext' => DummyNonTextContentHandler::class, |
| 54 |
] ); |
| 55 |
$this->editPage( 'ThisPageIsNotInWikitext', new DummyNonTextContent( 'Hello' ), 'Test', NS_MAIN, $this->getTestSysop()->getAuthority() ); |
| 56 |
$this->expectCallToFatalError(); |
| 57 |
$this->expectOutputRegex( '/Non-text content models not supported/' ); |
| 58 |
$this->maintenance->setArg( 'title', 'ThisPageIsNotInWikitext' ); |
| 59 |
$this->maintenance->execute(); |
| 60 |
} |
| 61 |
|
| 62 |
} |