3 namespace MediaWiki\Tests\Maintenance
;
5 use DummyNonTextContent
;
6 use DummyNonTextContentHandler
;
7 use MediaWiki\Content\TextContent
;
8 use MediaWiki\Revision\RevisionRecord
;
16 class ViewCLITest
extends MaintenanceBaseTestCase
{
18 protected function getMaintenanceClass() {
19 return ViewCLI
::class;
22 public function testExecute() {
23 $testPage = $this->getExistingTestPage();
25 $this->maintenance
->setArg( 'title', $testPage );
26 $this->maintenance
->execute();
27 // Verify that the content of the last revision of the page was outputted.
28 $content = $testPage->getContent( RevisionRecord
::RAW
);
29 $this->assertInstanceOf( TextContent
::class, $content );
30 $expectedOutput = $content->getText();
31 $this->expectOutputString( $expectedOutput );
34 /** @dataProvider provideExecuteForInvalidTitles */
35 public function testExecuteForInvalidTitles( string $title, string $expectedOutputRegex ) {
36 $this->expectCallToFatalError();
37 $this->expectOutputRegex( $expectedOutputRegex );
39 $this->maintenance
->setArg( 'title', $title );
40 $this->maintenance
->execute();
43 public static function provideExecuteForInvalidTitles() {
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/' ],
51 public function testExecuteForNonWikitextPage() {
52 $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
53 'testing-nontext' => DummyNonTextContentHandler
::class,
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();