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
|
<?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));
}
}
/**
* @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();
}
}
}
|