Skip to content

Instantly share code, notes, and snippets.

@hyusetiawan
Created March 26, 2013 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyusetiawan/5247406 to your computer and use it in GitHub Desktop.
Save hyusetiawan/5247406 to your computer and use it in GitHub Desktop.
class UserTest extends MyTestCase
public function testValidRegistration($user = null)
{
if ($user === null) {
$user = TestData::$USERS[0];
}
$user['password_confirmation'] = $user['password'];
$resp = $this->json('POST', '/user', $user);
$this->responseIs(Status::CREATED);
//check the returned data is accurate
$this->assertSpecificKeys(['email', 'username'], $user);
//check that the user is automatically logged in
$this->assertEquals(Confide::user()->email, $user['email']);
}
public function testValidLogout()
{
$this->json('GET', '/user/logout');
$this->assertNull(Confide::user());
}
public function testValidLoginWithEmail($user = null)
{
if ($user === null){
$user = TestData::$USERS[0];
}
$this->testValidRegistration($user);
$this->testValidLogout();
//@NOTE:even though I pass this data, what I get from Request::json is registration data from line 35
$resp = $this->json('POST', '/user/login', ['login' => $user['email'], 'password' => $user['password']]);
$this->assertEquals(Confide::user()->email, $user['email']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment