Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tests/integration/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
50 changes: 49 additions & 1 deletion tests/integration/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
use Behat\Gherkin\Node\PyStringNode;

require __DIR__ . '/../../../../lib/composer/autoload.php';

Expand All @@ -17,6 +18,7 @@ trait BasicStructure {
use Tags;
use Trashbin;
use WebDav;
use CommandLine;

/** @var string */
private $currentUser = '';
Expand All @@ -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;
Expand All @@ -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');
Expand Down Expand Up @@ -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
*/
Expand Down
69 changes: 69 additions & 0 deletions tests/integration/features/bootstrap/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
112 changes: 0 additions & 112 deletions tests/integration/features/bootstrap/CommandLineContext.php

This file was deleted.

8 changes: 8 additions & 0 deletions tests/integration/features/status.feature
Original file line number Diff line number Diff line change
@@ -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"}
"""