2024-02-06 22:26:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Minerva;
|
|
|
|
|
|
|
|
use MediaWiki\Minerva\Skins\FeaturesHelper;
|
|
|
|
use MediaWiki\Request\WebRequest;
|
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
use MediaWikiIntegrationTestCase;
|
2024-03-24 18:26:16 +00:00
|
|
|
use RequestContext;
|
2024-02-06 22:26:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group MinervaNeue
|
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\Skins\FeaturesHelper
|
|
|
|
*/
|
|
|
|
class FeaturesHelperTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
public function provideShouldDisableNightModeExcluded() {
|
|
|
|
$options = [
|
|
|
|
'exclude' => [
|
|
|
|
'mainpage' => true,
|
|
|
|
'pagetitles' => [ 'Test_Page' ],
|
|
|
|
'namespaces' => [ 1 ],
|
|
|
|
'querystring' => [
|
|
|
|
'action' => '(edit)',
|
|
|
|
'diff' => '.+'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
2024-03-24 18:26:16 +00:00
|
|
|
$context = new RequestContext();
|
2024-02-06 22:26:55 +00:00
|
|
|
$request = $context->getRequest();
|
2024-03-24 18:26:16 +00:00
|
|
|
$editContext = new RequestContext();
|
2024-02-06 22:26:55 +00:00
|
|
|
$editRequest = $context->getRequest();
|
|
|
|
$editRequest->setVal( 'action', 'edit' );
|
|
|
|
$mainTitle = Title::makeTitle( NS_MAIN, 'Main Page' );
|
|
|
|
$testTitle = Title::makeTitle( NS_MAIN, 'Test_Page' );
|
|
|
|
$otherTitle = Title::makeTitle( NS_MAIN, 'Other_Page' );
|
|
|
|
$differentTitle = Title::makeTitle( NS_MAIN, 'Different Page' );
|
|
|
|
$includedTitle = Title::makeTitle( NS_MAIN, 'Included Page' );
|
|
|
|
yield 'main page' => [ $options, $request, $mainTitle, true ];
|
|
|
|
yield 'page titles' => [ $options, $request, $testTitle, true ];
|
|
|
|
yield 'namespaces' => [ $options, $request, $otherTitle, true ];
|
|
|
|
yield 'query string' => [ $options, $editRequest, $differentTitle, true ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideShouldDisableNightModeExcluded
|
|
|
|
* @covers \MediaWiki\Minerva\Skins\FeaturesHelper::shouldDisableNightMode
|
|
|
|
*/
|
|
|
|
public function testShouldDisableNightModeExcluded(
|
2024-03-05 20:58:06 +00:00
|
|
|
array $options, WebRequest $request, Title $title = null, bool $expected = false ) {
|
2024-02-06 22:26:55 +00:00
|
|
|
$featuresHelper = new FeaturesHelper();
|
|
|
|
$shouldDisableNightMode = $featuresHelper->shouldDisableNightMode( $options, $request, $title );
|
2024-03-05 20:58:06 +00:00
|
|
|
$this->assertSame( $expected, $shouldDisableNightMode );
|
2024-02-06 22:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Minerva\Skins\FeaturesHelper::shouldDisableNightMode
|
|
|
|
*/
|
|
|
|
public function testShouldDisableNightModeIncluded() {
|
|
|
|
$options = [
|
|
|
|
'exclude' => [
|
|
|
|
'mainpage' => false,
|
|
|
|
'pagetitles' => [ 'Test_Page' ],
|
|
|
|
'namespaces' => [ 1 ],
|
|
|
|
'querystring' => [
|
|
|
|
'action' => '(edit)',
|
|
|
|
'diff' => '.+'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
2024-03-24 18:26:16 +00:00
|
|
|
$context = new RequestContext();
|
2024-02-06 22:26:55 +00:00
|
|
|
$request = $context->getRequest();
|
|
|
|
$includedTitle = Title::makeTitle( NS_MAIN, 'Included Page' );
|
|
|
|
$featuresHelper = new FeaturesHelper();
|
|
|
|
$shouldDisableNightMode = $featuresHelper->shouldDisableNightMode( $options, $request, $includedTitle );
|
|
|
|
$this->assertFalse( $shouldDisableNightMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|