summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/integration/features/bootstrap/CommandLineTrait.php177
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php2
-rw-r--r--tests/integration/features/command/active-calls.feature41
3 files changed, 220 insertions, 0 deletions
diff --git a/tests/integration/features/bootstrap/CommandLineTrait.php b/tests/integration/features/bootstrap/CommandLineTrait.php
new file mode 100644
index 000000000..d8dd7f5d9
--- /dev/null
+++ b/tests/integration/features/bootstrap/CommandLineTrait.php
@@ -0,0 +1,177 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Robin Appelman <robin@icewind.nl>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @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/>
+ *
+ */
+
+require __DIR__ . '/../../vendor/autoload.php';
+
+trait CommandLineTrait {
+
+ /** @var int return code of last command */
+ private $lastCode;
+ /** @var string stdout of last command */
+ private $lastStdOut;
+ /** @var string stderr of last command */
+ private $lastStdErr;
+
+ /** @var string */
+ protected $ocPath = '../../../..';
+
+ /**
+ * Invokes an OCC command
+ *
+ * @param []string $args OCC command, the part behind "occ". For example: "files:transfer-ownership"
+ * @return int exit code
+ */
+ public function runOcc($args = []) {
+ $args = array_map(function ($arg) {
+ return escapeshellarg($arg);
+ }, $args);
+ $args[] = '--no-ansi';
+ $args = implode(' ', $args);
+
+ $descriptor = [
+ 0 => ['pipe', 'r'],
+ 1 => ['pipe', 'w'],
+ 2 => ['pipe', 'w'],
+ ];
+ $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $this->ocPath);
+ $this->lastStdOut = stream_get_contents($pipes[1]);
+ $this->lastStdErr = stream_get_contents($pipes[2]);
+ $this->lastCode = proc_close($process);
+
+ // Clean opcode cache
+ $client = new GuzzleHttp\Client();
+ $client->request('GET', 'http://localhost:8080/apps/testing/clean_opcode_cache.php');
+
+ return $this->lastCode;
+ }
+
+ /**
+ * @Given /^invoking occ with "([^"]*)"$/
+ */
+ public function invokingTheCommand($cmd) {
+ $args = explode(' ', $cmd);
+ $this->runOcc($args);
+ }
+
+ /**
+ * Find exception texts in stderr
+ */
+ public function findExceptions() {
+ $exceptions = [];
+ $captureNext = false;
+ // the exception text usually appears after an "[Exception"] row
+ foreach (explode("\n", $this->lastStdErr) as $line) {
+ if (preg_match('/\[Exception\]/', $line)) {
+ $captureNext = true;
+ continue;
+ }
+ if ($captureNext) {
+ $exceptions[] = trim($line);
+ $captureNext = false;
+ }
+ }
+
+ return $exceptions;
+ }
+
+ /**
+ * Finds all lines containing the given text
+ *
+ * @param string $input stdout or stderr output
+ * @param string $text text to search for
+ * @return array array of lines that matched
+ */
+ public function findLines($input, $text) {
+ $results = [];
+ // the exception text usually appears after an "[Exception"] row
+ foreach (explode("\n", $input) as $line) {
+ if (strpos($line, $text) !== false) {
+ $results[] = $line;
+ }
+ }
+
+ return $results;
+ }
+
+ /**
+ * @Then /^the command was successful$/
+ */
+ public function theCommandWasSuccessful() {
+ $exceptions = $this->findExceptions();
+ if ($this->lastCode !== 0) {
+ $msg = 'The command was not successful, exit code was ' . $this->lastCode . '.';
+ if (!empty($exceptions)) {
+ $msg .= ' Exceptions: ' . implode(', ', $exceptions);
+ }
+ throw new \Exception($msg);
+ } elseif (!empty($exceptions)) {
+ $msg = 'The command was successful but triggered exceptions: ' . implode(', ', $exceptions);
+ throw new \Exception($msg);
+ }
+ }
+
+ /**
+ * @Then /^the command failed with exit code ([0-9]+)$/
+ */
+ public function theCommandFailedWithExitCode($exitCode) {
+ if ($this->lastCode !== (int)$exitCode) {
+ throw new \Exception('The command was expected to fail with exit code ' . $exitCode . ' but got ' . $this->lastCode);
+ }
+ }
+
+ /**
+ * @Then /^the command failed with exception text "([^"]*)"$/
+ */
+ public function theCommandFailedWithException($exceptionText) {
+ $exceptions = $this->findExceptions();
+ if (empty($exceptions)) {
+ throw new \Exception('The command did not throw any exceptions');
+ }
+
+ if (!in_array($exceptionText, $exceptions)) {
+ throw new \Exception('The command did not throw any exception with the text "' . $exceptionText . '"');
+ }
+ }
+
+ /**
+ * @Then /^the command output contains the text "([^"]*)"$/
+ */
+ public function theCommandOutputContainsTheText($text) {
+ $lines = $this->findLines($this->lastStdOut, $text);
+ if (empty($lines)) {
+ throw new \Exception('The command did not output the expected text on stdout "' . $text . '"');
+ }
+ }
+
+ /**
+ * @Then /^the command error output contains the text "([^"]*)"$/
+ */
+ public function theCommandErrorOutputContainsTheText($text) {
+ $lines = $this->findLines($this->lastStdErr, $text);
+ if (empty($lines)) {
+ throw new \Exception('The command did not output the expected text on stderr "' . $text . '"');
+ }
+ }
+}
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index b95e5d67f..b9b3a20cb 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -74,6 +74,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var SharingContext */
private $sharingContext;
+ use CommandLineTrait;
+
public static function getTokenForIdentifier(string $identifier) {
return self::$identifierToToken[$identifier];
}
diff --git a/tests/integration/features/command/active-calls.feature b/tests/integration/features/command/active-calls.feature
new file mode 100644
index 000000000..f73145c77
--- /dev/null
+++ b/tests/integration/features/command/active-calls.feature
@@ -0,0 +1,41 @@
+Feature: create
+
+ Background:
+ Given user "participant1" exists
+
+ Scenario: No call in progress
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"
+
+ Scenario: Users only chatting
+ When user "participant1" creates room "room"
+ | roomType | 3 |
+ | roomName | room |
+ Then user "participant1" joins room "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"
+
+ Then user "participant1" leaves room "room" with 200
+
+
+ Scenario: Call in progress
+ When user "participant1" creates room "room"
+ | roomType | 3 |
+ | roomName | room |
+
+ Then user "participant1" joins room "room" with 200
+ And user "participant1" joins call "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ Then the command failed with exit code 1
+ And the command output contains the text "There are currently 1 calls in progress with 1 participants"
+
+ Then user "participant1" leaves call "room" with 200
+ And user "participant1" leaves room "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"