Skip to content

Commit d5baebe

Browse files
committed
Add behat tests for User::list()
1 parent ecf0012 commit d5baebe

File tree

2 files changed

+116
-29
lines changed

2 files changed

+116
-29
lines changed

tests/Behat/Bootstrap/UserContextTrait.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,49 @@ public function iCreateAUserWithTheFollowingData(TableNode $table)
3030
}
3131

3232
/**
33-
* @When I update the user with id :id and the following data
33+
* @When I show the user with id :userId
3434
*/
35-
public function iUpdateTheUserWithIdAndTheFollowingData($id, TableNode $table)
35+
public function iShowTheUserWithId(int $userId)
3636
{
37-
$data = [];
37+
/** @var User */
38+
$api = $this->getNativeCurlClient()->getApi('user');
3839

39-
foreach ($table as $row) {
40-
$data[$row['property']] = $row['value'];
41-
}
40+
$this->registerClientResponse(
41+
$api->show($userId),
42+
$api->getLastResponse(),
43+
);
44+
}
4245

46+
/**
47+
* @When I list all users
48+
*/
49+
public function iListAllUsers()
50+
{
4351
/** @var User */
4452
$api = $this->getNativeCurlClient()->getApi('user');
4553

4654
$this->registerClientResponse(
47-
$api->update($id, $data),
55+
$api->list(),
4856
$api->getLastResponse(),
4957
);
5058
}
5159

5260
/**
53-
* @When I show the user with id :userId
61+
* @When I update the user with id :id and the following data
5462
*/
55-
public function iShowTheUserWithId(int $userId)
63+
public function iUpdateTheUserWithIdAndTheFollowingData($id, TableNode $table)
5664
{
65+
$data = [];
66+
67+
foreach ($table as $row) {
68+
$data[$row['property']] = $row['value'];
69+
}
70+
5771
/** @var User */
5872
$api = $this->getNativeCurlClient()->getApi('user');
5973

6074
$this->registerClientResponse(
61-
$api->show($userId),
75+
$api->update($id, $data),
6276
$api->getLastResponse(),
6377
);
6478
}

tests/Behat/features/user.feature

Lines changed: 92 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Interacting with the REST API for users
44
As a user
55
I want to make sure the Redmine server replies with the correct response
66

7-
87
Scenario: Creating an user
98
Given I have a "NativeCurlClient" client
109
When I create a user with the following data
@@ -45,24 +44,6 @@ Feature: Interacting with the REST API for users
4544
| twofa_scheme | [] |
4645
| status | 1 |
4746

48-
Scenario: Updating an user
49-
Given I have a "NativeCurlClient" client
50-
And I create a user with the following data
51-
| property | value |
52-
| login | username |
53-
| firstname | first |
54-
| lastname | last |
55-
| mail | mail@example.com |
56-
When I update the user with id "5" and the following data
57-
| property | value |
58-
| firstname | new_first |
59-
| lastname | new_last |
60-
| mail | new_mail@example.com |
61-
Then the response has the status code "204"
62-
And the response has an empty content type
63-
And the response has the content ""
64-
And the returned data is exactly ""
65-
6647
Scenario: Showing a user
6748
Given I have a "NativeCurlClient" client
6849
When I show the user with id "1"
@@ -113,6 +94,98 @@ Feature: Interacting with the REST API for users
11394
And the response has the content ""
11495
And the returned data is false
11596

97+
Scenario: Listing of multiple users
98+
Given I have a "NativeCurlClient" client
99+
And I create a user with the following data
100+
| property | value |
101+
| login | username |
102+
| firstname | first |
103+
| lastname | last |
104+
| mail | mail@example.net |
105+
When I list all users
106+
Then the response has the status code "200"
107+
And the response has the content type "application/json"
108+
And the returned data has only the following properties
109+
"""
110+
users
111+
total_count
112+
offset
113+
limit
114+
"""
115+
And the returned data has proterties with the following data
116+
| property | value |
117+
| total_count | 2 |
118+
| offset | 0 |
119+
| limit | 25 |
120+
And the returned data "users" property is an array
121+
And the returned data "users" property contains "2" items
122+
And the returned data "users.0" property is an array
123+
And the returned data "users.0" property has only the following properties
124+
"""
125+
id
126+
login
127+
admin
128+
firstname
129+
lastname
130+
mail
131+
created_on
132+
updated_on
133+
last_login_on
134+
passwd_changed_on
135+
twofa_scheme
136+
"""
137+
And the returned data "users.0" property contains the following data
138+
| property | value |
139+
| id | 1 |
140+
| login | admin |
141+
| admin | true |
142+
| firstname | Redmine |
143+
| lastname | Admin |
144+
| mail | admin@example.net |
145+
| twofa_scheme | null |
146+
And the returned data "users.1" property is an array
147+
And the returned data "users.1" property has only the following properties
148+
"""
149+
id
150+
login
151+
admin
152+
firstname
153+
lastname
154+
mail
155+
created_on
156+
updated_on
157+
last_login_on
158+
passwd_changed_on
159+
twofa_scheme
160+
"""
161+
And the returned data "users.1" property contains the following data
162+
| property | value |
163+
| id | 5 |
164+
| login | username |
165+
| admin | false |
166+
| firstname | first |
167+
| lastname | last |
168+
| mail | mail@example.net |
169+
| twofa_scheme | null |
170+
171+
Scenario: Updating an user
172+
Given I have a "NativeCurlClient" client
173+
And I create a user with the following data
174+
| property | value |
175+
| login | username |
176+
| firstname | first |
177+
| lastname | last |
178+
| mail | mail@example.com |
179+
When I update the user with id "5" and the following data
180+
| property | value |
181+
| firstname | new_first |
182+
| lastname | new_last |
183+
| mail | new_mail@example.com |
184+
Then the response has the status code "204"
185+
And the response has an empty content type
186+
And the response has the content ""
187+
And the returned data is exactly ""
188+
116189
Scenario: Removing an user
117190
Given I have a "NativeCurlClient" client
118191
And I create a user with the following data

0 commit comments

Comments
 (0)