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 16:42:05 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-18 18:02:26 +0300
commit96ba051c5c8b357a37161ee417dab04786e83ca1 (patch)
treeb40886dc7644844748601af1da3df542f9a53f19 /tests
parent11917d10387b7ae9e6e31d412aca5ff0d1981725 (diff)
Add tests for empty notifications list 200/204
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/controller.php91
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php43
-rw-r--r--tests/integration/features/notifications.feature9
-rw-r--r--tests/integration/run.sh8
-rw-r--r--tests/unit/controller/EndpointControllerTest.php4
5 files changed, 154 insertions, 1 deletions
diff --git a/tests/integration/controller.php b/tests/integration/controller.php
new file mode 100644
index 0000000..ec3297f
--- /dev/null
+++ b/tests/integration/controller.php
@@ -0,0 +1,91 @@
+<?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\IManager;
+use OCP\AppFramework\Http;
+use OCP\IConfig;
+use OCP\IRequest;
+
+class Controller extends \OCP\AppFramework\Controller {
+
+ /** @var IConfig */
+ private $config;
+
+ /** @var IManager */
+ private $manager;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param IConfig $config
+ * @param IManager $manager
+ */
+ public function __construct($appName, IRequest $request, IConfig $config, IManager $manager) {
+ parent::__construct($appName, $request);
+
+ $this->config = $config;
+ $this->manager = $manager;
+ }
+
+ /**
+ * @NoCSRFRequired
+ *
+ * @return \OC_OCS_Result
+ */
+ public function fillNotifiers() {
+ if (!$this->config->getAppValue('notifications', 'debug')) {
+ return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
+ }
+
+ $this->config->setAppValue('notifications', 'forceHasNotifiers', 'true');
+ return new \OC_OCS_Result();
+ }
+
+ /**
+ * @NoCSRFRequired
+ *
+ * @return \OC_OCS_Result
+ */
+ public function clearNotifiers() {
+ if (!$this->config->getAppValue('notifications', 'debug')) {
+ return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
+ }
+
+ $this->config->setAppValue('notifications', 'forceHasNotifiers', 'false');
+ 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);
+ }
+
+ $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 321a4de..6b9cfb9 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -12,10 +12,26 @@ 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() {
@@ -28,4 +44,31 @@ class FeatureContext implements Context, SnippetAcceptingContext {
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();
+ }
+ }
}
diff --git a/tests/integration/features/notifications.feature b/tests/integration/features/notifications.feature
index 08b669a..01f90c9 100644
--- a/tests/integration/features/notifications.feature
+++ b/tests/integration/features/notifications.feature
@@ -5,6 +5,15 @@ Feature: notifications
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/run.sh b/tests/integration/run.sh
index 41c7f7a..c7f9d5c 100644
--- a/tests/integration/run.sh
+++ b/tests/integration/run.sh
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
+APP_NAME=notifications
+
APP_INTEGRATION_DIR=$PWD
-ROOT_DIR=../../../..
+ROOT_DIR=${APP_INTEGRATION_DIR}/../../../..
cd ${ROOT_DIR}/build/integration
composer install
@@ -11,10 +13,14 @@ php -S localhost:8080 -t ${ROOT_DIR} &
PHPPID=$!
echo $PHPPID
+${ROOT_DIR}/occ config:app:set ${APP_NAME} debug --value="on"
+
export TEST_SERVER_URL="http://localhost:8080/ocs/"
${ROOT_DIR}/build/integration/vendor/bin/behat -f junit -f pretty
RESULT=$?
kill $PHPPID
+${ROOT_DIR}/occ config:app:delete ${APP_NAME} debug
+
exit $RESULT
diff --git a/tests/unit/controller/EndpointControllerTest.php b/tests/unit/controller/EndpointControllerTest.php
index e09a733..e875cff 100644
--- a/tests/unit/controller/EndpointControllerTest.php
+++ b/tests/unit/controller/EndpointControllerTest.php
@@ -69,6 +69,10 @@ class EndpointControllerTest extends TestCase {
$this->config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
+ $this->config->expects($this->any())
+ ->method('getAppValue')
+ ->with('notifications', 'forceHasNotifiers', $this->anything())
+ ->willReturnArgument(2);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
$this->session = $this->getMockBuilder('OCP\IUserSession')