Completed
Push — stable8.2 ( 3eaa45...4ae337 )
by Thomas
13:54
created

Provisioning::getArrayOfGroupsResponded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 5
cc 1
eloc 4
nop 1
rs 9.4285
1
<?php
2
3
use GuzzleHttp\Client;
4
use GuzzleHttp\Message\ResponseInterface;
5
6
require __DIR__ . '/../../vendor/autoload.php';
7
8
trait Provisioning {
9
	use BasicStructure;
10
11
	/** @var array */
12
	private $createdUsers = [];
13
14
	/** @var array */
15
	private $createdRemoteUsers = [];
16
17
	/** @var array */
18
	private $createdRemoteGroups = [];
19
	
20
	/** @var array */
21
	private $createdGroups = [];
22
23
	/**
24
	 * @Given /^user "([^"]*)" exists$/
25
	 * @param string $user
26
	 */
27 View Code Duplication
	public function assureUserExists($user) {
28
		try {
29
			$this->userExists($user);
30
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
31
			$previous_user = $this->currentUser;
32
			$this->currentUser = "admin";
33
			$this->creatingTheUser($user);
34
			$this->currentUser = $previous_user;
35
		}
36
		$this->userExists($user);
37
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
38
	}
39
40
	/**
41
	 * @Given /^user "([^"]*)" does not exist$/
42
	 * @param string $user
43
	 */
44 View Code Duplication
	public function userDoesNotExist($user) {
45
		try {
46
			$this->userExists($user);
47
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
48
			$this->response = $ex->getResponse();
49
			PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
50
			return;
51
		}
52
		$previous_user = $this->currentUser;
53
		$this->currentUser = "admin";
54
		$this->deletingTheUser($user);
55
		$this->currentUser = $previous_user;
56
		try {
57
			$this->userExists($user);
58
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
59
			$this->response = $ex->getResponse();
60
			PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
61
		}
62
	}
63
64
	public function creatingTheUser($user) {
65
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
66
		$client = new Client();
67
		$options = [];
68
		if ($this->currentUser === 'admin') {
69
			$options['auth'] = $this->adminUser;
0 ignored issues
show
Bug introduced by
The property adminUser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
		}
71
72
		$options['body'] = [
73
							'userid' => $user,
74
							'password' => '123456'
75
							];
76
77
		$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
78 View Code Duplication
		if ($this->currentServer === 'LOCAL'){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
			$this->createdUsers[$user] = $user;
80
		} elseif ($this->currentServer === 'REMOTE') {
81
			$this->createdRemoteUsers[$user] = $user;
82
		}
83
84
		//Quick hack to login once with the current user
85
		$options2 = [
86
			'auth' => [$user, '123456'],
87
		];
88
		$url = $fullUrl.'/'.$user;
89
		$client->send($client->createRequest('GET', $url, $options2));
90
	}
91
92
	public function createUser($user) {
93
		$previous_user = $this->currentUser;
94
		$this->currentUser = "admin";
95
		$this->creatingTheUser($user);
96
		$this->userExists($user);
97
		$this->currentUser = $previous_user;
98
	}
99
100
	public function deleteUser($user) {
101
		$previous_user = $this->currentUser;
102
		$this->currentUser = "admin";
103
		$this->deletingTheUser($user);
104
		$this->userDoesNotExist($user);
105
		$this->currentUser = $previous_user;
106
	}
107
108
	public function createGroup($group) {
109
		$previous_user = $this->currentUser;
110
		$this->currentUser = "admin";
111
		$this->creatingTheGroup($group);
112
		$this->groupExists($group);
113
		$this->currentUser = $previous_user;
114
	}
115
116
	public function deleteGroup($group) {
117
		$previous_user = $this->currentUser;
118
		$this->currentUser = "admin";
119
		$this->deletingTheGroup($group);
120
		$this->groupDoesNotExist($group);
121
		$this->currentUser = $previous_user;
122
	}
123
124 View Code Duplication
	public function userExists($user){
125
		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
126
		$client = new Client();
127
		$options = [];
128
		$options['auth'] = $this->adminUser;
129
130
		$this->response = $client->get($fullUrl, $options);
131
	}
132
133
	/**
134
	 * @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
135
	 * @param string $user
136
	 * @param string $group
137
	 */
138 View Code Duplication
	public function checkThatUserBelongsToGroup($user, $group) {
139
		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
140
		$client = new Client();
141
		$options = [];
142
		if ($this->currentUser === 'admin') {
143
			$options['auth'] = $this->adminUser;
144
		}
145
146
		$this->response = $client->get($fullUrl, $options);
147
		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
148
		sort($respondedArray);
149
		PHPUnit_Framework_Assert::assertContains($group, $respondedArray);
150
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
151
	}
152
153
	public function userBelongsToGroup($user, $group) {
154
		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
155
		$client = new Client();
156
		$options = [];
157
		if ($this->currentUser === 'admin') {
158
			$options['auth'] = $this->adminUser;
159
		}
160
161
		$this->response = $client->get($fullUrl, $options);
162
		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
163
164
		if (array_key_exists($group, $respondedArray)) {
165
			return True;
166
		} else{
167
			return False;
168
		}
169
	}
170
171
	/**
172
	 * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
173
	 * @param string $user
174
	 * @param string $group
175
	 */
176
	public function assureUserBelongsToGroup($user, $group){
177
		$previous_user = $this->currentUser;
178
		$this->currentUser = "admin";
179
180
		if (!$this->userBelongsToGroup($user, $group)){
181
			$this->addingUserToGroup($user, $group);
182
		}
183
184
		$this->checkThatUserBelongsToGroup($user, $group);
185
		$this->currentUser = $previous_user;
186
	}
187
188
	/**
189
	 * @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
190
	 * @param string $user
191
	 * @param string $group
192
	 */
193
	public function userDoesNotBelongToGroup($user, $group) {
194
		$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
195
		$client = new Client();
196
		$options = [];
197
		if ($this->currentUser === 'admin') {
198
			$options['auth'] = $this->adminUser;
199
		}
200
201
		$this->response = $client->get($fullUrl, $options);
202
		$groups = array($group);
203
		$respondedArray = $this->getArrayOfGroupsResponded($this->response);
204
		PHPUnit_Framework_Assert::assertNotEquals($groups, $respondedArray, "", 0.0, 10, true);
205
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
206
	}
207
208
	/**
209
	 * @When /^creating the group "([^"]*)"$/
210
	 * @param string $group
211
	 */
212
	public function creatingTheGroup($group) {
213
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
214
		$client = new Client();
215
		$options = [];
216
		if ($this->currentUser === 'admin') {
217
			$options['auth'] = $this->adminUser;
218
		}
219
220
		$options['body'] = [
221
							'groupid' => $group,
222
							];
223
224
		$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
225 View Code Duplication
		if ($this->currentServer === 'LOCAL'){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
			$this->createdGroups[$group] = $group;
227
		} elseif ($this->currentServer === 'REMOTE') {
228
			$this->createdRemoteGroups[$group] = $group;
229
		}
230
	}
231
232
	/**
233
	 * @When /^assure user "([^"]*)" is disabled$/
234
	 */
235 View Code Duplication
	public function assureUserIsDisabled($user) {
236
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/disable";
237
		$client = new Client();
238
		$options = [];
239
		if ($this->currentUser === 'admin') {
240
			$options['auth'] = $this->adminUser;
241
		}
242
243
		$this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
244
	}
245
246
	/**
247
	 * @When /^Deleting the user "([^"]*)"$/
248
	 * @param string $user
249
	 */
250 View Code Duplication
	public function deletingTheUser($user) {
251
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
252
		$client = new Client();
253
		$options = [];
254
		if ($this->currentUser === 'admin') {
255
			$options['auth'] = $this->adminUser;
256
		}
257
258
		$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
259
	}
260
261
	/**
262
	 * @When /^Deleting the group "([^"]*)"$/
263
	 * @param string $group
264
	 */
265 View Code Duplication
	public function deletingTheGroup($group) {
266
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
267
		$client = new Client();
268
		$options = [];
269
		if ($this->currentUser === 'admin') {
270
			$options['auth'] = $this->adminUser;
271
		}
272
273
		$this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
274
	}
275
276
	/**
277
	 * @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
278
	 * @param string $user
279
	 * @param string $group
280
	 */
281
	public function addUserToGroup($user, $group) {
282
		$this->userExists($user);
283
		$this->groupExists($group);
284
		$this->addingUserToGroup($user, $group);
285
286
	}
287
288
	/**
289
	 * @When /^User "([^"]*)" is added to the group "([^"]*)"$/
290
	 * @param string $user
291
	 * @param string $group
292
	 */
293 View Code Duplication
	public function addingUserToGroup($user, $group) {
294
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
295
		$client = new Client();
296
		$options = [];
297
		if ($this->currentUser === 'admin') {
298
			$options['auth'] = $this->adminUser;
299
		}
300
301
		$options['body'] = [
302
							'groupid' => $group,
303
							];
304
305
		$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
306
	}
307
308
309 View Code Duplication
	public function groupExists($group) {
310
		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
311
		$client = new Client();
312
		$options = [];
313
		$options['auth'] = $this->adminUser;
314
315
		$this->response = $client->get($fullUrl, $options);
316
	}
317
318
	/**
319
	 * @Given /^group "([^"]*)" exists$/
320
	 * @param string $group
321
	 */
322 View Code Duplication
	public function assureGroupExists($group) {
323
		try {
324
			$this->groupExists($group);
325
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
326
			$previous_user = $this->currentUser;
327
			$this->currentUser = "admin";
328
			$this->creatingTheGroup($group);
329
			$this->currentUser = $previous_user;
330
		}
331
		$this->groupExists($group);
332
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
333
	}
334
335
	/**
336
	 * @Given /^group "([^"]*)" does not exist$/
337
	 * @param string $group
338
	 */
339 View Code Duplication
	public function groupDoesNotExist($group) {
340
		try {
341
			$this->groupExists($group);
342
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
343
			$this->response = $ex->getResponse();
344
			PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
345
			return;
346
		}
347
		$previous_user = $this->currentUser;
348
		$this->currentUser = "admin";
349
		$this->deletingTheGroup($group);
350
		$this->currentUser = $previous_user;
351
		try {
352
			$this->groupExists($group);
353
		} catch (\GuzzleHttp\Exception\ClientException $ex) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
354
			$this->response = $ex->getResponse();
355
			PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
356
		}
357
	}
