mediawiki-skins-Citizen/tests/phpunit/Partials/BodyContentTest.php
H. C. Kruse 661ad61486
ci: add PHPUnit tests (#712)
* ci: WIP add PHP Unit Tests

* ci: 👷 lint code to MediaWiki standards

Check commit and GitHub actions for more details

* ci: Add phpunit tests

---------

Co-authored-by: github-actions <github-actions@users.noreply.github.com>
2023-08-25 14:39:37 -07:00

85 lines
2.2 KiB
PHP

<?php
declare( strict_types=1 );
namespace MediaWiki\Skins\Citizen\Tests\Partials;
use MediaWiki\Skins\Citizen\Partials\BodyContent;
use MediaWiki\Skins\Citizen\SkinCitizen;
use MediaWiki\Title\Title;
use MediaWikiIntegrationTestCase;
use MWException;
use RequestContext;
use Wikimedia\AtEase\AtEase;
/**
* @group Citizen
*/
class BodyContentTest extends MediaWikiIntegrationTestCase {
/**
* @covers \MediaWiki\Skins\Citizen\Partials\BodyContent
* @return void
* @throws MWException
*/
public function testDecorateBodyContentTitleNull() {
RequestContext::resetMain();
RequestContext::getMain()->setTitle( null );
$partial = new BodyContent( new SkinCitizen( [
'name' => 'SkinCitizen'
] ) );
$this->assertEquals( '<Foo>', $partial->decorateBodyContent( '<Foo>' ) );
}
/**
* @covers \MediaWiki\Skins\Citizen\Partials\BodyContent
* @return void
* @throws MWException
*/
public function testDecorateBodyContentCollapseNotEnabled() {
$this->overrideConfigValues( [
'CitizenEnableCollapsibleSections' => false,
] );
RequestContext::resetMain();
RequestContext::getMain()->setTitle( null );
$partial = new BodyContent( new SkinCitizen( [
'name' => 'SkinCitizen'
] ) );
$this->assertEquals( '<Foo>', $partial->decorateBodyContent( '<Foo>' ) );
}
/**
* @covers \MediaWiki\Skins\Citizen\Partials\BodyContent
* @return void
* @throws MWException
*/
public function testDecorateBodyContentCollapseEnabledContentPage() {
$this->overrideConfigValues( [
'CitizenEnableCollapsibleSections' => true,
] );
$title = Title::newFromText( 'BodyContent' );
RequestContext::resetMain();
RequestContext::getMain()->setTitle( $title );
$partial = new BodyContent( new SkinCitizen( [
'name' => 'SkinCitizen'
] ) );
$html = <<<HTML
<div class="mw-parser-output">
<div class="mw-heading"><h2><span class="mw-headline" id="Sidebar" data-mw-thread-id="h-Sidebar"><span data-mw-comment-start="" id="h-Sidebar"></span>Sidebar<span data-mw-comment-end="h-Sidebar"></span></span></h2><!--__DTELLIPSISBUTTON__--></div>
</div>
HTML;
AtEase::suppressWarnings();
$this->assertStringContainsString( 'section-indicator', $partial->decorateBodyContent( $html ) );
AtEase::restoreWarnings();
}
}