|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
|
8
|
|
|
use eZ\Publish\Core\Base\Exceptions\BadStateException; |
|
9
|
|
|
use PHPUnit_Framework_Assert as Assertion; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @method \eZ\Publish\API\Repository\Repository getRepository() |
|
13
|
|
|
*/ |
|
14
|
|
|
trait User |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Given /^there is a user with the login "([^"]*)"$/ |
|
18
|
|
|
*/ |
|
19
|
|
|
public function thereIsAUserWithTheLogin($login) |
|
20
|
|
|
{ |
|
21
|
|
|
Assertion::assertInstanceOf( |
|
22
|
|
|
'eZ\Publish\API\Repository\Values\User\User', |
|
23
|
|
|
$this->getRepository()->getUserService()->loadUserByLogin($login) |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @Given /^there isn't a user with the login "([^"]*)"$/ |
|
29
|
|
|
*/ |
|
30
|
|
|
public function thereIsNotAUserWithTheLogin($login) |
|
31
|
|
|
{ |
|
32
|
|
|
try { |
|
33
|
|
|
$this->getRepository()->getUserService()->loadUserByLogin($login); |
|
34
|
|
|
} catch (NotFoundException $e) { |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
throw new BadStateException('login', "A user with the login $login exists"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Verifies that there is at least one user with a given email address. |
|
42
|
|
|
* |
|
43
|
|
|
* @Given /^there is a at least one user with the email "([^"]*)"$/ |
|
44
|
|
|
* @Given /^there is a user with the email "([^"]*)"$/ |
|
45
|
|
|
*/ |
|
46
|
|
|
public function thereIsAUserWithTheEmail($email) |
|
47
|
|
|
{ |
|
48
|
|
|
$users = $this->getRepository()->getUserService()->loadUsersByEmail($email); |
|
49
|
|
|
|
|
50
|
|
|
Assertion::assertGreaterThan(0, count($users), "No user was found with the email '$email'"); |
|
51
|
|
|
Assertion::assertInstanceOf('eZ\Publish\API\Repository\Values\User\User', $users[0]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Verifies that there is at least one user with a given email address. |
|
56
|
|
|
* |
|
57
|
|
|
* @Given /^there isn't a user with the email "([^"]*)"$/ |
|
58
|
|
|
* @Given /^there are no users with the email "([^"]*)"$/ |
|
59
|
|
|
*/ |
|
60
|
|
|
public function thereAreNoUsersWithTheEmail($email) |
|
61
|
|
|
{ |
|
62
|
|
|
$users = $this->getRepository()->getUserService()->loadUsersByEmail($email); |
|
63
|
|
|
Assertion::assertEquals(0, count($users), "Users with the email '$email' exist"); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @Given /^response contains only the user with the login "([^"]*)"$/ |
|
68
|
|
|
*/ |
|
69
|
|
|
public function responseContainsOnlyTheUserWithTheLogin($login) |
|
70
|
|
|
{ |
|
71
|
|
|
$userList = $this->getResponseObject(); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
Assertion::assertEquals( |
|
74
|
|
|
1, |
|
75
|
|
|
count($userList), |
|
76
|
|
|
'UserList was expected to contain one user only' |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
Assertion::assertInstanceOf( |
|
80
|
|
|
'eZ\Publish\API\Repository\Values\User\User', |
|
81
|
|
|
$userList[0], |
|
82
|
|
|
'UserList[0] is not a user' |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
Assertion::assertEquals( |
|
86
|
|
|
$login, |
|
87
|
|
|
$userList[0]->login, |
|
88
|
|
|
"UserList was expected to contain the user with login '$login'" |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @Given /^response contains only the user with the email "([^"]*)"$/ |
|
94
|
|
|
*/ |
|
95
|
|
|
public function responseContainsOnlyUsersWithTheEmail($email) |
|
96
|
|
|
{ |
|
97
|
|
|
$userList = $this->getResponseObject(); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
Assertion::assertGreaterThan( |
|
100
|
|
|
0, |
|
101
|
|
|
count($userList), |
|
102
|
|
|
'UserList was expected to contain one user only' |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
foreach ($userList as $user) { |
|
106
|
|
|
Assertion::assertInstanceOf( |
|
107
|
|
|
'eZ\Publish\API\Repository\Values\User\User', |
|
108
|
|
|
$user, |
|
109
|
|
|
'Non User found in the response' |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
Assertion::assertEquals( |
|
113
|
|
|
$email, |
|
114
|
|
|
$user->email, |
|
115
|
|
|
"UserList was expected to contain only users with email '$email'" |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @Given /^that I can't view users$/ |
|
122
|
|
|
*/ |
|
123
|
|
|
public function thatICannotViewUsers() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->usePermissionsOfRole('anonymous'); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.