/** * Algorithm for choosing auth strategy * * @todo Move validation and error handling into separate class * @return AbstractAuthStrategy */ public function create() { $post = $this->getPost(); $cookies = $this->getCookies(); $auth = null; switch (true) { case isset($post['ln'], $post['pw']): $auth = new LoginFormStrategy($post['ln'], $post['pw'], new User()); $post['ln'] || $auth->setError($auth::ERR_NOT_VALID_LOGIN); $post['pw'] || $auth->setError($auth::ERR_NOT_VALID_PASSWORD); break; case isset($cookies['id'], $cookies['pw']): $auth = new CookieStrategy($cookies['id'], $cookies['pw'], new User()); $cookies['id'] || $auth->setError($auth::ERR_NOT_VALID_UID); $cookies['pw'] || $auth->setError($auth::ERR_NOT_VALID_HASH); break; default: $auth = new GuestStrategy(new User()); } return $auth; }
/** * @covers Veles\Auth\Strategies\LoginFormStrategy::getPassword * @depends testSetPassword */ public function testGetPassword() { $login = '******'; $expected = uniqid(); $object = new LoginFormStrategy($login, $expected, new User()); $result = $object->getPassword(); $msg = 'LoginFormStrategy::getLogin() wrong behavior!'; $this->assertSame($expected, $result, $msg); }