-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
204 changes: 204 additions & 0 deletions
204
tests/integration/REST/GetUsersWithPermissionInfoToContentItemTest.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\AdminUi\REST; | ||
|
||
use Ibexa\Contracts\Core\Repository\RoleService; | ||
use Ibexa\Contracts\Core\Repository\UserService; | ||
use Ibexa\Contracts\Core\Repository\Values\User\UserCreateStruct; | ||
use Ibexa\Contracts\Test\Rest\WebTestCase; | ||
|
||
final class GetUsersWithPermissionInfoToContentItemTest extends WebTestCase | ||
{ | ||
private const ENDPOINT_URL = 'permission/users-with-permission-info/%d/%s/%s?%s'; | ||
private const HEADERS = [ | ||
'HTTP_ACCEPT' => 'application/json', | ||
'X-Siteaccess' => 'admin', | ||
]; | ||
private const MEDIA_CONTENT_ITEM_ID = 41; | ||
private const MEDIA_LOCATION_ID = 43; | ||
private const MODULE_CONTENT = 'content'; | ||
private const FUNCTION_EDIT = 'edit'; | ||
private const FUNCTION_READ = 'read'; | ||
|
||
private UserService $userService; | ||
|
||
private RoleService $roleService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$ibexaTestCore = $this->getIbexaTestCore(); | ||
$this->userService = $ibexaTestCore->getUserService(); | ||
$this->roleService = $ibexaTestCore->getRoleService(); | ||
|
||
$this->createUsers(); | ||
} | ||
|
||
/** | ||
* @dataProvider provideDataForTestGetUsersWithPermissionsEndpoint | ||
* | ||
* @param array<string, string> $queryParameters | ||
*/ | ||
public function testGetUsersWithPermissionsEndpoint( | ||
int $contentId, | ||
string $module, | ||
string $function, | ||
array $queryParameters, | ||
string $expectedResponse | ||
): void { | ||
$uri = $this->getUri($contentId, $module, $function, $queryParameters); | ||
$this->client->request('GET', $uri, [], [], self::HEADERS); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
self::assertSame(200, $response->getStatusCode()); | ||
self::assertSame($expectedResponse, $response->getContent()); | ||
} | ||
|
||
/** | ||
* @return iterable<array{ | ||
* int, | ||
* string, | ||
* string, | ||
* array<string, mixed>, | ||
* string, | ||
* }> | ||
*/ | ||
public function provideDataForTestGetUsersWithPermissionsEndpoint(): iterable | ||
{ | ||
yield 'Check content-read for content item 41' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_READ, | ||
[], | ||
'{"access":[{"name":"Administrator User","email":"[email protected]"},{"name":"John Doe","email":"[email protected]"},{"name":"Josh Bar","email":"[email protected]"}],"no_access":[{"name":"Anonymous User","email":"[email protected]"}]}', | ||
]; | ||
|
||
yield 'Check content-read for content item 41 and location 51' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_READ, | ||
['locationId' => 51], | ||
'{"access":[{"name":"Administrator User","email":"[email protected]"},{"name":"John Doe","email":"[email protected]"},{"name":"Josh Bar","email":"[email protected]"}],"no_access":[{"name":"Anonymous User","email":"[email protected]"}]}', | ||
]; | ||
|
||
yield 'Check content-read for content item 41 and phrase=adm' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_READ, | ||
['phrase' => 'Adm*'], | ||
'{"access":[{"name":"Administrator User","email":"[email protected]"}],"no_access":[]}', | ||
]; | ||
|
||
yield 'Check content-read for phrase=undef*' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_READ, | ||
['phrase' => 'undef*'], | ||
'{"access":[],"no_access":[]}', | ||
]; | ||
|
||
yield 'Check content-read for location 43 and phrase=anony' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_READ, | ||
[ | ||
'phrase' => 'anony*', | ||
'locationId' => self::MEDIA_LOCATION_ID, | ||
], | ||
'{"access":[],"no_access":[{"name":"Anonymous User","email":"[email protected]"}]}', | ||
]; | ||
|
||
yield 'Check content-edit for content item 2 and phrase=jo' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_EDIT, | ||
[ | ||
'phrase' => 'jo*', | ||
], | ||
'{"access":[{"name":"John Doe","email":"[email protected]"},{"name":"Josh Bar","email":"[email protected]"}],"no_access":[]}', | ||
]; | ||
|
||
yield 'Check content-edit for content item 41 and phrase=bar*' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_EDIT, | ||
[ | ||
'phrase' => 'bar*', | ||
], | ||
'{"access":[{"name":"Josh Bar","email":"[email protected]"}],"no_access":[]}', | ||
]; | ||
|
||
yield 'Check content-edit for content item 41 and location 43 and [email protected]' => [ | ||
self::MEDIA_CONTENT_ITEM_ID, | ||
self::MODULE_CONTENT, | ||
self::FUNCTION_EDIT, | ||
[ | ||
'phrase' => 'joshua*', | ||
'locationId' => self::MEDIA_LOCATION_ID, | ||
], | ||
'{"access":[{"name":"Josh Bar","email":"[email protected]"}],"no_access":[]}', | ||
]; | ||
} | ||
|
||
private function createUsers(): void | ||
{ | ||
$this->getIbexaTestCore()->setAdministratorUser(); | ||
|
||
$role = $this->roleService->loadRoleByIdentifier('Editor'); | ||
$editorGroup = $this->userService->loadUserGroupByRemoteId('3c160cca19fb135f83bd02d911f04db2'); | ||
|
||
$user1CreateStruct = $this->createUserCreateStruct('john', 'John', 'Doe', '[email protected]'); | ||
|
||
$user1 = $this->userService->createUser($user1CreateStruct, [$editorGroup]); | ||
$this->roleService->assignRoleToUser($role, $user1); | ||
|
||
$user2CreateStruct = $this->createUserCreateStruct('josh', 'Josh', 'Bar', '[email protected]'); | ||
$user2 = $this->userService->createUser($user2CreateStruct, [$editorGroup]); | ||
$this->roleService->assignRoleToUser($role, $user2); | ||
} | ||
|
||
private function createUserCreateStruct( | ||
string $login, | ||
string $firstName, | ||
string $lastName, | ||
string $email | ||
): UserCreateStruct { | ||
$userCreateStruct = $this->userService->newUserCreateStruct( | ||
$login, | ||
$email, | ||
$login, | ||
'eng-GB' | ||
); | ||
|
||
$userCreateStruct->setField('first_name', $firstName); | ||
$userCreateStruct->setField('last_name', $lastName); | ||
|
||
return $userCreateStruct; | ||
} | ||
|
||
/** | ||
* @param array<string, string> $queryParameters | ||
*/ | ||
private static function getUri( | ||
int $contentId, | ||
string $module, | ||
string $function, | ||
array $queryParameters = [] | ||
): string { | ||
return sprintf( | ||
self::ENDPOINT_URL, | ||
$contentId, | ||
$module, | ||
$function, | ||
http_build_query($queryParameters), | ||
); | ||
} | ||
} |
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