Debian Codegraph @

skins/Vector/tests/phpunit/unit/FeatureManagement/Requirements/LoggedInRequirementTest.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\Skins\Vector\FeatureManagement\Requirements\LoggedInRequirement;
26 use MediaWiki\User\UserIdentity;
27 use PHPUnit\Framework\TestCase;
28
29 /**
30 * @group Vector
31 * @group FeatureManagement
32 * @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\LoggedInRequirement
33 */
34 class LoggedInRequirementTest extends TestCase {
35
36 public function userProvider(): array {
37 return [
38 'Logged-in user' => [
39 // User is logged in
40 true,
41 // Expected isMet() result
42 true
43 ],
44 'Anonymous user' => [
45 // User is not logged in
46 false,
47 // Expected isMet() result
48 false
49 ]
50 ];
51 }
52
53 /**
54 * @covers ::getName
55 */
56 public function testGetName() {
57 // Mock the User object
58 $userMock = $this->createMock( UserIdentity::class );
59 $requirementName = 'mockedUserLoggedInRequirement';
60
61 // Instantiate the LoggedInRequirement with the mock User object and the requirement name
62 $loggedInRequirement = new LoggedInRequirement( $userMock, $requirementName );
63
64 // Assert that the getName method returns the correct requirement name
65 $this->assertEquals( $requirementName, $loggedInRequirement->getName(), 'Failed testing getName method.' );
66 }
67
68 /**
69 * @dataProvider userProvider
70 * @covers ::isMet
71 * @param bool $isUserLoggedIn
72 * @param bool $expectedResult
73 */
74 public function testIsMet( bool $isUserLoggedIn, bool $expectedResult ) {
75 // Mock the User object
76 $userMock = $this->createMock( UserIdentity::class );
77 // Setup the isRegistered method to return the login state
78 $userMock->method( 'isRegistered' )->willReturn( $isUserLoggedIn );
79
80 // Instantiate the LoggedInRequirement with the mock User object and a dummy name
81 $loggedInRequirement = new LoggedInRequirement( $userMock, 'mockedUserLoggedInRequirement' );
82
83 // Assert that the isMet method returns the expected boolean value
84 $this->assertEquals( $expectedResult, $loggedInRequirement->isMet(), 'Failed testing isMet method.' );
85 }
86
87 }