1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<?php
require __DIR__ . '/../../../../../../build/integration/features/bootstrap/BasicStructure.php';
require __DIR__ . '/../../../../../../build/integration/features/bootstrap/Provisioning.php';
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext {
use BasicStructure;
use Provisioning;
/**
* @Given /^list of notifiers (is|is not) empty$/
*/
public function hasNotifiers($noNotifiers) {
if ($noNotifiers === 'is') {
$response = $this->setTestingValue('DELETE', 'apps/notifications/testing/notifiers', null);
PHPUnit_Framework_Assert::assertEquals(200, $response->getStatusCode());
PHPUnit_Framework_Assert::assertEquals(200, (int) $this->getOCSResponse($response));
} else {
$response = $this->setTestingValue('POST', 'apps/notifications/testing/notifiers', null);
PHPUnit_Framework_Assert::assertEquals(200, $response->getStatusCode());
PHPUnit_Framework_Assert::assertEquals(200, (int) $this->getOCSResponse($response));
}
}
/**
* @Given /^user "([^"]*)" has notifications$/
*/
public function hasNotifications($user) {
if ($user === 'test1') {
$response = $this->setTestingValue('POST', 'apps/notifications/testing/notifications', null);
PHPUnit_Framework_Assert::assertEquals(200, $response->getStatusCode());
PHPUnit_Framework_Assert::assertEquals(200, (int) $this->getOCSResponse($response));
}
}
/**
* @Then /^list of notifications has (\d+) entries$/
*/
public function checkNumNotifications($numNotifications) {
$notifications = $this->getArrayOfNotificationsResponded($this->response);
PHPUnit_Framework_Assert::assertCount((int) $numNotifications, $notifications);
}
/**
* Parses the xml answer to get the array of users returned.
* @param ResponseInterface $resp
* @return array
*/
public function getArrayOfNotificationsResponded($resp) {
$jsonResponse = json_decode($resp->getBody()->getContents(), 1);
return $jsonResponse['ocs']['data'];
}
/**
* @BeforeSuite
*/
public static function addFilesToSkeleton() {
// The path to the skeleton files does not match, and we don't need them
}
/**
* @AfterSuite
*/
public static function removeFilesFromSkeleton() {
// The path to the skeleton files does not match, and we don't need them
}
/**
* @AfterScenario
*/
public function removeDebugConfigs() {
$response = $this->setTestingValue('DELETE', 'apps/notifications/testing', null);
PHPUnit_Framework_Assert::assertEquals(200, $response->getStatusCode());
PHPUnit_Framework_Assert::assertEquals(200, (int) $this->getOCSResponse($response));
}
protected function setTestingValue($verb, $url, $body) {
$fullUrl = $this->baseUrl . "v2.php/" . $url;
$client = new Client();
$options = [
'auth' => $this->adminUser,
];
if ($body instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $body->getRowsHash();
$options['body'] = $fd;
}
try {
return $client->send($client->createRequest($verb, $fullUrl, $options));
} catch (\GuzzleHttp\Exception\ClientException $ex) {
return $ex->getResponse();
}
}
}
|