358
359
	/**
360
	 * @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
361
	 * @param string $user
362
	 * @param string $group
363
	 */
364 View Code Duplication
	public function userIsSubadminOfGroup($user, $group) {
365
		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
366
		$client = new Client();
367
		$options = [];
368
		if ($this->currentUser === 'admin') {
369
			$options['auth'] = $this->adminUser;
370
		}
371
372
		$this->response = $client->get($fullUrl, $options);
373
		$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
374
		sort($respondedArray);
375
		PHPUnit_Framework_Assert::assertContains($user, $respondedArray);
376
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
377
	}
378
379
	/**
380
	 * @Given /^Assure user "([^"]*)" is subadmin of group "([^"]*)"$/
381
	 * @param string $user
382
	 * @param string $group
383
	 */
384 View Code Duplication
	public function assureUserIsSubadminOfGroup($user, $group) {
385
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/subadmins";
386
		$client = new Client();
387
		$options = [];
388
		if ($this->currentUser === 'admin') {
389
			$options['auth'] = $this->adminUser;
390
		}
391
		$options['body'] = [
392
							'groupid' => $group
393
							];
394
		$this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
395
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
396
	}
397
398
	/**
399
	 * @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
400
	 * @param string $user
401
	 * @param string $group
402
	 */
403 View Code Duplication
	public function userIsNotSubadminOfGroup($user, $group) {
404
		$fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
405
		$client = new Client();
406
		$options = [];
407
		if ($this->currentUser === 'admin') {
408
			$options['auth'] = $this->adminUser;
409
		}
410
411
		$this->response = $client->get($fullUrl, $options);
412
		$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
413
		sort($respondedArray);
414
		PHPUnit_Framework_Assert::assertNotContains($user, $respondedArray);
415
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
416
	}
