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
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-03-30 18:36:16 +0300
committerJoas Schilling <nickvergessen@gmx.de>2016-03-30 18:36:16 +0300
commite285bf55d712afbeffae02ea2fe31b0e7822b3af (patch)
treec7765ac69bbeb5e9d449f1e5d729fc6a070cc2f4
parent46da88f6a447b8348656467e40098e51b7e04052 (diff)
parent2002789f6de1e4dcb03257b31dcf4c5b715648f2 (diff)
Merge pull request #78 from owncloud/backport-77v9.0.52RC1
Make integration tests independent from core
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml5
-rw-r--r--tests/integration/composer.json8
-rw-r--r--tests/integration/config/behat.yml7
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php160
-rw-r--r--tests/integration/features/delete-notifications.feature3
-rw-r--r--tests/integration/features/notifications-content.feature3
-rw-r--r--tests/integration/features/statuscodes.feature3
-rw-r--r--tests/integration/run.sh9
9 files changed, 160 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index f63c7b8..10e3947 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,4 +55,6 @@ nbproject
/tests/unit/clover.xml
/tests/unit/js/node_modules
+/tests/integration/composer.lock
/tests/integration/output
+/tests/integration/vendor
diff --git a/.travis.yml b/.travis.yml
index dbda281..78ab754 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,13 +31,12 @@ before_install:
- ./occ app:list
# Setup behat for integration tests
- - cd build/integration/
+ - cd apps/$APP_NAME/
+ - cd tests/integration/
- sh -c "if [ '$INTEGRATION' = '1' ]; then composer install; fi"
- cd ../../
script:
- - cd apps/$APP_NAME/
-
# Test the app
- sh -c "if [ '$CODECHECK' = '1' ]; then find . -name \*.php -exec php -l \"{}\" \;; fi"
- cd ../../
diff --git a/tests/integration/composer.json b/tests/integration/composer.json
new file mode 100644
index 0000000..dc8e8d7
--- /dev/null
+++ b/tests/integration/composer.json
@@ -0,0 +1,8 @@
+{
+ "require-dev": {
+ "phpunit/phpunit": "~4.8",
+ "behat/behat": "^3.0",
+ "guzzlehttp/guzzle": "~5.0",
+ "jarnaiz/behat-junit-formatter": "^1.3"
+ }
+}
diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml
index c9d6754..0fcead7 100644
--- a/tests/integration/config/behat.yml
+++ b/tests/integration/config/behat.yml
@@ -6,12 +6,7 @@ default:
paths:
- %paths.base%/../features
contexts:
- - FeatureContext:
- baseUrl: http://localhost:8080/ocs/
- admin:
- - admin
- - admin
- regular_user_password: 123456
+ - FeatureContext
extensions:
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 37d944e..8594d30 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -19,8 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-require __DIR__ . '/../../../../../../build/integration/features/bootstrap/BasicStructure.php';
-require __DIR__ . '/../../../../../../build/integration/features/bootstrap/Provisioning.php';
+require __DIR__ . '/../../vendor/autoload.php';
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
@@ -38,10 +37,22 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var int */
protected $deletedNotification;
- protected $adminUser;
+ /** @var string */
+ protected $currentUser;
- use BasicStructure;
- use Provisioning;
+ /** @var ResponseInterface */
+ private $response = null;
+
+ /** @var \GuzzleHttp\Cookie\CookieJar */
+ private $cookieJar;
+
+ /**
+ * FeatureContext constructor.
+ */
+ public function __construct() {
+ $this->cookieJar = new \GuzzleHttp\Cookie\CookieJar();
+ $this->baseUrl = getenv('TEST_SERVER_URL');
+ }
/**
* @Given /^user "([^"]*)" has notifications$/
@@ -171,20 +182,6 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
- * @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
- }
-
- /**
* @BeforeScenario
* @AfterScenario
*/
@@ -201,10 +198,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @return \GuzzleHttp\Message\FutureResponse|ResponseInterface|null
*/
protected function setTestingValue($verb, $url, $body) {
- $fullUrl = $this->baseUrl . "v2.php/" . $url;
+ $fullUrl = $this->baseUrl . 'ocs/v2.php/' . $url;
$client = new Client();
$options = [
- 'auth' => $this->adminUser,
+ 'auth' => ['admin', 'admin'],
];
if ($body instanceof \Behat\Gherkin\Node\TableNode) {
$fd = $body->getRowsHash();
@@ -217,4 +214,125 @@ class FeatureContext implements Context, SnippetAcceptingContext {
return $ex->getResponse();
}
}
+
+ /*
+ * User management
+ */
+
+ /**
+ * @Given /^As user "([^"]*)"$/
+ * @param string $user
+ */
+ public function setCurrentUser($user) {
+ $this->currentUser = $user;
+ }
+
+ /**
+ * @Given /^user "([^"]*)" exists$/
+ * @param string $user
+ */
+ public function assureUserExists($user) {
+ try {
+ $this->userExists($user);
+ } catch (\GuzzleHttp\Exception\ClientException $ex) {
+ $this->createUser($user);
+ }
+ $this->userExists($user);
+ PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
+
+ }
+
+ private function userExists($user) {
+ $client = new Client();
+ $options = ['auth' => ['admin', 'admin']];
+ $this->response = $client->get($this->baseUrl . 'ocs/v2.php/cloud/users/' . $user, $options);
+ }
+
+ private function createUser($user) {
+ $previous_user = $this->currentUser;
+ $this->currentUser = "admin";
+
+ $userProvisioningUrl = $this->baseUrl . 'ocs/v2.php/cloud/users';
+ $client = new Client();
+ $options = [
+ 'auth' => ['admin', 'admin'],
+ 'body' => [
+ 'userid' => $user,
+ 'password' => '123456'
+ ],
+ ];
+ $this->response = $client->send($client->createRequest('POST', $userProvisioningUrl, $options));
+
+ //Quick hack to login once with the current user
+ $options2 = ['auth' => [$user, '123456']];
+ $client->send($client->createRequest('GET', $userProvisioningUrl . '/' . $user, $options2));
+
+ $this->currentUser = $previous_user;
+ }
+
+ /*
+ * Requests
+ */
+
+ /**
+ * @When /^sending "([^"]*)" to "([^"]*)"$/
+ * @param string $verb
+ * @param string $url
+ */
+ public function sendingTo($verb, $url) {
+ $this->sendingToWith($verb, $url, null);
+ }
+
+ /**
+ * @When /^sending "([^"]*)" to "([^"]*)" with$/
+ * @param string $verb
+ * @param string $url
+ * @param \Behat\Gherkin\Node\TableNode $body
+ */
+ public function sendingToWith($verb, $url, $body) {
+ $fullUrl = $this->baseUrl . 'ocs/v2.php' . $url;
+ $client = new Client();
+ $options = [];
+ if ($this->currentUser === 'admin') {
+ $options['auth'] = ['admin', 'admin'];
+ } else {
+ $options['auth'] = [$this->currentUser, '123456'];
+ }
+ if ($body instanceof \Behat\Gherkin\Node\TableNode) {
+ $fd = $body->getRowsHash();
+ $options['body'] = $fd;
+ }
+
+ try {
+ $this->response = $client->send($client->createRequest($verb, $fullUrl, $options));
+ } catch (\GuzzleHttp\Exception\ClientException $ex) {
+ $this->response = $ex->getResponse();
+ }
+ }
+
+ /**
+ * Parses the xml answer to get ocs response which doesn't match with
+ * http one in v1 of the api.
+ * @param ResponseInterface $response
+ * @return string
+ */
+ private function getOCSResponse($response) {
+ return $response->xml()->meta[0]->statuscode;
+ }
+
+ /**
+ * @Then /^the OCS status code should be "([^"]*)"$/
+ * @param int $statusCode
+ */
+ public function theOCSStatusCodeShouldBe($statusCode) {
+ PHPUnit_Framework_Assert::assertEquals($statusCode, $this->getOCSResponse($this->response));
+ }
+
+ /**
+ * @Then /^the HTTP status code should be "([^"]*)"$/
+ * @param int $statusCode
+ */
+ public function theHTTPStatusCodeShouldBe($statusCode) {
+ PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
+ }
}
diff --git a/tests/integration/features/delete-notifications.feature b/tests/integration/features/delete-notifications.feature
index cc28cea..c2cccb3 100644
--- a/tests/integration/features/delete-notifications.feature
+++ b/tests/integration/features/delete-notifications.feature
@@ -1,8 +1,7 @@
Feature: delete-notifications
Background:
- Given using api version "2"
Given user "test1" exists
- Given As an "test1"
+ Given As user "test1"
Scenario: Delete first notification
Given user "test1" has notifications
diff --git a/tests/integration/features/notifications-content.feature b/tests/integration/features/notifications-content.feature
index be568f0..1366eb4 100644
--- a/tests/integration/features/notifications-content.feature
+++ b/tests/integration/features/notifications-content.feature
@@ -1,8 +1,7 @@
Feature: notifications-content
Background:
- Given using api version "2"
Given user "test1" exists
- Given As an "test1"
+ Given As user "test1"
Scenario: Create notification
Given user "test1" receives notification with
diff --git a/tests/integration/features/statuscodes.feature b/tests/integration/features/statuscodes.feature
index 401687b..c9a68d3 100644
--- a/tests/integration/features/statuscodes.feature
+++ b/tests/integration/features/statuscodes.feature
@@ -1,8 +1,7 @@
Feature: statuscodes
Background:
- Given using api version "2"
Given user "test1" exists
- Given As an "test1"
+ Given As user "test1"
Scenario: Status code when reading notifications with notifiers and without notifications
When sending "GET" to "/apps/notifications/api/v1/notifications?format=json"
diff --git a/tests/integration/run.sh b/tests/integration/run.sh
index 1e6b6cb..6d51763 100644
--- a/tests/integration/run.sh
+++ b/tests/integration/run.sh
@@ -5,19 +5,20 @@ APP_NAME=notifications
APP_INTEGRATION_DIR=$PWD
ROOT_DIR=${APP_INTEGRATION_DIR}/../../../..
-cd ${ROOT_DIR}/build/integration
+#cd ${ROOT_DIR}/build/integration
composer install
-cd ${APP_INTEGRATION_DIR}
+#cd ${APP_INTEGRATION_DIR}
php -S localhost:8080 -t ${ROOT_DIR} &
PHPPID=$!
echo $PHPPID
cp -R ./app ../../../notificationsintegrationtesting
+${ROOT_DIR}/occ app:enable notifications
${ROOT_DIR}/occ app:enable notificationsintegrationtesting
-export TEST_SERVER_URL="http://localhost:8080/ocs/"
-${ROOT_DIR}/build/integration/vendor/bin/behat -f junit -f pretty
+export TEST_SERVER_URL="http://localhost:8080/"
+${APP_INTEGRATION_DIR}/vendor/bin/behat -f junit -f pretty
RESULT=$?
kill $PHPPID