2019-04-10 21:43:50 +00:00
|
|
|
<?php
|
|
|
|
|
2022-05-03 18:11:54 +00:00
|
|
|
namespace MediaWiki\Minerva;
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2024-03-03 13:31:09 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2024-03-24 10:49:33 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
|
2022-05-03 18:11:54 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
2019-10-20 02:26:08 +00:00
|
|
|
use OutOfBoundsException;
|
2019-04-10 21:43:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Tests\MediaWiki\Minerva
|
|
|
|
* @group MinervaNeue
|
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\SkinOptions
|
|
|
|
*/
|
2022-05-03 18:11:54 +00:00
|
|
|
class SkinOptionsTest extends MediaWikiUnitTestCase {
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2024-10-21 18:39:39 +00:00
|
|
|
private function newSkinOptions(): SkinOptions {
|
2024-03-03 13:31:09 +00:00
|
|
|
return new SkinOptions(
|
2024-03-24 10:49:33 +00:00
|
|
|
$this->createMock( HookContainer::class ),
|
|
|
|
$this->createMock( SkinUserPageHelper::class )
|
2024-03-03 13:31:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:43:50 +00:00
|
|
|
/**
|
|
|
|
* @covers ::get
|
|
|
|
* @covers ::getAll
|
|
|
|
* @covers ::setMultiple
|
|
|
|
*/
|
|
|
|
public function testSettersAndGetters() {
|
2024-03-03 13:31:09 +00:00
|
|
|
$options = $this->newSkinOptions();
|
2019-08-22 20:31:31 +00:00
|
|
|
$defaultValue = $options->get( SkinOptions::BETA_MODE );
|
|
|
|
$options->setMultiple( [ SkinOptions::BETA_MODE => !$defaultValue ] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
|
|
|
$allOptions = $options->getAll();
|
|
|
|
|
2019-08-22 20:31:31 +00:00
|
|
|
$this->assertEquals( !$defaultValue, $options->get( SkinOptions::BETA_MODE ) );
|
|
|
|
$this->assertArrayHasKey( SkinOptions::BETA_MODE, $allOptions );
|
|
|
|
$this->assertEquals( !$defaultValue, $allOptions[ SkinOptions::BETA_MODE ] );
|
2019-04-10 21:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::hasSkinOptions
|
|
|
|
*/
|
|
|
|
public function testHasSkinOptions() {
|
2024-03-03 13:31:09 +00:00
|
|
|
$options = $this->newSkinOptions();
|
2019-04-10 21:43:50 +00:00
|
|
|
$this->assertTrue( $options->hasSkinOptions() );
|
|
|
|
$options->setMultiple( [
|
2020-06-25 21:06:46 +00:00
|
|
|
SkinOptions::SHOW_DONATE => false,
|
2019-07-30 00:24:23 +00:00
|
|
|
SkinOptions::TALK_AT_TOP => false,
|
|
|
|
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
|
|
|
|
SkinOptions::TOOLBAR_SUBMENU => false,
|
2019-08-22 20:31:31 +00:00
|
|
|
SkinOptions::MAIN_MENU_EXPANDED => false,
|
|
|
|
SkinOptions::PERSONAL_MENU => false,
|
2022-04-08 19:21:50 +00:00
|
|
|
SkinOptions::TABS_ON_SPECIALS => false,
|
2019-04-10 21:43:50 +00:00
|
|
|
] );
|
|
|
|
$this->assertFalse( $options->hasSkinOptions() );
|
|
|
|
}
|
2019-07-31 20:47:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::get
|
|
|
|
*/
|
|
|
|
public function testGettingUnknownKeyShouldThrowException() {
|
2024-03-03 13:31:09 +00:00
|
|
|
$options = $this->newSkinOptions();
|
2019-10-20 02:26:08 +00:00
|
|
|
$this->expectException( OutOfBoundsException::class );
|
2019-07-31 20:47:27 +00:00
|
|
|
$options->get( 'non_existing_key' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::get
|
2020-01-26 19:26:31 +00:00
|
|
|
*/
|
2019-07-31 20:47:27 +00:00
|
|
|
public function testSettingUnknownKeyShouldThrowException() {
|
2024-03-03 13:31:09 +00:00
|
|
|
$options = $this->newSkinOptions();
|
2019-10-20 02:26:08 +00:00
|
|
|
$this->expectException( OutOfBoundsException::class );
|
2019-07-31 20:47:27 +00:00
|
|
|
$options->setMultiple( [
|
|
|
|
'non_existing_key' => 1
|
|
|
|
] );
|
|
|
|
}
|
2019-04-10 21:43:50 +00:00
|
|
|
}
|