417
418
	/**
419
	 * @Then /^users returned are$/
420
	 * @param \Behat\Gherkin\Node\TableNode|null $usersList
421
	 */
422 View Code Duplication
	public function theUsersShouldBe($usersList) {
423
		if ($usersList instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
424
			$users = $usersList->getRows();
425
			$usersSimplified = $this->simplifyArray($users);
426
			$respondedArray = $this->getArrayOfUsersResponded($this->response);
427
			PHPUnit_Framework_Assert::assertEquals($usersSimplified, $respondedArray, "", 0.0, 10, true);
428
		}
429
430
	}
431
432
	/**
433
	 * @Then /^groups returned are$/
434
	 * @param \Behat\Gherkin\Node\TableNode|null $groupsList
435
	 */
436 View Code Duplication
	public function theGroupsShouldBe($groupsList) {
437
		if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
438
			$groups = $groupsList->getRows();
439
			$groupsSimplified = $this->simplifyArray($groups);
440
			$respondedArray = $this->getArrayOfGroupsResponded($this->response);
441
			PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
442
		}
443
444
	}
445
446
	/**
447
	 * @Then /^subadmin groups returned are$/
448
	 * @param \Behat\Gherkin\Node\TableNode|null $groupsList
449
	 */
450 View Code Duplication
	public function theSubadminGroupsShouldBe($groupsList) {
451
		if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
452
			$groups = $groupsList->getRows();
453
			$groupsSimplified = $this->simplifyArray($groups);
454
			$respondedArray = $this->getArrayOfSubadminsResponded($this->response);
455
			PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
456
		}
