Skip to content

Commit

Permalink
EZP-29083: Error after trying to delete role assignment (#2377)
Browse files Browse the repository at this point in the history
* EZP-29083: Error after trying to delete role assignment

* EZP-29083: Error after trying to delete role assignment - integration test

* EZP-29083: Error after trying to delete role assignment - new implementation
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Aug 2, 2018
1 parent 01a5396 commit 351a782
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Repository/Tests/RoleServiceTest.php
Expand Up @@ -1781,6 +1781,51 @@ public function testDeletePolicy()
$this->assertSame(array(), $role->getPolicies());
}

/**
* Test for the addPolicyByRoleDraft() method.
*
* @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft()
*/
public function testAddPolicyWithRoleAssignment()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$roleService = $repository->getRoleService();
$userService = $repository->getUserService();

/* Create new user group */
$mainGroupId = $this->generateId('group', 4);
$parentUserGroup = $userService->loadUserGroup($mainGroupId);
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-US');
$userGroupCreate->setField('name', 'newUserGroup');
$userGroup = $userService->createUserGroup($userGroupCreate, $parentUserGroup);

/* Create Role */
$roleCreate = $roleService->newRoleCreateStruct('newRole');
$roleDraft = $roleService->createRole($roleCreate);
$roleService->publishRoleDraft($roleDraft);

$role = $roleService->loadRole($roleDraft->id);
$roleService->assignRoleToUserGroup($role, $userGroup);

$roleAssignmentsBeforeNewPolicy = $roleService->getRoleAssignments($role)[0];

/* Add new policy to existing role */
$roleUpdateDraft = $roleService->createRoleDraft($role);
$roleUpdateDraft = $roleService->addPolicyByRoleDraft(
$roleUpdateDraft,
$roleService->newPolicyCreateStruct('content', 'create')
);
$roleService->publishRoleDraft($roleUpdateDraft);

$roleAfterUpdate = $roleService->loadRole($role->id);
$roleAssignmentsAfterNewPolicy = $roleService->getRoleAssignments($roleAfterUpdate)[0];
/* END: Use Case */

$this->assertNotEquals($roleAssignmentsBeforeNewPolicy->id, $roleAssignmentsAfterNewPolicy->id);
}

/**
* Test loading user/group role assignments.
*
Expand Down

0 comments on commit 351a782

Please sign in to comment.