diff --git a/tests/phpunit/unit/FeatureManagement/Requirements/LoggedInRequirementTest.php b/tests/phpunit/unit/FeatureManagement/Requirements/LoggedInRequirementTest.php new file mode 100644 index 000000000..39f9dec5e --- /dev/null +++ b/tests/phpunit/unit/FeatureManagement/Requirements/LoggedInRequirementTest.php @@ -0,0 +1,87 @@ + [ + // User is logged in + true, + // Expected isMet() result + true + ], + 'Anonymous user' => [ + // User is not logged in + false, + // Expected isMet() result + false + ] + ]; + } + + /** + * @covers ::getName + */ + public function testGetName() { + // Mock the User object + $userMock = $this->createMock( User::class ); + $requirementName = 'mockedUserLoggedInRequirement'; + + // Instantiate the LoggedInRequirement with the mock User object and the requirement name + $loggedInRequirement = new LoggedInRequirement( $userMock, $requirementName ); + + // Assert that the getName method returns the correct requirement name + $this->assertEquals( $requirementName, $loggedInRequirement->getName(), 'Failed testing getName method.' ); + } + + /** + * @dataProvider userProvider + * @covers ::isMet + * @param bool $isUserLoggedIn + * @param bool $expectedResult + */ + public function testIsMet( bool $isUserLoggedIn, bool $expectedResult ) { + // Mock the User object + $userMock = $this->createMock( User::class ); + // Setup the isRegistered method to return the login state + $userMock->method( 'isRegistered' )->willReturn( $isUserLoggedIn ); + + // Instantiate the LoggedInRequirement with the mock User object and a dummy name + $loggedInRequirement = new LoggedInRequirement( $userMock, 'mockedUserLoggedInRequirement' ); + + // Assert that the isMet method returns the expected boolean value + $this->assertEquals( $expectedResult, $loggedInRequirement->isMet(), 'Failed testing isMet method.' ); + } + +}