457
458
	}
459
460
	/**
461
	 * @Then /^apps returned are$/
462
	 * @param \Behat\Gherkin\Node\TableNode|null $appList
463
	 */
464 View Code Duplication
	public function theAppsShouldBe($appList) {
465
		if ($appList instanceof \Behat\Gherkin\Node\TableNode) {
0 ignored issues
show
Bug introduced by
The class Behat\Gherkin\Node\TableNode does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
466
			$apps = $appList->getRows();
467
			$appsSimplified = $this->simplifyArray($apps);
468
			$respondedArray = $this->getArrayOfAppsResponded($this->response);
469
			PHPUnit_Framework_Assert::assertEquals($appsSimplified, $respondedArray, "", 0.0, 10, true);
470
		}
471
472
	}
473
474
	/**
475
	 * @Then /^subadmin users returned are$/
476
	 * @param \Behat\Gherkin\Node\TableNode|null $groupsList
477
	 */
478
	public function theSubadminUsersShouldBe($groupsList) {
479
		$this->theSubadminGroupsShouldBe($groupsList);
480
	}
481
482
	/**
483
	 * Parses the xml answer to get the array of users returned.
484
	 * @param ResponseInterface $resp
485
	 * @return array
486
	 */
487
	public function getArrayOfUsersResponded($resp) {
488
		$listCheckedElements = $resp->xml()->data[0]->users[0]->element;
489
		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
490
		return $extractedElementsArray;
491
	}
492
493
	/**
494
	 * Parses the xml answer to get the array of groups returned.
495
	 * @param ResponseInterface $resp
496
	 * @return array
497
	 */
498
	public function getArrayOfGroupsResponded($resp) {
499
		$listCheckedElements = $resp->xml()->data[0]->groups[0]->element;
500
		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
501
		return $extractedElementsArray;
502
	}
503
504
	/**
505
	 * Parses the xml answer to get the array of apps returned.
506
	 * @param ResponseInterface $resp
507
	 * @return array
508
	 */
509
	public function getArrayOfAppsResponded($resp) {
510
		$listCheckedElements = $resp->xml()->data[0]->apps[0]->element;
511
		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
512
		return $extractedElementsArray;
513
	}
514
515
	/**
516
	 * Parses the xml answer to get the array of subadmins returned.
517
	 * @param ResponseInterface $resp
518
	 * @return array
519
	 */
520
	public function getArrayOfSubadminsResponded($resp) {
521
		$listCheckedElements = $resp->xml()->data[0]->element;
522
		$extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
523
		return $extractedElementsArray;
524
	}
525
526
527
	/**
528
	 * @Given /^app "([^"]*)" is disabled$/
529
	 * @param string $app
530
	 */
531 View Code Duplication
	public function appIsDisabled($app) {
532
		$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled";
533
		$client = new Client();
534
		$options = [];
535
		if ($this->currentUser === 'admin') {
536
			$options['auth'] = $this->adminUser;
537
		}
538
539
		$this->response = $client->get($fullUrl, $options);
540
		$respondedArray = $this->getArrayOfAppsResponded($this->response);
541
		PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
542
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
543
	}
544
545
	/**
546
	 * @Given /^app "([^"]*)" is enabled$/
547
	 * @param string $app
548
	 */
549 View Code Duplication
	public function appIsEnabled($app) {
550
		$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=enabled";
551
		$client = new Client();
552
		$options = [];
553
		if ($this->currentUser === 'admin') {
554
			$options['auth'] = $this->adminUser;
555
		}
556
557
		$this->response = $client->get($fullUrl, $options);
558
		$respondedArray = $this->getArrayOfAppsResponded($this->response);
559
		PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
560
		PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
561
	}
562
563
	/**
564
	 * @Then /^user "([^"]*)" is disabled$/
565
	 * @param string $user
566
	 */
567 View Code Duplication
	public function userIsDisabled($user) {
568
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
569
		$client = new Client();
570
		$options = [];
571
		if ($this->currentUser === 'admin') {
572
			$options['auth'] = $this->adminUser;
573
		}
574
575
		$this->response = $client->get($fullUrl, $options);
576
		PHPUnit_Framework_Assert::assertEquals("false", $this->response->xml()->data[0]->enabled);
577
	}
578
579
	/**
580
	 * @Then /^user "([^"]*)" is enabled$/
581
	 * @param string $user
582
	 */
583 View Code Duplication
	public function userIsEnabled($user) {
584
		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
585
		$client = new Client();
586
		$options = [];
587
		if ($this->currentUser === 'admin') {
588
			$options['auth'] = $this->adminUser;
589
		}
590
591
		$this->response = $client->get($fullUrl, $options);
592
		PHPUnit_Framework_Assert::assertEquals("true", $this->response->xml()->data[0]->enabled);
593
	}
594
595
	/**
596
	 * @Given user :user has a quota of :quota
597
	 * @param string $user
598
	 * @param string $quota
599
	 */
600
	public function userHasAQuotaOf($user, $quota)
601
	{
602
		$body = new \Behat\Gherkin\Node\TableNode([
603
			0 => ['key', 'quota'],
604
			1 => ['value', $quota],
605
		]);
606
607
		// method used from BasicStructure trait
608
		$this->sendingToWith("PUT", "/cloud/users/" . $user, $body);
609
	}
610
611
	/**
612
	 * @Given user :user has unlimited quota
613
	 * @param string $user
614
	 */
615
	public function userHasUnlimitedQuota($user)
616
	{
617
		$this->userHasAQuotaOf($user, 'none');
618
	}
619
620
	/**
621
	 * @BeforeScenario
622
	 * @AfterScenario
623
	 */
624
	public function cleanupUsers()
625
	{
626
		$previousServer = $this->currentServer;
627
		$this->usingServer('LOCAL');
628
		foreach($this->createdUsers as $user) {	
629
			$this->deleteUser($user);
630
		}
631
		$this->usingServer('REMOTE');
632
		foreach($this->createdRemoteUsers as $remoteUser) {
633
			$this->deleteUser($remoteUser);
634
		}
635
		$this->usingServer($previousServer);
636
	}
637
638
	/**
639
	 * @BeforeScenario
640
	 * @AfterScenario
641
	 */
642
	public function cleanupGroups()
643
	{
644
		$previousServer = $this->currentServer;
645
		$this->usingServer('LOCAL');
646
		foreach($this->createdGroups as $group) {
647
			$this->deleteGroup($group);
648
		}
649
		$this->usingServer('REMOTE');
650
		foreach($this->createdRemoteGroups as $remoteGroup) {
651
			$this->deleteUser($remoteGroup);
652
		}
653
		$this->usingServer($previousServer);
654
	}
655
656
}
657