mediawiki-skins-Citizen/tests/phpunit/SkinCitizenTest.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

126 lines
3.3 KiB
PHP

<?php
declare( strict_types=1 );
namespace MediaWiki\Skins\Citizen\Tests;
use Exception;
use MediaWiki\Skins\Citizen\SkinCitizen;
use MediaWiki\Title\Title;
use MediaWikiIntegrationTestCase;
use RequestContext;
/**
* TODO: Fully test tagline logic
* @group Citizen
*/
class SkinCitizenTest extends MediaWikiIntegrationTestCase {
/**
* @covers \MediaWiki\Skins\Citizen\SkinCitizen
* @return void
*/
public function testConstructor() {
$skin = new SkinCitizen( [
'name' => 'Citizen',
] );
$this->assertInstanceOf( SkinCitizen::class, $skin );
}
/**
* @covers \MediaWiki\Skins\Citizen\SkinCitizen
* @covers \MediaWiki\Skins\Citizen\SkinCitizen::buildSkinFeatures
* @covers \MediaWiki\Skins\Citizen\Partials\Metadata
* @covers \MediaWiki\Skins\Citizen\Partials\Theme
* @return void
* @throws Exception
*/
public function testBuildSkinFeatures() {
$this->overrideConfigValues( [
'CitizenThemeDefault' => 'dark',
'CitizenThemeColor' => '#ffaabb',
'CitizenEnableManifest' => true,
] );
$skin = new SkinCitizen( [
'name' => 'Citizen',
] );
$title = Title::newFromText( 'TestTitle' );
$skin->setRelevantTitle( $title );
$options = $skin->getOptions();
$out = $skin->getOutput();
$this->assertFalse( $options['toc'] );
$this->assertContains( [ 'theme-color', '#ffaabb' ], $out->getMetaTags() );
$this->assertContains( [
'rel' => 'manifest',
'href' => $this->getServiceContainer()->getUrlUtils()->expand( wfAppendQuery( wfScript( 'api' ),
[ 'action' => 'webapp-manifest' ] ), PROTO_RELATIVE ),
], $out->getLinkTags() );
}
/**
* @covers \MediaWiki\Skins\Citizen\SkinCitizen
* @covers \MediaWiki\Skins\Citizen\SkinCitizen::buildSkinFeatures
* @covers \MediaWiki\Skins\Citizen\Partials\Metadata
* @covers \MediaWiki\Skins\Citizen\Partials\Theme
* @return void
* @throws Exception
*/
public function testBuildSkinFeaturesNotAddManifest() {
$this->overrideConfigValues( [
'CitizenEnableManifest' => false,
] );
$skin = new SkinCitizen( [
'name' => 'Citizen',
] );
$this->assertEmpty( $skin->getOutput()->getLinkTags() );
}
/**
* @covers \MediaWiki\Skins\Citizen\SkinCitizen
* @covers \MediaWiki\Skins\Citizen\SkinCitizen::buildSkinFeatures
* @return void
* @throws Exception
*/
public function testBuildSkinFeaturesEnableCjk() {
$this->overrideConfigValues( [
'CitizenEnableCJKFonts' => true,
] );
$skin = new SkinCitizen( [
'name' => 'Citizen',
] );
$this->assertArrayHasKey( 'styles', $skin->getOptions() );
$this->assertContains( 'skins.citizen.styles.fonts.cjk', $skin->getOptions()['styles'] );
}
/**
* @covers \MediaWiki\Skins\Citizen\SkinCitizen
* @covers \MediaWiki\Skins\Citizen\SkinCitizen::buildSkinFeatures
* @return void
* @throws Exception
*/
public function testBuildSkinFeaturesEnableCollapsibleSections() {
$title = Title::newFromText( 'BuildSkinFeaturesEnableCollapsibleSections' );
RequestContext::resetMain();
RequestContext::getMain()->setTitle( $title );
$this->overrideConfigValues( [
'CitizenEnableCollapsibleSections' => true,
] );
$skin = new SkinCitizen( [
'name' => 'Citizen',
] );
$this->assertArrayHasKey( 'bodyClasses', $skin->getOptions() );
$this->assertContains( 'citizen-sections-enabled', $skin->getOptions()['bodyClasses'] );
}
}