for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Containers\Authorization\UI\API\Tests\Functional;
use App\Containers\Authorization\Models\Role;
use App\Containers\Authorization\Tests\TestCase;
use App\Containers\User\Models\User;
/**
* Class SyncUserRolesTest.
*
* @author Mahmoud Zalt <[email protected]>
*/
class SyncUserRolesTest extends TestCase
{
protected $endpoint = 'post@roles/sync';
protected $access = [
'roles' => 'admin',
'permissions' => '',
];
public function testSyncMultipleRolesOnUser()
$role1 = factory(Role::class)->create(['display_name' => '111']);
$role2 = factory(Role::class)->create(['display_name' => '222']);
$randomUser = factory(User::class)->create();
$randomUser->assignRole($role1);
$data = [
'roles_ids' => [
$role1->getHashedKey(),
$role2->getHashedKey(),
],
'user_id' => $randomUser->getHashedKey(),
// send the HTTP request
$response = $this->makeCall($data);
// assert response status is correct
$this->assertEquals('200', $response->getStatusCode());
$responseContent = $this->getResponseContent($response);
$this->assertTrue(count($responseContent->data->roles->data) > 1);
$this->assertEquals($data['roles_ids'][0], $responseContent->data->roles->data[0]->id);
$this->assertEquals($data['roles_ids'][1], $responseContent->data->roles->data[1]->id);
}