wiki.techinc.nl/tests/phpunit/maintenance/GetTextMaintTest.php
Dreamy Jazz 2368f91ff3 Test getText.php
Why:
* The maintenance scripts in core are mostly untested and testing
  the less complex scripts will improve the test coverage in core.

What:
* Test getText.php

Bug: T371167
Change-Id: Iebf7a7a7f124859738350848eb698f6e055078a6
2024-07-27 08:50:48 +00:00

50 lines
1.5 KiB
PHP

<?php
namespace MediaWiki\Tests\Maintenance;
use GetTextMaint;
use MediaWiki\Revision\SlotRecord;
/**
* @covers \GetTextMaint
* @group Database
* @author Dreamy Jazz
*/
class GetTextMaintTest extends MaintenanceBaseTestCase {
protected function getMaintenanceClass() {
return GetTextMaint::class;
}
public function testExecute() {
$testPage = $this->getExistingTestPage();
// Call ::execute
$this->maintenance->setArg( 'title', $testPage );
$this->maintenance->execute();
// Verify that the content of the last revision of the page was outputted.
$expectedOutput = $testPage->getContent( SlotRecord::MAIN )->serialize();
if ( stream_isatty( STDOUT ) ) {
$expectedOutput .= "\n";
}
$this->expectOutputString( $expectedOutput );
}
public function testExecuteForOldRevision() {
// Get a test page with two revisions
$testPage = $this->getExistingTestPage();
$firstRevContent = $testPage->getContent( SlotRecord::MAIN )->serialize();
$this->editPage( $testPage, 'testing1234' );
// Call ::execute
$this->maintenance->setArg( 'title', $testPage );
$this->maintenance->setOption(
'revision', $this->getServiceContainer()->getRevisionLookup()->getFirstRevision( $testPage )->getId()
);
$this->maintenance->execute();
// Verify that the content of the first revision of the page was outputted.
$expectedOutput = $firstRevContent;
if ( stream_isatty( STDOUT ) ) {
$expectedOutput .= "\n";
}
$this->expectOutputString( $expectedOutput );
}
}