added supervisor setting for user (#4251)
This commit is contained in:
@@ -16,12 +16,15 @@ use App\Entity\User;
|
||||
*/
|
||||
class UserControllerTest extends APIControllerBaseTest
|
||||
{
|
||||
public function testIsSecure()
|
||||
public function testIsSecure(): void
|
||||
{
|
||||
$this->assertUrlIsSecured('/api/users');
|
||||
}
|
||||
|
||||
public function getRoleTestData()
|
||||
/**
|
||||
* @return array<array<string>>
|
||||
*/
|
||||
public function getRoleTestData(): array
|
||||
{
|
||||
return [
|
||||
[User::ROLE_USER],
|
||||
@@ -33,12 +36,12 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
/**
|
||||
* @dataProvider getRoleTestData
|
||||
*/
|
||||
public function testIsSecureForRole(string $role)
|
||||
public function testIsSecureForRole(string $role): void
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole($role, '/api/users');
|
||||
}
|
||||
|
||||
public function testGetCollection()
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/api/users');
|
||||
@@ -52,7 +55,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCollectionWithQuery()
|
||||
public function testGetCollectionWithQuery(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/api/users', 'GET', ['visible' => 2, 'orderBy' => 'email', 'order' => 'DESC', 'term' => 'chris']);
|
||||
@@ -66,7 +69,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCollectionWithQuery2()
|
||||
public function testGetCollectionWithQuery2(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/api/users', 'GET', ['visible' => 3, 'orderBy' => 'email', 'order' => 'DESC']);
|
||||
@@ -80,7 +83,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetEntity()
|
||||
public function testGetEntity(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/api/users/1');
|
||||
@@ -93,7 +96,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
self::assertEquals('Clara Haynes', $result['alias']);
|
||||
}
|
||||
|
||||
public function testGetMyProfile()
|
||||
public function testGetMyProfile(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/api/users/me');
|
||||
@@ -106,18 +109,18 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
self::assertEquals('', $result['alias']);
|
||||
}
|
||||
|
||||
public function testNotFound()
|
||||
public function testNotFound(): void
|
||||
{
|
||||
$this->assertEntityNotFound(User::ROLE_SUPER_ADMIN, '/api/users/99');
|
||||
}
|
||||
|
||||
public function testGetEntityAccessDenied()
|
||||
public function testGetEntityAccessDenied(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertApiAccessDenied($client, '/api/users/4', 'You are not allowed to view this profile');
|
||||
}
|
||||
|
||||
public function testGetEntityAccessAllowedForOwnProfile()
|
||||
public function testGetEntityAccessAllowedForOwnProfile(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/users/2');
|
||||
@@ -127,7 +130,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
self::assertApiResponseTypeStructure('UserEntity', $result);
|
||||
}
|
||||
|
||||
public function testPostAction()
|
||||
public function testPostAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$data = [
|
||||
@@ -136,6 +139,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
'title' => 'asdfghjkl',
|
||||
'plainPassword' => 'foo@example.com',
|
||||
'enabled' => true,
|
||||
'supervisor' => 2,
|
||||
'language' => 'ru',
|
||||
'timezone' => 'Europe/Paris',
|
||||
'roles' => [
|
||||
@@ -158,7 +162,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
self::assertEquals(['ROLE_TEAMLEAD', 'ROLE_ADMIN'], $result['roles']);
|
||||
}
|
||||
|
||||
public function testPostActionWithShortPassword()
|
||||
public function testPostActionWithShortPassword(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$data = [
|
||||
@@ -181,7 +185,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
$this->assertApiCallValidationError($response, ['plainPassword']);
|
||||
}
|
||||
|
||||
public function testPostActionWithValidationErrors()
|
||||
public function testPostActionWithValidationErrors(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$data = [
|
||||
@@ -201,7 +205,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
$this->assertApiCallValidationError($response, ['username', 'email', 'plainPassword', 'language', 'timezone', 'roles']);
|
||||
}
|
||||
|
||||
public function testPostActionWithInvalidUser()
|
||||
public function testPostActionWithInvalidUser(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$data = [
|
||||
@@ -217,7 +221,7 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
$this->assertApiResponseAccessDenied($response, 'Access denied.');
|
||||
}
|
||||
|
||||
public function testPatchAction()
|
||||
public function testPatchAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$data = [
|
||||
@@ -261,19 +265,19 @@ class UserControllerTest extends APIControllerBaseTest
|
||||
self::assertEquals(['ROLE_TEAMLEAD'], $result['roles']);
|
||||
}
|
||||
|
||||
public function testPatchActionWithUnknownUser()
|
||||
public function testPatchActionWithUnknownUser(): void
|
||||
{
|
||||
$this->assertEntityNotFoundForPatch(User::ROLE_SUPER_ADMIN, '/api/users/255', []);
|
||||
}
|
||||
|
||||
public function testPatchActionWithInvalidUser()
|
||||
public function testPatchActionWithInvalidUser(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->request($client, '/api/users/1', 'PATCH', [], json_encode(['language' => 'hu']));
|
||||
$this->assertApiResponseAccessDenied($client->getResponse(), 'Not allowed to edit user');
|
||||
}
|
||||
|
||||
public function testPatchActionWithValidationErrors()
|
||||
public function testPatchActionWithValidationErrors(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$data = [
|
||||
|
||||
Reference in New Issue
Block a user