Instead of creating a half-initialized helper and later calling ::init, provide all the information necessary for the helper in the constructor. This is facilitated by the fact that there already exists a factory class, PageRestHelperFactory, which holds all the services required. This affects: * HtmlOutputRendererHelper::init() * HtmlMessageOutputHelper::init() * HtmlInputTransformHelper::init() Change-Id: I1e1213597c6be012f2bc024c2b370c968ff3b472
68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Rest\Handler\Helper;
|
|
|
|
use MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper;
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper
|
|
* @group Database
|
|
*/
|
|
class HtmlMessageOutputHelperTest extends MediaWikiIntegrationTestCase {
|
|
private function newHelper( $page ): HtmlMessageOutputHelper {
|
|
return new HtmlMessageOutputHelper( $page );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::init
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::getHtml
|
|
*/
|
|
public function testGetHtml() {
|
|
$page = $this->getNonexistingTestPage( 'MediaWiki:Logouttext' );
|
|
|
|
$helper = $this->newHelper( $page );
|
|
|
|
$this->assertSame( 0, $page->getLatest() );
|
|
|
|
$htmlresult = $helper->getHtml()->getRawText();
|
|
|
|
$this->assertStringContainsString( 'You are now logged out', $htmlresult );
|
|
// Check that we have a full HTML document in English
|
|
$this->assertStringContainsString( '<html', $htmlresult );
|
|
$this->assertStringContainsString( 'content="en"', $htmlresult );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::init
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::getETag
|
|
*/
|
|
public function testGetETag() {
|
|
$page = $this->getNonexistingTestPage( 'MediaWiki:Logouttext' );
|
|
|
|
$helper = $this->newHelper( $page );
|
|
|
|
$etag = $helper->getETag();
|
|
|
|
$this->assertStringContainsString( '"message/', $etag );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::init
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlMessageOutputHelper::getHtml
|
|
*/
|
|
public function testGetHtmlWithLanguageCode() {
|
|
$page = $this->getNonexistingTestPage( 'MediaWiki:Logouttext/de' );
|
|
|
|
$helper = $this->newHelper( $page );
|
|
|
|
$this->assertSame( 0, $page->getLatest() );
|
|
|
|
$htmlresult = $helper->getHtml()->getRawText();
|
|
|
|
$this->assertStringContainsString( 'Du bist nun abgemeldet', $htmlresult );
|
|
// Check that we have a full HTML document in English
|
|
$this->assertStringContainsString( '<html', $htmlresult );
|
|
$this->assertStringContainsString( 'content="de"', $htmlresult );
|
|
}
|
|
}
|