instance = new RequireUsername(); $aclMock = $this->getMockBuilder('\tao_models_classes_UserService') ->disableOriginalConstructor() ->getMock(); $aclMock->method('loginExists') ->willReturn(false); $this->instance->setServiceLocator($this->getServiceLocatorMock([ \tao_models_classes_UserService::SERVICE_ID => $aclMock ])); } public function tearDown(): void { $this->instance = null; } public function testIsAuthorized() { $_COOKIE['login'] = 'loginFixture'; $this->assertTrue($this->instance->isAuthorized()); unset($_COOKIE['login']); $this->assertFalse($this->instance->isAuthorized()); } public function testGetAuthorizationUrl() { $urlFixture = 'fakeUrl'; $expectedResult = _url('login', 'Authenticator', 'taoClientDiagnostic', array('successCallback' => $urlFixture)); $this->assertEquals($this->instance->getAuthorizationUrl($urlFixture), $expectedResult); } public function getLoginData() { return [ ['', true, InvalidLoginException::class], ['loginFixture', true, InvalidLoginException::class], ['loginFixture', false, '', true, true], ['loginFixture', true, InvalidLoginException::class, true], ]; } /** * @dataProvider getLoginData */ public function testValidateLogin($loginFixture, $hasException, $exception, $useACLService = false, $returnACL = false) { if ($useACLService) { $aclFixture = $this->getMockBuilder('\tao_models_classes_UserService') ->disableOriginalConstructor() ->getMock(); $aclFixture->method('loginExists') ->willReturn($returnACL); $this->instance->setServiceLocator($this->getServiceLocatorMock([ \tao_models_classes_UserService::SERVICE_ID => $aclFixture ])); } if ($hasException) { $this->expectException($exception); } $result = $this->instance->validateLogin($loginFixture); if (!$hasException) { $this->assertTrue($result); } } }