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
|
|
|
|
*/
|
|
|
|
|
2021-11-23 13:40:35 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
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' )
|
2021-05-17 08:04:07 +00:00
|
|
|
->with( $this->anything(), 'beta' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( 'alpha' );
|
|
|
|
|
|
|
|
$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( [
|
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-11-23 13:40:35 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', 'beta' );
|
|
|
|
|
|
|
|
$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' )
|
2021-05-17 08:04:07 +00:00
|
|
|
->with( $this->anything(), 'beta' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( 'beta' );
|
|
|
|
|
|
|
|
$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( [
|
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-11-23 13:40:35 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', 'beta' );
|
|
|
|
|
|
|
|
$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' )
|
2021-05-17 08:04:07 +00:00
|
|
|
->with( $this->anything(), '1' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( '1' );
|
|
|
|
|
|
|
|
$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( [
|
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-11-23 13:40:35 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '1', '1' );
|
|
|
|
|
|
|
|
$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.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVersion
|
|
|
|
* @covers ::isLegacy
|
|
|
|
*/
|
|
|
|
public function testConfigAnon() {
|
|
|
|
$request = $this->getMockBuilder( \WebRequest::class )->getMock();
|
|
|
|
$request
|
|
|
|
->method( 'getVal' )
|
2021-05-17 08:04:07 +00:00
|
|
|
->with( $this->anything(), '2' )
|
2020-04-28 21:02:15 +00:00
|
|
|
->willReturn( '2' );
|
|
|
|
|
|
|
|
$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( [
|
|
|
|
'VectorDefaultSkinVersion' => '2',
|
|
|
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
|
|
|
] );
|
|
|
|
|
2021-11-23 13:40:35 +00:00
|
|
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', '2' );
|
|
|
|
|
|
|
|
$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
|
|
|
|
* @param mixed|null $defaultOverride
|
|
|
|
* @param mixed|null $returnVal
|
|
|
|
* @return UserOptionsLookup
|
|
|
|
*/
|
|
|
|
private function getUserOptionsLookupMock( $user, $defaultOverride, $returnVal ) {
|
|
|
|
$mock = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$mock->method( 'getOption' )
|
|
|
|
->with( $user, $this->anything(), $defaultOverride )
|
|
|
|
->willReturn( $returnVal );
|
|
|
|
return $mock;
|
|
|
|
}
|
2020-04-28 21:02:15 +00:00
|
|
|
}
|