Created
April 28, 2015 13:35
-
-
Save rizqidjamaluddin/f8bb27ead807989d384d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserTest extends \IntegrationTest | |
{ | |
/** | |
* @test | |
*/ | |
public function users_cannot_self_register() | |
{ | |
$response = $this->api('post', 'users/register', [ | |
'email' => 'email@example.com', | |
'first_name' => 'Jane', | |
'last_name' => 'Doe', | |
'password' => 'password', | |
'groups' => ['admin'] | |
]); | |
$this->assertResponseStatus(401); | |
} | |
/** | |
* @test | |
*/ | |
public function users_can_be_registered_by_an_admin() | |
{ | |
$this->asAdmin(); | |
$response = $this->api('post', 'users/register', [ | |
'email' => 'jane_doe@example.com', | |
'first_name' => 'Jane', | |
'last_name' => 'Doe', | |
'password' => 'password', | |
'groups' => ['admin'] | |
]); | |
$this->assertResponseOk(); | |
// assert response contained user object | |
$this->assertEquals('Jane', $response->data->first_name); | |
$this->assertEquals('Doe', $response->data->last_name); | |
$this->assertEquals('Jane Doe', $response->data->name); | |
$this->assertEquals('jane_doe@example.com', $response->data->email); | |
$this->assertEquals(['admin'], $response->data->groups); | |
// fetch to ensure it was stored properly | |
$fetch = $this->api('get', 'users?findEmail=jane_doe@example.com'); | |
$this->assertResponseOk(); | |
$this->assertEquals('Jane Doe', $fetch->data->name); | |
} | |
/** | |
* @test | |
*/ | |
public function users_cannot_be_given_an_invalid_group() | |
{ | |
$this->asAdmin(); | |
$response = $this->api('post', 'users/register', [ | |
'email' => 'jane_doe@example.com', | |
'first_name' => 'Jane', | |
'last_name' => 'Doe', | |
'password' => 'password', | |
'groups' => ['nonexistent-group'] | |
]); | |
$this->assertResponseStatus(500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment