Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-08 18:13:30 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-18 18:02:26 +0300
commit76b0740bec3866538840e8b05cf240ea18f0f73b (patch)
treea1afd73c1392d615180e1f68d8926308d65837a3 /tests
parent96ba051c5c8b357a37161ee417dab04786e83ca1 (diff)
Extend integration tests to test all status codes
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/controller.php28
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php29
-rw-r--r--tests/integration/features/notifications.feature20
-rw-r--r--tests/integration/features/statuscodes.feature34
-rw-r--r--tests/integration/notifier.php65
5 files changed, 156 insertions, 20 deletions
diff --git a/tests/integration/controller.php b/tests/integration/controller.php
index ec3297f..549244a 100644
--- a/tests/integration/controller.php
+++ b/tests/integration/controller.php
@@ -80,11 +80,39 @@ class Controller extends \OCP\AppFramework\Controller {
*
* @return \OC_OCS_Result
*/
+ public function addNotification() {
+ if (!$this->config->getAppValue('notifications', 'debug')) {
+ return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
+ }
+
+ $notification = $this->manager->createNotification();
+ $notification->setApp('testing')
+ ->setDateTime(\DateTime::createFromFormat('U', 1449585176)) // 2015-12-08T14:32:56+00:00
+ ->setUser('test1')
+ ->setSubject('testing')
+ ->setLink('https://www.owncloud.org/')
+ ->setMessage('message')
+ ->setObject('object', 23);
+
+ $this->manager->notify($notification);
+
+ return new \OC_OCS_Result();
+ }
+
+ /**
+ * @NoCSRFRequired
+ *
+ * @return \OC_OCS_Result
+ */
public function reset() {
if (!$this->config->getAppValue('notifications', 'debug')) {
return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
}
+ $notification = $this->manager->createNotification();
+ $notification->setApp('testing');
+ $this->manager->markProcessed($notification);
+
$this->config->deleteAppValue('notifications', 'forceHasNotifiers');
return new \OC_OCS_Result();
}
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 6b9cfb9..66576ce 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -32,6 +32,35 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
+ * @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() {
diff --git a/tests/integration/features/notifications.feature b/tests/integration/features/notifications.feature
deleted file mode 100644
index 01f90c9..0000000
--- a/tests/integration/features/notifications.feature
+++ /dev/null
@@ -1,20 +0,0 @@
-Feature: notifications
- Background:
- Given using api version "2"
-
- Scenario: Read notifications without Notifiers
- Given user "test1" exists
- Given As an "test1"
- Given list of notifiers is not empty
- When sending "GET" to "/apps/notifications/api/v1/notifications"
- # "200 OK" - Because there is no notifier
- Then the HTTP status code should be "200"
-
- Scenario: Read notifications with Notifiers
- Given user "test1" exists
- Given As an "test1"
- Given list of notifiers is empty
- When sending "GET" to "/apps/notifications/api/v1/notifications"
- # "204 No Content" - Because there is no notifier
- Then the HTTP status code should be "204"
-
diff --git a/tests/integration/features/statuscodes.feature b/tests/integration/features/statuscodes.feature
new file mode 100644
index 0000000..b4f3034
--- /dev/null
+++ b/tests/integration/features/statuscodes.feature
@@ -0,0 +1,34 @@
+Feature: statuscodes
+ Background:
+ Given using api version "2"
+ Given user "test1" exists
+ Given As an "test1"
+
+ Scenario: Status code when reading notifications without notifiers
+ Given list of notifiers is empty
+ When sending "GET" to "/apps/notifications/api/v1/notifications?format=json"
+ # "204 No Content"
+ Then the HTTP status code should be "204"
+ # Request-Body is empty: And list of notifications has 0 entries
+
+ Scenario: Status code when reading notifications with notifiers and without notifications
+ Given list of notifiers is not empty
+ When sending "GET" to "/apps/notifications/api/v1/notifications?format=json"
+ Then the HTTP status code should be "200"
+ And list of notifications has 0 entries
+
+ Scenario: Status code when reading notifications with notifiers and notification
+ Given list of notifiers is not empty
+ Given user "test1" has notifications
+ When sending "GET" to "/apps/notifications/api/v1/notifications?format=json"
+ Then the HTTP status code should be "200"
+ And list of notifications has 1 entries
+
+ Scenario: Status code when reading notifications with notifiers and notifications
+ Given list of notifiers is not empty
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ Given user "test1" has notifications
+ When sending "GET" to "/apps/notifications/api/v1/notifications?format=json"
+ Then the HTTP status code should be "200"
+ And list of notifications has 3 entries
diff --git a/tests/integration/notifier.php b/tests/integration/notifier.php
new file mode 100644
index 0000000..96cd45a
--- /dev/null
+++ b/tests/integration/notifier.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Notifications\Tests\Integration;
+
+use OC\Notification\INotification;
+use OC\Notification\INotifier;
+use OCP\IConfig;
+
+class Notifier implements INotifier {
+
+ /** @var IConfig */
+ private $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function isDebugMode() {
+ if ($this->config->getAppValue('notifications', 'debug', '') !== '' && $this->config->getAppValue('notifications', 'forceHasNotifiers', '') !== '') {
+ return $this->config->getAppValue('notifications', 'forceHasNotifiers') === 'true';
+ }
+ return false;
+ }
+
+ /**
+ * @param INotification $notification
+ * @param string $languageCode The code of the language that should be used to prepare the notification
+ * @return INotification
+ * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ */
+ public function prepare(INotification $notification, $languageCode) {
+ if ($this->isDebugMode() && $notification->getApp() === 'testing') {
+ $notification->setParsedSubject($notification->getSubject());
+ $notification->setParsedMessage($notification->getMessage());
+ return $notification;
+ }
+
+ throw new \InvalidArgumentException();
+ }
+}