Debian Codegraph @

skins/Vector/tests/phpunit/unit/FeatureManagement/Requirements/ABRequirementTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @since 1.42
21 */
22
23 namespace MediaWiki\Skins\Vector\Tests\Unit\FeatureManagement\Requirements;
24
25 use MediaWiki\Config\HashConfig;
26 use MediaWiki\Skins\Vector\FeatureManagement\Requirements\ABRequirement;
27 use MediaWiki\User\UserIdentity;
28 use PHPUnit\Framework\TestCase;
29
30 /**
31 * @group Vector
32 * @group FeatureManagement
33 * @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\ABRequirement
34 */
35 class ABRequirementTest extends TestCase {
36
37 private function createUserMock( $userId ) {
38 $userMock = $this->createMock( UserIdentity::class );
39 $userMock->method( 'getId' )->willReturn( $userId );
40 return $userMock;
41 }
42
43 /**
44 * Provides different scenarios for AB test enrollment.
45 */
46 public function enrollmentProvider(): array {
47 return [
48 'Experiment Disabled' => [
49 [ 'enabled' => false, 'name' => 'mockExperiment' ],
50 // User ID
51 1,
52 // Expected result
53 true
54 ],
55 'Experiment Enabled, Wrong Name' => [
56 [ 'enabled' => true, 'name' => 'mockWrongExperiment' ],
57 1,
58 true
59 ],
60 'Experiment Enabled, Correct Name, User in Control Group' => [
61 [ 'enabled' => true, 'name' => 'mockExperiment' ],
62 2,
63 false
64 ],
65 'Experiment Enabled, Correct Name, User in Test Group' => [
66 [ 'enabled' => true, 'name' => 'mockExperiment' ],
67 1,
68 true
69 ],
70 ];
71 }
72
73 /**
74 * @dataProvider enrollmentProvider
75 * @covers ::isMet
76 */
77 public function testABRequirement( $experimentConfig, $userId, $expectedResult ) {
78 $config = new HashConfig( [
79 'VectorWebABTestEnrollment' => $experimentConfig
80 ] );
81
82 $user = $this->createUserMock( $userId );
83
84 $abRequirement = new ABRequirement(
85 $config,
86 $user,
87 'mockExperiment',
88 );
89
90 $this->assertEquals( $expectedResult, $abRequirement->isMet() );
91 }
92
93 /**
94 * @covers ::getName
95 */
96 public function testGetName() {
97 $config = new HashConfig();
98 $user = $this->createUserMock( 0 );
99 $experimentName = 'mockExperiment';
100 $name = 'ABTestRequirement';
101
102 $abRequirement = new ABRequirement(
103 $config,
104 $user,
105 $experimentName,
106 $name
107 );
108
109 $this->assertEquals( $name, $abRequirement->getName() );
110 }
111 }