mediawiki-skins-Vector/tests/phpunit/integration/FeatureManagement/Requirements/SearchInHeaderRequirementTest.php
jdlrobson 7449c7fdf6 A/B test of search in header for logged in users
A new config flag is added that buckets 50% of users into the old
header and the 50% into the new header.

Bug: T249363
Change-Id: I8b4fa475f9cd7e61ad2989e2a1485e7e64c8ab3f
2020-09-14 14:22:46 +01:00

128 lines
3.1 KiB
PHP

<?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.36
*/
use Vector\Constants;
use Vector\FeatureManagement\Requirements\SearchInHeaderRequirement;
/**
* @group Vector
* @coversDefaultClass \Vector\FeatureManagement\Requirements\SearchInHeaderRequirement
*/
class SearchInHeaderRequirementTest extends \MediaWikiTestCase {
public function providerSearchInHeaderRequirement() {
return [
[
// Is enabled for anons
false,
// is A-B test enabled
false,
// note 0 = anon user
0,
false,
'If nothing enabled nobody gets search in header'
],
[
// Is enabled for anons
true,
// is A-B test enabled
false,
// note 0 = anon user
0,
true,
'All anons should get search in header if enable but when A/B test disabled'
],
[
// Is enabled for anons
true,
// is A-B test enabled
false,
0,
true,
'All even logged in users should get search in header when A/B test disabled'
],
[
// Is enabled for anons
true,
// is A-B test enabled
false,
1,
true,
'All odd logged in users should get search in header when A/B test disabled'
],
[
// Is enabled for anons
true,
// is A-B test enabled
true,
// note 0 = anon user
0,
true,
'All anons get search in header even when A/B enabled'
],
[
// Is enabled for anons
true,
// is A-B test enabled
true,
2,
true,
'Bucketed users get search in header when A/B test enabled'
],
[
// Is enabled for anons
true,
// is A-B test enabled
true,
1,
false,
'Non-Bucketed users do not get search in header when A/B test enabled'
],
];
}
/**
* @covers ::isMet
* @dataProvider providerSearchInHeaderRequirement
* @param bool $searchInHeaderConfigValue
* @param bool $abValue
* @param int $userId
* @param bool $expected
* @param string $msg
*/
public function testSearchInHeaderRequirement(
$searchInHeaderConfigValue, $abValue, $userId, $expected, $msg
) {
$config = new HashConfig( [
Constants::CONFIG_SEARCH_IN_HEADER => $searchInHeaderConfigValue,
Constants::CONFIG_SEARCH_IN_HEADER_AB => $abValue,
] );
$user = $this->getTestUser()->getUser();
$user->setId( $userId );
$requirement = new SearchInHeaderRequirement(
$config, $user
);
$this->assertSame( $requirement->isMet(), $expected, $msg );
}
}