Add integration test skeleton
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
9702daaac7
Коммит
6b1d560bf9
35
.drone.yml
35
.drone.yml
|
@ -81,6 +81,41 @@ trigger:
|
|||
- push
|
||||
---
|
||||
kind: pipeline
|
||||
name: integration
|
||||
|
||||
steps:
|
||||
- name: nextcloud
|
||||
image: nextcloudci/php7.3:php7.3-5
|
||||
environment:
|
||||
APP_NAME: richdocuments
|
||||
CORE_BRANCH: master
|
||||
DB: sqlite
|
||||
commands:
|
||||
- bash ./tests/drone-server-setup.sh $APP_NAME $CORE_BRANCH $DB
|
||||
- cd ../server
|
||||
- ./occ app:enable $APP_NAME
|
||||
- cd apps/$APP_NAME
|
||||
|
||||
# Run integration tests
|
||||
- cd tests
|
||||
- bash run-integration.sh features/wopi
|
||||
services:
|
||||
- name: collabora
|
||||
image: collabora/code:4.0.9.4
|
||||
environment:
|
||||
extra_params: '--o:ssl.enable=false'
|
||||
domain: 'nextcloud'
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
- stable*
|
||||
event:
|
||||
- pull_request
|
||||
- push
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: jest
|
||||
steps:
|
||||
- name: jest
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~8.0",
|
||||
"behat/behat": "^3.0",
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"jarnaiz/behat-junit-formatter": "^1.3",
|
||||
"sabre/dav": "^4.0",
|
||||
"juliushaertl/nextcloud-behat": "dev-master"
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,15 @@
|
|||
default:
|
||||
autoload:
|
||||
'': '%paths.base%/../features/bootstrap'
|
||||
suites:
|
||||
default:
|
||||
paths:
|
||||
- '%paths.base%/../features'
|
||||
contexts:
|
||||
- FeatureContext:
|
||||
baseUrl: 'http://localhost:8080'
|
||||
|
||||
extensions:
|
||||
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
|
||||
filename: report.xml
|
||||
outputDir: '%paths.base%/../output/'
|
|
@ -57,6 +57,9 @@ echo "Installing server"
|
|||
cd ../server
|
||||
bash $WORKDIR/tests/drone-server-install.sh $DB
|
||||
|
||||
export OC_PASS=123456
|
||||
php occ user:add --password-from-env user1
|
||||
php occ user:add --password-from-env user2
|
||||
echo "Installing app: $APP_NAME"
|
||||
php occ app:enable $APP_NAME
|
||||
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class FeatureContext implements Context
|
||||
{
|
||||
|
||||
use \JuliusHaertl\NextcloudBehat\FilesSharingContextTrait;
|
||||
use \JuliusHaertl\NextcloudBehat\FilesDavContextTrait;
|
||||
use \JuliusHaertl\NextcloudBehat\UserContextTrait;
|
||||
use \JuliusHaertl\NextcloudBehat\UserWebContextTrait;
|
||||
|
||||
/**
|
||||
* Initializes context.
|
||||
*
|
||||
* Every scenario gets its own context instance.
|
||||
* You can also pass arbitrary arguments to the
|
||||
* context constructor through behat.yml.
|
||||
*/
|
||||
public function __construct($baseUrl)
|
||||
{
|
||||
$this->setBaseUrl($baseUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When User :user opens :file
|
||||
*/
|
||||
public function userOpens($user, $file)
|
||||
{
|
||||
// get file id
|
||||
$davClient = $this->getSabreClient($user);
|
||||
$path = $this->makeSabrePath($user, $file);
|
||||
$result = $davClient->propFind($path, ['{http://owncloud.org/ns}fileid']);
|
||||
$fileId = $result['{http://owncloud.org/ns}fileid'];
|
||||
|
||||
$this->usingWebAsUser($user);
|
||||
|
||||
$client = new Client();
|
||||
$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/index?fileId=' . $fileId, $this->getWebOptions());
|
||||
$contents =$result->getBody()->getContents();
|
||||
$re = '/var richdocuments_([A-z]+) = (.*);/m';
|
||||
preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
|
||||
$result = [];
|
||||
foreach ($matches as $match) {
|
||||
$result[$match[1]] = str_replace("'", "", $match[2]);
|
||||
}
|
||||
|
||||
$this->fileId = $result['fileId'];
|
||||
$this->wopiToken = $result['token'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then a guest opens the share link
|
||||
*/
|
||||
public function aGuestOpensTheShareLink()
|
||||
{
|
||||
if (count($this->lastShareData->data->element) > 0){
|
||||
$token = $this->lastShareData->data[0]->token;
|
||||
} else {
|
||||
$token = $this->lastShareData->data->token;
|
||||
}
|
||||
|
||||
|
||||
// public function publicPage($shareToken, $fileName, $fileId) {
|
||||
$client = new Client();
|
||||
$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/public?shareToken=' . $token, $this->getWebOptions());
|
||||
$contents =$result->getBody()->getContents();
|
||||
$re = '/var richdocuments_([A-z]+) = (.*);/m';
|
||||
preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
|
||||
$result = [];
|
||||
foreach ($matches as $match) {
|
||||
$result[$match[1]] = str_replace("'", "", $match[2]);
|
||||
}
|
||||
|
||||
$this->fileId = $result['fileId'];
|
||||
$this->wopiToken = $result['token'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Collabora fetches checkFileInfo
|
||||
*/
|
||||
public function collaboraFetchesCheckfileinfo() {
|
||||
$client = new Client();
|
||||
$options = [];
|
||||
$result = $client->get($this->baseUrl . 'index.php/apps/richdocuments/wopi/files/' . $this->fileId . '?access_token=' . $this->wopiToken, $options);
|
||||
$this->checkFileInfoResult = json_decode($result->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then Collabora puts :source
|
||||
*/
|
||||
public function collaboraPuts($source)
|
||||
{
|
||||
$file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r'));
|
||||
$client = new Client();
|
||||
$options = [
|
||||
'data' => $file,
|
||||
'headers' => [
|
||||
'X-LOOL-WOPI-Timestamp' => $this->checkFileInfoResult['LastModifiedTime']
|
||||
]
|
||||
];
|
||||
$result = $client->post($this->baseUrl . 'index.php/apps/richdocuments/wopi/files/' . $this->fileId . '/contents?access_token=' . $this->wopiToken, $options);
|
||||
$this->checkFileInfoResult = json_decode($result->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then checkFileInfo :arg1 is ":arg2"
|
||||
*/
|
||||
public function checkfileinfoIs($arg1, $arg2)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertEquals($arg2, $this->checkFileInfoResult[$arg1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then checkFileInfo :arg1 matches ":arg2"
|
||||
*/
|
||||
public function checkfileinfoMatches($arg1, $arg2)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertRegExp($arg2, $this->checkFileInfoResult[$arg1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then checkFileInfo :arg1 is true
|
||||
*/
|
||||
public function checkfileinfoIsTrue($arg1)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertTrue($this->checkFileInfoResult[$arg1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then checkFileInfo :arg1 is false
|
||||
*/
|
||||
public function checkfileinfoIsFalse($arg1)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertFalse($this->checkFileInfoResult[$arg1]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
trait NextcloudTrait {
|
||||
|
||||
public $baseUrl;
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
Feature: wopi
|
||||
|
||||
Background
|
||||
Given "user1" exists
|
||||
Given "user2" exists
|
||||
|
||||
Scenario: Create a new wopi token for a user and open it
|
||||
Given as user "user1"
|
||||
And User "user1" uploads file "./../assets/template.odt" to "/file.odt"
|
||||
Then User "user1" opens "/file.odt"
|
||||
And Collabora fetches checkFileInfo
|
||||
And checkFileInfo "BaseFileName" is "file.odt"
|
||||
And checkFileInfo "UserId" is "user1"
|
||||
And checkFileInfo "OwnerId" is "user1"
|
||||
And checkFileInfo "UserCanWrite" is true
|
||||
|
||||
Scenario: Fetch checkFileInfo for public share link
|
||||
Given as user "user1"
|
||||
And User "user1" uploads file "./../assets/template.odt" to "/file.odt"
|
||||
And as "user1" create a share with
|
||||
| path | /file.odt |
|
||||
| shareType | 3 |
|
||||
Then Using web as guest
|
||||
And a guest opens the share link
|
||||
And Collabora fetches checkFileInfo
|
||||
And checkFileInfo "BaseFileName" is "file.odt"
|
||||
And checkFileInfo "UserId" matches "/Guest-/"
|
||||
And checkFileInfo "OwnerId" is "user1"
|
||||
And checkFileInfo "UserCanWrite" is false
|
||||
|
||||
Scenario: Save a file as the owner
|
||||
Given as user "user1"
|
||||
And User "user1" uploads file "./../assets/template.odt" to "/file.odt"
|
||||
Then User "user1" opens "/file.odt"
|
||||
And Collabora fetches checkFileInfo
|
||||
And checkFileInfo "UserCanWrite" is true
|
||||
And Collabora puts "./../assets/template.odt"
|
||||
|
||||
|
||||
Scenario: Save a file as guest with write permissions
|
||||
Given as user "user1"
|
||||
And User "user1" uploads file "./../assets/template.odt" to "/file.odt"
|
||||
And as "user1" create a share with
|
||||
| path | /file.odt |
|
||||
| shareType | 3 |
|
||||
And Updating last share with
|
||||
| permissions | 3 |
|
||||
And the HTTP status code should be "200"
|
||||
Then Using web as guest
|
||||
And a guest opens the share link
|
||||
And Collabora fetches checkFileInfo
|
||||
And checkFileInfo "BaseFileName" is "file.odt"
|
||||
And checkFileInfo "UserId" matches "/Guest-/"
|
||||
And checkFileInfo "OwnerId" is "user1"
|
||||
And checkFileInfo "UserCanWrite" is true
|
||||
And Collabora puts "./../assets/template.odt"
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
OC_PATH=../../../
|
||||
OCC=${OC_PATH}occ
|
||||
SCENARIO_TO_RUN=$1
|
||||
HIDE_OC_LOGS=$2
|
||||
APP_NAME=richdocuments
|
||||
|
||||
INSTALLED=$($OCC status | grep installed: | cut -d " " -f 5)
|
||||
|
||||
if [ "$INSTALLED" == "true" ]; then
|
||||
$OCC app:enable $APP_NAME
|
||||
else
|
||||
if [ "$SCENARIO_TO_RUN" != "setup_features/setup.feature" ]; then
|
||||
echo "Nextcloud instance needs to be installed" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
composer install
|
||||
composer dump-autoload
|
||||
|
||||
curl -v http://collabora:9980/hosting/capabilities
|
||||
|
||||
PORT=8080
|
||||
php -S localhost:$PORT -t $OC_PATH &
|
||||
PHPPID=$!
|
||||
echo $PHPPID
|
||||
|
||||
|
||||
#export BEHAT_PARAMS="context[parameters][base_url]=https://nextcloud.local.dev.bitgrid.net"
|
||||
$OCC config:app:set richdocuments wopi_url --value="http://collabora:9980"
|
||||
$OCC config:app:set richdocuments public_wopi_url --value="http://collabora:9980"
|
||||
|
||||
|
||||
vendor/bin/behat
|
||||
RESULT=$?
|
||||
|
||||
kill $PHPPID
|
||||
|
||||
echo "runsh: Exit code: $RESULT"
|
||||
exit $RESULT
|
Загрузка…
Ссылка в новой задаче