diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml index 5e11f3a2819a..768915d6e0b4 100644 --- a/tests/integration/config/behat.yml +++ b/tests/integration/config/behat.yml @@ -13,13 +13,11 @@ default: - admin regular_user_password: 123456 mailhog_url: http://127.0.0.1:8025/api/v2/messages + oc_path: ../../ - CardDavContext: baseUrl: http://localhost:8080 - CalDavContext: baseUrl: http://localhost:8080 - - CommandLineContext: - baseUrl: http://localhost:8080 - ocPath: ../../ - AppManagementContext: federation: paths: @@ -32,6 +30,7 @@ default: - admin regular_user_password: 123456 mailhog_url: http://127.0.0.1:8025/api/v2/messages + oc_path: ../../ capabilities: paths: - %paths.base%/../capabilities_features @@ -43,6 +42,7 @@ default: - admin regular_user_password: 123456 mailhog_url: http://127.0.0.1:8025/api/v2/messages + oc_path: ../../ sharees: paths: - %paths.base%/../sharees_features @@ -54,6 +54,7 @@ default: - admin regular_user_password: 123456 mailhog_url: http://127.0.0.1:8025/api/v2/messages + oc_path: ../../ extensions: jarnaiz\JUnitFormatter\JUnitFormatterExtension: diff --git a/tests/integration/features/bootstrap/BasicStructure.php b/tests/integration/features/bootstrap/BasicStructure.php index 33a83b973384..94fe36918c01 100644 --- a/tests/integration/features/bootstrap/BasicStructure.php +++ b/tests/integration/features/bootstrap/BasicStructure.php @@ -2,6 +2,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Message\ResponseInterface; +use Behat\Gherkin\Node\PyStringNode; require __DIR__ . '/../../../../lib/composer/autoload.php'; @@ -17,6 +18,7 @@ trait BasicStructure { use Tags; use Trashbin; use WebDav; + use CommandLine; /** @var string */ private $currentUser = ''; @@ -39,7 +41,7 @@ trait BasicStructure { /** @var string */ private $requestToken; - public function __construct($baseUrl, $admin, $regular_user_password, $mailhog_url) { + public function __construct($baseUrl, $admin, $regular_user_password, $mailhog_url, $oc_path) { // Initialize your context here $this->baseUrl = $baseUrl; @@ -50,6 +52,7 @@ public function __construct($baseUrl, $admin, $regular_user_password, $mailhog_u $this->remoteBaseUrl = $this->baseUrl; $this->currentServer = 'LOCAL'; $this->cookieJar = new \GuzzleHttp\Cookie\CookieJar(); + $this->ocPath = $oc_path; // in case of CI deployment we take the server url from the environment $testServerUrl = getenv('TEST_SERVER_URL'); @@ -461,6 +464,51 @@ private function getPasswordForUser($userName) { } } + /** + * @When requesting status.php + */ + public function getStatusPhp(){ + $fullUrl = $this->baseUrlWithoutOCSAppendix() . "status.php"; + $client = new Client(); + $options = []; + $options['auth'] = $this->adminUser; + try { + $this->response = $client->send($client->createRequest('GET', $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + } + + /** + * @Then the json responded should match with + */ + public function jsonRespondedShouldMatch(PyStringNode $jsonExpected) { + $jsonExpectedEncoded = json_encode($jsonExpected->getRaw()); + $jsonRespondedEncoded = json_encode((string) $this->response->getBody()); + PHPUnit\Framework\Assert::assertEquals($jsonExpectedEncoded, $jsonRespondedEncoded); + } + + /** + * @Then the status.php with versions fixed responded should match with + */ + public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected) { + $jsonExpectedDecoded = json_decode($jsonExpected->getRaw(), true); + $jsonRespondedEncoded = json_encode(json_decode($this->response->getBody(), true)); + if ($this->runOcc(['status']) === 0) { + $output = explode("- ", $this->lastStdOut); + $version = explode(": ", $output[2]); + PHPUnit_Framework_Assert::assertEquals("version", $version[0]); + $versionString = explode(": ", $output[3]); + PHPUnit_Framework_Assert::assertEquals("versionstring", $versionString[0]); + $jsonExpectedDecoded['version'] = trim($version[1]); + $jsonExpectedDecoded['versionstring'] = trim($versionString[1]); + $jsonExpectedEncoded = json_encode($jsonExpectedDecoded); + } else { + PHPUnit_Framework_Assert::fail('Cannot get version variables from occ'); + } + PHPUnit\Framework\Assert::assertEquals($jsonExpectedEncoded, $jsonRespondedEncoded); + } + /** * @BeforeScenario @local_storage */ diff --git a/tests/integration/features/bootstrap/CommandLine.php b/tests/integration/features/bootstrap/CommandLine.php index c69d28298e64..254193f50b37 100644 --- a/tests/integration/features/bootstrap/CommandLine.php +++ b/tests/integration/features/bootstrap/CommandLine.php @@ -163,4 +163,73 @@ public function theCommandErrorOutputContainsTheText($text) { throw new \Exception('The command did not output the expected text on stderr "' . $text . '"'); } } + + private $lastTransferPath; + + private function findLastTransferFolderForUser($sourceUser, $targetUser) { + $foundPaths = []; + $results = $this->listFolder($targetUser, '', 1); + foreach ($results as $path => $data) { + $path = rawurldecode($path); + $parts = explode(' ', $path); + if (basename($parts[0]) !== 'transferred') { + continue; + } + if (isset($parts[2]) && $parts[2] === $sourceUser) { + // store timestamp as key + $foundPaths[] = [ + 'date' => strtotime(trim($parts[4], '/')), + 'path' => $path, + ]; + } + } + + if (empty($foundPaths)) { + return null; + } + + usort($foundPaths, function($a, $b) { + return $a['date'] - $b['date']; + }); + + $davPath = rtrim($this->getDavFilesPath($targetUser), '/'); + + $foundPath = end($foundPaths)['path']; + // strip dav path + return substr($foundPath, strlen($davPath) + 1); + } + + /** + * @When /^transferring ownership from "([^"]+)" to "([^"]+)"/ + */ + public function transferringOwnership($user1, $user2) { + if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) { + $this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2); + } else { + // failure + $this->lastTransferPath = null; + } + } + + /** + * @When /^transferring ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)"/ + */ + public function transferringOwnershipPath($path, $user1, $user2) { + $path = '--path=' . $path; + if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) { + $this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2); + } else { + // failure + $this->lastTransferPath = null; + } + } + + /** + * @When /^using received transfer folder of "([^"]+)" as dav path$/ + */ + public function usingTransferFolderAsDavPath($user) { + $davPath = $this->getDavFilesPath($user); + $davPath = rtrim($davPath, '/') . $this->lastTransferPath; + $this->usingDavPath($davPath); + } } diff --git a/tests/integration/features/bootstrap/CommandLineContext.php b/tests/integration/features/bootstrap/CommandLineContext.php deleted file mode 100644 index 192cd6b9c060..000000000000 --- a/tests/integration/features/bootstrap/CommandLineContext.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * @copyright Copyright (c) 2016, 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 - * - */ - -require __DIR__ . '/../../../../lib/composer/autoload.php'; - -use Behat\Behat\Hook\Scope\BeforeScenarioScope; - -class CommandLineContext implements \Behat\Behat\Context\Context { - use CommandLine; - - private $lastTransferPath; - - private $featureContext; - - public function __construct($ocPath, $baseUrl) { - $this->ocPath = rtrim($ocPath, '/') . '/'; - $this->localBaseUrl = $baseUrl; - $this->remoteBaseUrl = $baseUrl; - } - - /** @BeforeScenario */ - public function gatherContexts(BeforeScenarioScope $scope) { - $environment = $scope->getEnvironment(); - // this should really be "WebDavContext" ... - $this->featureContext = $environment->getContext('FeatureContext'); - } - - private function findLastTransferFolderForUser($sourceUser, $targetUser) { - $foundPaths = []; - $results = $this->featureContext->listFolder($targetUser, '', 1); - foreach ($results as $path => $data) { - $path = rawurldecode($path); - $parts = explode(' ', $path); - if (basename($parts[0]) !== 'transferred') { - continue; - } - if (isset($parts[2]) && $parts[2] === $sourceUser) { - // store timestamp as key - $foundPaths[] = [ - 'date' => strtotime(trim($parts[4], '/')), - 'path' => $path, - ]; - } - } - - if (empty($foundPaths)) { - return null; - } - - usort($foundPaths, function($a, $b) { - return $a['date'] - $b['date']; - }); - - $davPath = rtrim($this->featureContext->getDavFilesPath($targetUser), '/'); - - $foundPath = end($foundPaths)['path']; - // strip dav path - return substr($foundPath, strlen($davPath) + 1); - } - - /** - * @When /^transferring ownership from "([^"]+)" to "([^"]+)"/ - */ - public function transferringOwnership($user1, $user2) { - if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) { - $this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2); - } else { - // failure - $this->lastTransferPath = null; - } - } - - /** - * @When /^transferring ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)"/ - */ - public function transferringOwnershipPath($path, $user1, $user2) { - $path = '--path=' . $path; - if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) { - $this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2); - } else { - // failure - $this->lastTransferPath = null; - } - } - - /** - * @When /^using received transfer folder of "([^"]+)" as dav path$/ - */ - public function usingTransferFolderAsDavPath($user) { - $davPath = $this->featureContext->getDavFilesPath($user); - $davPath = rtrim($davPath, '/') . $this->lastTransferPath; - $this->featureContext->usingDavPath($davPath); - } -} diff --git a/tests/integration/features/status.feature b/tests/integration/features/status.feature new file mode 100644 index 000000000000..5060eb3e7a34 --- /dev/null +++ b/tests/integration/features/status.feature @@ -0,0 +1,8 @@ +Feature: Status + + Scenario: Status.php is correct + When requesting status.php + Then the status.php with versions fixed responded should match with + """ + {"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"$CURRENT_VERSION","versionstring":"$CURRENT_VERSION_STRING","edition":"Community","productname":"ownCloud"} + """