Env::get('_test_foo'); $this->assert(false, 'Exception accessing unknown Env value'); } catch (\Exception $e) { $this->assert(true, 'Exception accessing unknown Env value'); } Env::set('_test_foo', 'bar'); $this->assertEqual(Env::get('_test_foo'), 'bar', 'Read Env value'); Env::set('_test_foo', 'a', 10); $this->assertEqual(Env::get('_test_foo'), 'a', 'Apply higher priority value'); Env::set('_test_foo', 'b', -5); $this->assertEqual(Env::get('_test_foo'), 'a', 'Ignore low priority value'); Env::push('_test_foo', 'c'); $this->assertEqual(Env::get('_test_foo'), 'c', 'Push env value'); Env::push('_test_foo', 'd'); $this->assertEqual(Env::get('_test_foo'), 'd', 'Push another env value'); Env::pop('_test_foo'); $this->assertEqual(Env::get('_test_foo'), 'c', 'Pop env value'); Env::pop('_test_foo'); $this->assertEqual(Env::get('_test_foo'), 'a', 'Pop another env value'); try { Env::pop('_test_foo'); $this->assert(false, 'Exception popping too many times'); } catch (\Exception $e) { $this->assert(true, 'Exception popping too many times'); } try { Env::pop('_test_bar', 'c'); $this->assert(false, 'Exception popping unknown Env value'); } catch (\Exception $e) { $this->assert(true, 'Exception popping unknown Env value'); }
$returnedId = Auth::userIdIfCredentialsValid($email, $password); $this->assertEqual($returnedId, null, 'Verify incorrect email fails'); // correct username, incorrect password $email = 'justine'; $password = '******'; $id = Auth::userIdByEmail($email); $db->User->prepareForCall('byId', [$id], (object) ['id' => $id, 'type' => 'test', 'email' => 'justine', 'password' => $passwordHash, 'signature' => '8e82e581a143b6f8d30206891ca2549214e05afc']); $returnedId = Auth::userIdIfCredentialsValid($email, $password); $this->assertEqual($returnedId, null, 'Verify incorrect password fails'); // correct password $password = '******'; $returnedId = Auth::userIdIfCredentialsValid($email, $password); $this->assertEqual($returnedId, $id, 'Verify correct credentials succeed'); // no cookie should mean no logged in user $cookieManager->prepareForCall('get', ['u'], null); $u = Auth::loggedInUser(); $this->assertEqual($u, null, "Check for no logged in user"); // logged in user with bad cookie should mean no logged in user $cookieManager->prepareForCall('get', ['u'], 'blah'); $cookieManager->prepareForCall('clear', ['u']); $db->LoginSession->prepareForCall('byId', ['blah'], function () { throw new \Exception("Invalid id"); }); $db->LoginSession->prepareForCall('purge', ['blah']); $u = Auth::loggedInUser(); $this->assertEqual($u, null, "Check for no logged in user with invalid cookie"); Env::pop('cookie'); // more! $this->fail('TODO: test more stuff'); Env::pop('db');