Skip to content

Instantly share code, notes, and snippets.

@rizqidjamaluddin
Created April 28, 2015 13:35
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 rizqidjamaluddin/f8bb27ead807989d384d to your computer and use it in GitHub Desktop.
Save rizqidjamaluddin/f8bb27ead807989d384d to your computer and use it in GitHub Desktop.
<?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