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

Bundle/EzPublishRestBundle/Features/Context/SubContext/User.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext;
8
9 use eZ\Publish\API\Repository\Exceptions\NotFoundException;
10 use eZ\Publish\Core\Base\Exceptions\BadStateException;
11 use PHPUnit\Framework\Assert as Assertion;
12
16 trait User
17 {
21 public function thereIsAUserWithTheLogin($login)
22 {
23 Assertion::assertInstanceOf(
24 'eZ\Publish\API\Repository\Values\User\User',
25 $this->getRepository()->getUserService()->loadUserByLogin($login)
26 );
27 }
28
32 public function thereIsNotAUserWithTheLogin($login)
33 {
34 try {
35 $this->getRepository()->getUserService()->loadUserByLogin($login);
36 } catch (NotFoundException $e) {
37 return;
38 }
39 throw new BadStateException('login', "A user with the login $login exists");
40 }
41
48 public function thereIsAUserWithTheEmail($email)
49 {
50 $users = $this->getRepository()->getUserService()->loadUsersByEmail($email);
51
52 Assertion::assertGreaterThan(0, count($users), "No user was found with the email '$email'");
53 Assertion::assertInstanceOf('eZ\Publish\API\Repository\Values\User\User', $users[0]);
54 }
55
62 public function thereAreNoUsersWithTheEmail($email)
63 {
64 $users = $this->getRepository()->getUserService()->loadUsersByEmail($email);
65 Assertion::assertEquals(0, count($users), "Users with the email '$email' exist");
66 }
67
71 public function responseContainsOnlyTheUserWithTheLogin($login)
72 {
73 $userList = $this->getResponseObject();
74
75 Assertion::assertEquals(
76 1,
77 count($userList),
78 'UserList was expected to contain one user only'
79 );
80
81 Assertion::assertInstanceOf(
82 'eZ\Publish\API\Repository\Values\User\User',
83 $userList[0],
84 'UserList[0] is not a user'
85 );
86
87 Assertion::assertEquals(
88 $login,
89 $userList[0]->login,
90 "UserList was expected to contain the user with login '$login'"
91 );
92 }
93
97 public function responseContainsOnlyUsersWithTheEmail($email)
98 {
99 $userList = $this->getResponseObject();
100
101 Assertion::assertGreaterThan(
102 0,
103 count($userList),
104 'UserList was expected to contain one user only'
105 );
106
107 foreach ($userList as $user) {
108 Assertion::assertInstanceOf(
109 'eZ\Publish\API\Repository\Values\User\User',
110 $user,
111 'Non User found in the response'
112 );
113
114 Assertion::assertEquals(
115 $email,
116 $user->email,
117 "UserList was expected to contain only users with email '$email'"
118 );
119 }
120 }
121
125 public function thatICannotViewUsers()
126 {
127 $this->usePermissionsOfRole('anonymous');
128 }
129 }
EzSystems\PlatformBehatBundle\Context\getRepository
getRepository()
Definition: RepositoryContext.php:40
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\Core\Base\Exceptions\BadStateException
BadState Exception implementation.
Definition: Core/Base/Exceptions/BadStateException.php:20
eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext
Definition: Authentication.php:7
eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext\usePermissionsOfRole
usePermissionsOfRole($role)
@Given I have :role permissions
Definition: Authentication.php:17
eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext\getResponseObject
getResponseObject()
Get the response object (if it's not converted do the conversion also).
Definition: EzRest.php:230
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.