mediawiki-skins-Vector/tests/phpunit/integration/FeatureManagement/Requirements/WvuiSearchTreatmentRequirementTest.php
Nicholas Ray 8c76a17e43 Move Wvui Search A/B Logic to FeatureManager
FeatureManager allows the logic to be centralized and allows clients to
ask about its state. For instance, SkinVector will make use of it in
I70277c1082a504fbd5f6023e9873e8071de7e35d.

Also:

* Adds WvuiSearchTreatmentRequirementTest to test A/B logic

WvuiSearchTreatmentRequirement/Test logic are adapted from
I878239a85ffbecb5e78d73aed5568c56dbd7d659.

Bug: T270202
Change-Id: Ia02349a7b41c7caf26fbd728e0be7d47488b97e5
2021-01-26 17:36:37 -07: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\WvuiSearchTreatmentRequirement;
/**
* @group Vector
* @coversDefaultClass \Vector\FeatureManagement\Requirements\WvuiSearchTreatmentRequirement
*/
class WvuiSearchTreatmentRequirementTest extends \MediaWikiTestCase {
public function providerWvuiSearchTreatmentRequirement() {
return [
[
// Is wvui search enabled
false,
// is A-B test enabled
false,
// note 0 = anon user
0,
false,
'If nothing enabled nobody gets wvui search'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
false,
// note 0 = anon user
0,
true,
'Anon users should get wvui search if enabled when A/B test disabled'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
false,
2,
true,
'Logged in users should get wvui search if enabled when A/B test disabled'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
false,
1,
true,
'All odd logged in users should get wvui search when A/B test disabled'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
true,
// note 0 = anon user
0,
true,
'Anon users with a/b test enabled should see wvui search when search config enabled'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
true,
2,
true,
'Even logged in users get wvui search when A/B test enabled'
],
[
// Is wvui search enabled
true,
// is A-B test enabled
true,
1,
false,
'Odd logged in users do not wvui search when A/B test enabled'
],
];
}
/**
* @covers ::isMet
* @dataProvider providerWvuiSearchTreatmentRequirement
* @param bool $wvuiSearchConfigValue
* @param bool $abValue
* @param int $userId
* @param bool $expected
* @param string $msg
*/
public function testWvuiSearchTreatmentRequirement(
$wvuiSearchConfigValue, $abValue, $userId, $expected, $msg
) {
$config = new HashConfig( [
Constants::CONFIG_KEY_USE_WVUI_SEARCH => $wvuiSearchConfigValue,
Constants::CONFIG_SEARCH_TREATMENT_AB_TEST => $abValue,
] );
$user = $this->getTestUser()->getUser();
$user->setId( $userId );
$requirement = new WvuiSearchTreatmentRequirement(
$config, $user
);
$this->assertSame( $requirement->isMet(), $expected, $msg );
}
}