/** * 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\CookieStrategy::getId * @depends testSetId */ public function testGetId() { $expected = rand(); $hash = uniqid(); $object = new CookieStrategy($expected, $hash, new User()); $result = $object->getId(); $msg = 'CookieStrategy::getId() returns wrong result!'; $this->assertSame($expected, $result, $msg); }