mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-28 16:10:55 +00:00
258e635ae5
SkinOptions array was used to determine which options are available for current session. Once we started extracting things from SkinMinerva class, we found out that lots of things depend on SkinOptions. For example MainMenu/PageActionsMenu depend on skinsOptions var. We could pass $skin object as dependency to a menu builder, but this would cause a circural dependency (Skin depends on menu builder, menu builder depends on skin) which is an anti-pattern. In order to avoid such situations lets prepare first, and extract the SkinOptions to a separate class, register it as a service so different parts of Skin Minerva can freely use a single instance of SkinOptions object. Bug: T216152 Bug: T221012 Change-Id: Icd5da546e1bfaf8d9bfe86dab3b659a88eae19e4
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\MediaWiki\Minerva;
|
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
|
use MediaWikiTestCase;
|
|
|
|
/**
|
|
* Class SkinMinervaTest
|
|
* @package Tests\MediaWiki\Minerva
|
|
* @group MinervaNeue
|
|
* @coversDefaultClass \MediaWiki\Minerva\SkinOptions
|
|
*/
|
|
class SkinOptionsTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers ::get
|
|
* @covers ::getAll
|
|
* @covers ::setMultiple
|
|
*/
|
|
public function testSettersAndGetters() {
|
|
$options = new SkinOptions();
|
|
$defaultValue = $options->get( SkinOptions::OPTION_AMC );
|
|
$options->setMultiple( [ SkinOptions::OPTION_AMC => !$defaultValue ] );
|
|
|
|
$allOptions = $options->getAll();
|
|
|
|
$this->assertEquals( !$defaultValue, $options->get( SkinOptions::OPTION_AMC ) );
|
|
$this->assertArrayHasKey( SkinOptions::OPTION_AMC, $allOptions );
|
|
$this->assertEquals( !$defaultValue, $allOptions[ SkinOptions::OPTION_AMC ] );
|
|
}
|
|
|
|
/**
|
|
* @covers ::hasSkinOptions
|
|
*/
|
|
public function testHasSkinOptions() {
|
|
$options = new SkinOptions();
|
|
// set OPTION_AMC to true just in case someone decides to set everything to false
|
|
// sometime in the future.
|
|
$options->setMultiple( [ SkinOptions::OPTION_AMC => true ] );
|
|
$this->assertTrue( $options->hasSkinOptions() );
|
|
$options->setMultiple( [ SkinOptions::OPTION_BACK_TO_TOP => true ] );
|
|
$this->assertTrue( $options->hasSkinOptions() );
|
|
$options->setMultiple( [
|
|
SkinOptions::OPTION_AMC => false,
|
|
SkinOptions::OPTION_BACK_TO_TOP => false
|
|
] );
|
|
$this->assertFalse( $options->hasSkinOptions() );
|
|
}
|
|
}
|