Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

RoleContext.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\Features\Context;
8
9 use Behat\Behat\Context\Context;
10 use PHPUnit\Framework\Assert as Assertion;
11 use EzSystems\PlatformBehatBundle\Context\RepositoryContext;
12 use eZ\Publish\API\Repository\Repository;
13 use eZ\Publish\API\Repository\RoleService;
14 use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
15
19 class RoleContext implements Context
20 {
21 use RepositoryContext;
22
24 protected $roleService;
25
30 public function __construct(Repository $repository, RoleService $roleService)
31 {
32 $this->setRepository($repository);
33 $this->roleService = $roleService;
34 }
35
43 public function ensureRoleExists($name)
44 {
45 try {
46 $role = $this->roleService->loadRoleByIdentifier($name);
47 } catch (ApiExceptions\NotFoundException $e) {
48 $roleCreateStruct = $this->roleService->newRoleCreateStruct($name);
49 $roleDraft = $this->roleService->createRole($roleCreateStruct);
50 $this->roleService->publishRoleDraft($roleDraft);
51 $role = $this->roleService->loadRole($roleDraft->id);
52 }
53
54 return $role;
55 }
56
64 public function getRole($identifier)
65 {
66 $role = null;
67 try {
68 $role = $this->roleService->loadRoleByIdentifier($identifier);
69 } catch (ApiExceptions\NotFoundException $e) {
70 // Role not found, do nothing, returns null
71 }
72
73 return $role;
74 }
75
83 public function iHaveRole($name)
84 {
85 return $this->ensureRoleExists($name);
86 }
87
93 public function iSeeRole($name)
94 {
95 $role = $this->getRole($name);
96 Assertion::assertNotNull(
97 $role,
98 "Couldn't find Role with name $name"
99 );
100 }
101
105 public function noAssginedPolicies($name)
106 {
107 $role = $this->getRole($name);
108 Assertion::assertNotNull(
109 $role,
110 "Couldn't find Role with name $name"
111 );
112 $policies = $role->getPolicies();
113 Assertion::assertEmpty($policies, "Role $name has policies associated");
114 }
115
119 public function noAssigneGroups($name)
120 {
121 $role = $this->getRole($name);
122 Assertion::assertNotNull(
123 $role,
124 "Couldn't find Role with name $name"
125 );
126 $roleAssigments = $this->roleService->getRoleAssignments($role);
127 Assertion::assertEmpty($roleAssigments, "Role $name has Users or groups associated");
128 }
129
135 public function iDontSeeRole($name)
136 {
137 $role = $this->getRole($name);
138 Assertion::assertNull(
139 $role,
140 "Found Role with name $name"
141 );
142 }
143 }
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext
Sentences for Roles.
Definition: RoleContext.php:20
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\iSeeRole
iSeeRole($name)
@Then I see that a/an :name role exists
Definition: RoleContext.php:93
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\$roleService
$roleService
Definition: RoleContext.php:24
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\noAssginedPolicies
noAssginedPolicies($name)
@Given :name do not have any assigned policies
Definition: RoleContext.php:105
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\getRole
getRole($identifier)
Fetches the role with identifier.
Definition: RoleContext.php:64
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\noAssigneGroups
noAssigneGroups($name)
@Given :name do not have any assigned Users and groups
Definition: RoleContext.php:119
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\iHaveRole
iHaveRole($name)
@Given a/an :name role exists
Definition: RoleContext.php:83
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\ensureRoleExists
ensureRoleExists($name)
Make sure a Role with name $name exists in parent group.
Definition: RoleContext.php:43
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\iDontSeeRole
iDontSeeRole($name)
@Then I see that a/an :name role does not exists
Definition: RoleContext.php:135
eZ\Bundle\EzPublishCoreBundle\Features\Context\RoleContext\__construct
__construct(Repository $repository, RoleService $roleService)
@injectService $repository @ezpublish.api.repository @injectService $roleService @ezpublish....
Definition: RoleContext.php:30
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\API\Repository\Repository
Repository interface.
Definition: API/Repository/Repository.php:16
eZ\Publish\API\Repository\RoleService
This service provides methods for managing Roles and Policies.
Definition: API/Repository/RoleService.php:26
eZ\Bundle\EzPublishCoreBundle\Features\Context
Definition: BasicContentContext.php:7
eZ\Publish\API\Repository\Exceptions
Definition: API/Repository/Exceptions/BadStateException.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.