2020-04-28 21:02:15 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @since 1.35
|
|
|
|
*/
|
|
|
|
|
2022-03-04 13:35:05 +00:00
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Integration;
|
|
|
|
|
|
|
|
use HashConfig;
|
2021-11-23 13:40:35 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
2021-09-09 22:13:48 +00:00
|
|
|
use Vector\Constants;
|
2020-04-28 21:02:15 +00:00
|
|
|
use Vector\SkinVersionLookup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Vector
|
|
|
|
* @coversDefaultClass \Vector\SkinVersionLookup
|
|
|
|
*/
|
2021-10-11 23:10:33 +00:00
|
|
|
class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
2020-04-28 21:02:15 +00:00
|
|
|
/**
|
|
|
|
* @covers ::isLegacy
|
|
|
|
* @covers ::getVersion
|
|
|
|
*/
|
|
|
|
public function testRequest() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
2022-01-24 20:11:52 +00:00
|
|
|
->willReturnCallback( static function ( $key ) {
|
|
|
|
if ( $key === Constants::QUERY_PARAM_SKIN ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return 'alpha';
|
|
|
|
}
|
|
|
|
} );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
2020-12-18 02:51:28 +00:00
|
|
|
->method( 'isRegistered' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
2021-09-09 22:13:48 +00:00
|
|
|
'VectorSkinMigrationMode' => false,
|
2020-04-28 21:02:15 +00:00
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, 'beta', [
|
|
|
|
'skin' => Constants::SKIN_NAME_LEGACY,
|
|
|
|
] );
|
2021-11-23 13:40:35 +00:00
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'alpha',
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->getVersion(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Query parameter is the first priority.'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
false,
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->isLegacy(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Version is non-Legacy.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
* @covers ::isLegacy
|
|
|
|
*/
|
|
|
|
public function testUserPreference() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
2022-01-24 20:11:52 +00:00
|
|
|
->willReturnCallback( static function ( $key ) {
|
|
|
|
if ( $key === Constants::QUERY_PARAM_SKIN ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return 'beta';
|
|
|
|
}
|
|
|
|
} );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
2020-12-18 02:51:28 +00:00
|
|
|
->method( 'isRegistered' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
2021-09-09 22:13:48 +00:00
|
|
|
'VectorSkinMigrationMode' => false,
|
2020-04-28 21:02:15 +00:00
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, 'beta', [
|
|
|
|
'skin' => Constants::SKIN_NAME_LEGACY,
|
|
|
|
] );
|
2021-11-23 13:40:35 +00:00
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'beta',
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->getVersion(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'User preference is the second priority.'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
false,
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->isLegacy(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Version is non-Legacy.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
* @covers ::isLegacy
|
|
|
|
*/
|
2020-12-18 02:51:28 +00:00
|
|
|
public function testConfigRegistered() {
|
2020-04-28 21:02:15 +00:00
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
2022-01-24 20:11:52 +00:00
|
|
|
->willReturnCallback( static function ( $key ) {
|
|
|
|
if ( $key === Constants::QUERY_PARAM_SKIN ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return '1';
|
|
|
|
}
|
|
|
|
} );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
2020-12-18 02:51:28 +00:00
|
|
|
->method( 'isRegistered' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( true );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
2021-09-09 22:13:48 +00:00
|
|
|
'VectorSkinMigrationMode' => false,
|
2020-04-28 21:02:15 +00:00
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '1', [
|
|
|
|
'skin' => Constants::SKIN_NAME_LEGACY,
|
|
|
|
] );
|
2021-11-23 13:40:35 +00:00
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'1',
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->getVersion(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Config is the third priority and distinguishes logged in users from anonymous users.'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
true,
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->isLegacy(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Version is Legacy.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-18 22:44:19 +00:00
|
|
|
public function providerAnonUserMigrationMode() {
|
|
|
|
return [
|
|
|
|
// When no query string just return DefaultSkin version.
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_LEGACY,
|
|
|
|
null,
|
|
|
|
Constants::SKIN_VERSION_LEGACY,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_MODERN,
|
|
|
|
null,
|
|
|
|
Constants::SKIN_VERSION_LATEST,
|
|
|
|
],
|
|
|
|
// When useskin=vector return legacy Vector version.
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_LEGACY,
|
|
|
|
Constants::SKIN_NAME_LEGACY,
|
|
|
|
Constants::SKIN_VERSION_LEGACY,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_MODERN,
|
|
|
|
Constants::SKIN_NAME_LEGACY,
|
|
|
|
Constants::SKIN_VERSION_LEGACY,
|
|
|
|
],
|
|
|
|
// When useskin=vector-2022 return modern Vector.
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_MODERN,
|
|
|
|
Constants::SKIN_NAME_MODERN,
|
|
|
|
Constants::SKIN_VERSION_LATEST,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constants::SKIN_NAME_LEGACY,
|
|
|
|
Constants::SKIN_NAME_MODERN,
|
|
|
|
Constants::SKIN_VERSION_LATEST,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
* @dataProvider providerAnonUserMigrationMode
|
|
|
|
*/
|
|
|
|
public function testVectorAnonUserMigrationModeWithUseSkinVector(
|
|
|
|
string $defaultSkin,
|
|
|
|
$useSkin,
|
|
|
|
$expectedVersion
|
|
|
|
) {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
|
|
|
->with( 'useskin' )
|
|
|
|
->willReturn( $useSkin );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
|
|
|
->method( 'isRegistered' )
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
|
|
|
'DefaultSkin' => $defaultSkin,
|
|
|
|
'VectorSkinMigrationMode' => true,
|
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '2'
|
|
|
|
] );
|
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', [
|
|
|
|
'skin' => $defaultSkin,
|
|
|
|
] );
|
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$expectedVersion,
|
|
|
|
$skinVersionLookup->getVersion(),
|
|
|
|
'useskin=vector query string yields legacy skin in migration mode'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
*/
|
|
|
|
public function testVectorRegisteredUserMigrationMode() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
|
|
|
->willReturn( null );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
|
|
|
->method( 'isRegistered' )
|
|
|
|
->willReturn( true );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
|
|
|
'DefaultSkin' => 'vector',
|
|
|
|
'VectorSkinMigrationMode' => true,
|
|
|
|
'VectorDefaultSkinVersion' => '1',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', [
|
|
|
|
'skin' => Constants::SKIN_NAME_LEGACY
|
|
|
|
] );
|
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'2',
|
|
|
|
$skinVersionLookup->getVersion(),
|
|
|
|
'If legacy skin is set with skin version modern, then the user gets modern skin still'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
*/
|
|
|
|
public function testSkin22() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
|
|
|
->willReturn( '1' );
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
|
|
|
->method( 'isRegistered' )
|
|
|
|
->willReturn( true );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
|
|
|
'VectorSkinMigrationMode' => false,
|
|
|
|
'VectorDefaultSkinVersion' => '1',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '1', [
|
|
|
|
'skin' => Constants::SKIN_NAME_MODERN
|
|
|
|
] );
|
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'2',
|
|
|
|
$skinVersionLookup->getVersion(),
|
|
|
|
'Using the modern skin always returns 2. Ignores skinversion query string.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-28 21:02:15 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
* @covers ::isLegacy
|
|
|
|
*/
|
|
|
|
public function testConfigAnon() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
2022-01-24 20:11:52 +00:00
|
|
|
->willReturnCallback( static function ( $key ) {
|
|
|
|
if ( $key === Constants::QUERY_PARAM_SKIN ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return '2';
|
|
|
|
}
|
|
|
|
} );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$user = $this->createMock( \User::class );
|
|
|
|
$user
|
2020-12-18 02:51:28 +00:00
|
|
|
->method( 'isRegistered' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
$config = new HashConfig( [
|
2021-09-09 22:13:48 +00:00
|
|
|
'VectorSkinMigrationMode' => false,
|
2020-04-28 21:02:15 +00:00
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', [
|
|
|
|
'skin' => Constants::SKIN_NAME_LEGACY,
|
|
|
|
] );
|
2021-11-23 13:40:35 +00:00
|
|
|
|
|
|
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
2020-04-28 21:02:15 +00:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'2',
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->getVersion(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Config is the third priority and distinguishes anonymous users from logged in users.'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
false,
|
2021-11-13 18:01:31 +00:00
|
|
|
$skinVersionLookup->isLegacy(),
|
2020-04-28 21:02:15 +00:00
|
|
|
'Version is non-Legacy.'
|
|
|
|
);
|
|
|
|
}
|
2021-11-23 13:40:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
2021-09-09 22:13:48 +00:00
|
|
|
* @param array $returnVal
|
|
|
|
* @param array $lookup values
|
2021-11-23 13:40:35 +00:00
|
|
|
* @return UserOptionsLookup
|
|
|
|
*/
|
2021-09-09 22:13:48 +00:00
|
|
|
private function getUserOptionsLookupMock( $user, $returnVal, $lookup = [] ) {
|
2021-11-23 13:40:35 +00:00
|
|
|
$mock = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$mock->method( 'getOption' )
|
2021-09-09 22:13:48 +00:00
|
|
|
->willReturnCallback( static function ( $user, $key ) use ( $returnVal, $lookup ) {
|
|
|
|
return $lookup[ $key ] ?? $returnVal;
|
|
|
|
} );
|
2021-11-23 13:40:35 +00:00
|
|
|
return $mock;
|
|
|
|
}
|
2020-04-28 21:02:15 +00:00
|
|
|
}
|