Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / ViewCLITest.php
blob08c1f301fa4699ee834169b0181f65f6b59ccce2
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use DummyNonTextContent;
6 use DummyNonTextContentHandler;
7 use MediaWiki\Content\TextContent;
8 use MediaWiki\Revision\RevisionRecord;
9 use ViewCLI;
11 /**
12 * @covers \ViewCLI
13 * @group Database
14 * @author Dreamy Jazz
16 class ViewCLITest extends MaintenanceBaseTestCase {
18 protected function getMaintenanceClass() {
19 return ViewCLI::class;
22 public function testExecute() {
23 $testPage = $this->getExistingTestPage();
24 // Call ::execute
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 );
38 // Call ::execute
39 $this->maintenance->setArg( 'title', $title );
40 $this->maintenance->execute();
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/' ],
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();