added supervisor setting for user (#4251)

This commit is contained in:
Kevin Papst
2023-08-20 13:18:35 +02:00
committed by GitHub
parent 9baa477bed
commit 3e61e0dce6
28 changed files with 358 additions and 612 deletions

View File

@@ -78,7 +78,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
$this->assertEquals($pageSize, $response->headers->get('X-Per-Page'));
}
protected function assertRequestIsSecured(HttpKernelBrowser $client, string $url, $method = 'GET'): void
protected function assertRequestIsSecured(HttpKernelBrowser $client, string $url, string $method = 'GET'): void
{
$this->request($client, $url, $method);
$this->assertResponseIsSecured($client->getResponse(), $url);
@@ -126,7 +126,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
]);
}
public function request(HttpKernelBrowser $client, string $url, $method = 'GET', array $parameters = [], string $content = null): Crawler
public function request(HttpKernelBrowser $client, string $url, string $method = 'GET', array $parameters = [], string $content = null): Crawler
{
$server = ['HTTP_CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json'];
@@ -355,6 +355,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
'enabled' => 'bool',
'alias' => '@string',
'title' => '@string',
'supervisor' => ['result' => 'object', 'type' => '@UserEntity'],
'avatar' => '@string',
'color' => '@string',
'teams' => ['result' => 'array', 'type' => 'Team'],

View File

@@ -17,12 +17,12 @@ use App\Tests\Controller\ControllerBaseTest;
*/
class ApiDocControllerTest extends ControllerBaseTest
{
public function testIsSecure()
public function testIsSecure(): void
{
$this->assertUrlIsSecured('/api/doc');
}
public function testGetDocs()
public function testGetDocs(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/doc');
@@ -47,7 +47,7 @@ class ApiDocControllerTest extends ControllerBaseTest
self::assertEquals($expectedKeys, $actual, sprintf('Expected %s sections in API docs, but found %s.', \count($actual), \count($expectedKeys)));
}
public function testGetJsonDocs()
public function testGetJsonDocs(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/doc.json');

View File

@@ -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 = [