Compare commits

...

1 Commits

Author SHA1 Message Date
Julius Härtl
1b02e7fb25 Move to behat helper library
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2021-05-25 18:18:07 +02:00
13 changed files with 128 additions and 307 deletions

View File

@@ -1,18 +1,29 @@
{ {
"require-dev": { "name": "nextcloud/deck-integration",
"phpunit/phpunit": "~6.5", "description": "Integration tests for the deck app",
"behat/behat": "~3.8.0", "require-dev": {
"guzzlehttp/guzzle": "6.5.2", "phpunit/phpunit": "^9",
"jarnaiz/behat-junit-formatter": "^1.3", "behat/behat": "^3",
"sabre/dav": "3.2.3", "guzzlehttp/guzzle": "^7",
"symfony/event-dispatcher": "~4.4" "jarnaiz/behat-junit-formatter": "^1.3",
}, "sabre/dav": "^4",
"autoload": { "symfony/event-dispatcher": "~4.4",
"psr-0": { "juliushaertl/nextcloud-behat": "*"
"": [ },
"features/bootstrap/", "minimum-stability": "dev",
"../../../../build/integration/features/bootstrap/" "prefer-stable": true,
] "repositories": [
} {
} "type": "path",
"url": "/home/jus/repos/nextcloud/nextcloud-behat"
}
],
"autoload": {
"psr-0": {
"": [
"features/bootstrap/",
"../../../../build/integration/features/bootstrap/"
]
}
}
} }

View File

@@ -1,12 +1,17 @@
default: default:
autoload:
'': '%paths.base%/../features/bootstrap'
suites: suites:
test: test:
paths: paths:
- '%paths.base%/../features/' - '%paths.base%/../features/'
contexts: contexts:
- ServerContext: - \JuliusHaertl\NextcloudBehat\Context\ServerContext:
baseUrl: http://localhost:8080/ servers:
- RequestContext default: http://localhost:8080
- \JuliusHaertl\NextcloudBehat\Context\SharingContext
- \JuliusHaertl\NextcloudBehat\Context\FilesContext
- BoardContext - BoardContext
- CommentContext - CommentContext
- SearchContext - SearchContext
- PendingContext

View File

@@ -8,83 +8,83 @@ Feature: acl
And user "user2" exists And user "user2" exists
Given group "group0" exists Given group "group0" exists
And group "group1" exists And group "group1" exists
Given user "user1" belongs to group "group1" Given user "user1" is member of group "group1"
Scenario: Fetch the board list Scenario: Fetch the board list
Given Logging in using web as "user0" Given Using web as user "user0"
When fetching the board list When fetching the board list
Then the response should have a status code "200" Then the HTTP status code should be "200"
And the response Content-Type should be "application/json; charset=utf-8" And the response Content-Type should be "application/json; charset=utf-8"
Scenario: Fetch board details of owned board Scenario: Fetch board details of owned board
Given Logging in using web as "admin" Given Using web as user "admin"
And creates a board named "MyPrivateAdminBoard" with color "fafafa" And creates a board named "MyPrivateAdminBoard" with color "fafafa"
When fetches the board named "MyPrivateAdminBoard" When fetches the board named "MyPrivateAdminBoard"
Then the response should have a status code "200" Then the HTTP status code should be "200"
And the response Content-Type should be "application/json; charset=utf-8" And the response Content-Type should be "application/json; charset=utf-8"
Scenario: Fetch board details of an other users board Scenario: Fetch board details of an other users board
Given Logging in using web as "admin" Given Using web as user "admin"
And creates a board named "MyPrivateAdminBoard" with color "ff0000" And creates a board named "MyPrivateAdminBoard" with color "ff0000"
Given Logging in using web as "user0" Given Using web as user "user0"
When fetches the board named "MyPrivateAdminBoard" When fetches the board named "MyPrivateAdminBoard"
Then the response should have a status code "403" Then the HTTP status code should be "403"
And the response Content-Type should be "application/json; charset=utf-8" And the response Content-Type should be "application/json; charset=utf-8"
Scenario: Share a board Scenario: Share a board
Given Logging in using web as "user0" Given Using web as user "user0"
And creates a board named "Shared board" with color "ff0000" And creates a board named "Shared board" with color "ff0000"
And shares the board with user "user1" And shares the board with user "user1"
| permissionEdit | 0 | | permissionEdit | 0 |
| permissionShare | 0 | | permissionShare | 0 |
| permissionManage | 0 | | permissionManage | 0 |
And the response should have a status code 200 And the HTTP status code should be 200
And shares the board with user "user2" And shares the board with user "user2"
| permissionEdit | 1 | | permissionEdit | 1 |
| permissionShare | 1 | | permissionShare | 1 |
| permissionManage | 1 | | permissionManage | 1 |
And the response should have a status code 200 And the HTTP status code should be 200
Given Logging in using web as "user2" Given Using web as user "user2"
When fetches the board named "Shared board" When fetches the board named "Shared board"
Then the current user should have "read" permissions on the board Then the current user should have "read" permissions on the board
And the current user should have "edit" permissions on the board And the current user should have "edit" permissions on the board
And the current user should have "share" permissions on the board And the current user should have "share" permissions on the board
And the current user should have "manage" permissions on the board And the current user should have "manage" permissions on the board
And create a stack named "Stack" And create a stack named "Stack"
And the response should have a status code 200 And the HTTP status code should be 200
And create a card named "Test" And create a card named "Test"
And the response should have a status code 200 And the HTTP status code should be 200
Given Logging in using web as "user1" Given Using web as user "user1"
When fetches the board named "Shared board" When fetches the board named "Shared board"
And create a card named "Test" And create a card named "Test"
And the response should have a status code 403 And the HTTP status code should be 403
Then the current user should have "read" permissions on the board Then the current user should have "read" permissions on the board
And the current user should not have "edit" permissions on the board And the current user should not have "edit" permissions on the board
And the current user should not have "share" permissions on the board And the current user should not have "share" permissions on the board
And the current user should not have "manage" permissions on the board And the current user should not have "manage" permissions on the board
And create a stack named "Stack" And create a stack named "Stack"
And the response should have a status code 403 And the HTTP status code should be 403
Scenario: Reshare a board Scenario: Reshare a board
Given Logging in using web as "user0" Given Using web as user "user0"
And creates a board named "Reshared board" with color "ff0000" And creates a board named "Reshared board" with color "ff0000"
And shares the board with user "user1" And shares the board with user "user1"
| permissionEdit | 0 | | permissionEdit | 0 |
| permissionShare | 1 | | permissionShare | 1 |
| permissionManage | 0 | | permissionManage | 0 |
And the response should have a status code 200 And the HTTP status code should be 200
Given Logging in using web as "user1" Given Using web as user "user1"
When fetches the board named "Shared board" When fetches the board named "Shared board"
And shares the board with user "user2" And shares the board with user "user2"
| permissionEdit | 1 | | permissionEdit | 1 |
| permissionShare | 1 | | permissionShare | 1 |
| permissionManage | 1 | | permissionManage | 1 |
And the response should have a status code 200 And the HTTP status code should be 200
Given Logging in using web as "user2" Given Using web as user "user2"
When fetches the board named "Shared board" When fetches the board named "Shared board"
Then the current user should have "read" permissions on the board Then the current user should have "read" permissions on the board
And the current user should not have "edit" permissions on the board And the current user should not have "edit" permissions on the board

View File

@@ -3,12 +3,13 @@
use Behat\Behat\Context\Context; use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode; use Behat\Gherkin\Node\TableNode;
use JuliusHaertl\NextcloudBehat\Context\ServerContext;
use JuliusHaertl\NextcloudBehat\Context\SharingContext;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/autoload.php';
class BoardContext implements Context { class BoardContext implements Context {
use RequestTrait;
/** @var array Last board response */ /** @var array Last board response */
private $board = null; private $board = null;
@@ -19,12 +20,16 @@ class BoardContext implements Context {
/** @var ServerContext */ /** @var ServerContext */
private $serverContext; private $serverContext;
/** @var SharingContext */
private $sharingContext;
/** @BeforeScenario */ /** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope) { public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment(); $environment = $scope->getEnvironment();
$this->serverContext = $environment->getContext('ServerContext'); $this->serverContext = $environment->getContext(ServerContext::class);
$this->sharingContext = $environment->getContext(SharingContext::class);
} }
public function getLastUsedCard() { public function getLastUsedCard() {
@@ -35,21 +40,21 @@ class BoardContext implements Context {
* @Given /^creates a board named "([^"]*)" with color "([^"]*)"$/ * @Given /^creates a board named "([^"]*)" with color "([^"]*)"$/
*/ */
public function createsABoardNamedWithColor($title, $color) { public function createsABoardNamedWithColor($title, $color) {
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/boards', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/boards', [
'title' => $title, 'title' => $title,
'color' => $color 'color' => $color
]); ]);
$this->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->board = json_decode((string)$this->getResponse()->getBody(), true); $this->board = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
* @When /^fetches the board named "([^"]*)"$/ * @When /^fetches the board named "([^"]*)"$/
*/ */
public function fetchesTheBoardNamed($boardName) { public function fetchesTheBoardNamed($boardName) {
$this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $this->board['id'], []); $this->serverContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $this->board['id'], []);
$this->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->board = json_decode((string)$this->getResponse()->getBody(), true); $this->board = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
@@ -63,7 +68,7 @@ class BoardContext implements Context {
]; ];
$tableRows = isset($permissions) ? $permissions->getRowsHash() : []; $tableRows = isset($permissions) ? $permissions->getRowsHash() : [];
$result = array_merge($defaults, $tableRows); $result = array_merge($defaults, $tableRows);
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/boards/' . $this->board['id'] . '/acl', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/boards/' . $this->board['id'] . '/acl', [
'type' => 0, 'type' => 0,
'participant' => $user, 'participant' => $user,
'permissionEdit' => $result['permissionEdit'] === '1', 'permissionEdit' => $result['permissionEdit'] === '1',
@@ -83,7 +88,7 @@ class BoardContext implements Context {
]; ];
$tableRows = isset($permissions) ? $permissions->getRowsHash() : []; $tableRows = isset($permissions) ? $permissions->getRowsHash() : [];
$result = array_merge($defaults, $tableRows); $result = array_merge($defaults, $tableRows);
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/boards/' . $this->board['id'] . '/acl', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/boards/' . $this->board['id'] . '/acl', [
'type' => 1, 'type' => 1,
'participant' => $group, 'participant' => $group,
'permissionEdit' => $result['permissionEdit'] === '1', 'permissionEdit' => $result['permissionEdit'] === '1',
@@ -97,38 +102,38 @@ class BoardContext implements Context {
* @When /^fetching the board list$/ * @When /^fetching the board list$/
*/ */
public function fetchingTheBoardList() { public function fetchingTheBoardList() {
$this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards'); $this->serverContext->sendJSONrequest('GET', '/index.php/apps/deck/boards');
} }
/** /**
* @When /^fetching the board with id "([^"]*)"$/ * @When /^fetching the board with id "([^"]*)"$/
*/ */
public function fetchingTheBoardWithId($id) { public function fetchingTheBoardWithId($id) {
$this->requestContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $id); $this->serverContext->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $id);
} }
/** /**
* @Given /^create a stack named "([^"]*)"$/ * @Given /^create a stack named "([^"]*)"$/
*/ */
public function createAStackNamed($name) { public function createAStackNamed($name) {
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/stacks', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/stacks', [
'title' => $name, 'title' => $name,
'boardId' => $this->board['id'] 'boardId' => $this->board['id']
]); ]);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->stack = json_decode((string)$this->getResponse()->getBody(), true); $this->stack = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
* @Given /^create a card named "([^"]*)"$/ * @Given /^create a card named "([^"]*)"$/
*/ */
public function createACardNamed($name) { public function createACardNamed($name) {
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/cards', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/cards', [
'title' => $name, 'title' => $name,
'stackId' => $this->stack['id'] 'stackId' => $this->stack['id']
]); ]);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->card = json_decode((string)$this->getResponse()->getBody(), true); $this->card = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
@@ -164,31 +169,31 @@ class BoardContext implements Context {
['shareType', 12], ['shareType', 12],
['shareWith', (string)$this->card['id']], ['shareWith', (string)$this->card['id']],
]); ]);
$this->serverContext->creatingShare($table); $this->sharingContext->createAShareWith($table);
} }
/** /**
* @Given /^set the description to "([^"]*)"$/ * @Given /^set the description to "([^"]*)"$/
*/ */
public function setTheDescriptionTo($description) { public function setTheDescriptionTo($description) {
$this->requestContext->sendJSONrequest('PUT', '/index.php/apps/deck/cards/' . $this->card['id'], array_merge( $this->serverContext->sendJSONrequest('PUT', '/index.php/apps/deck/cards/' . $this->card['id'], array_merge(
$this->card, $this->card,
['description' => $description] ['description' => $description]
)); ));
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->card = json_decode((string)$this->getResponse()->getBody(), true); $this->card = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
* @Given /^set the card attribute "([^"]*)" to "([^"]*)"$/ * @Given /^set the card attribute "([^"]*)" to "([^"]*)"$/
*/ */
public function setCardAttribute($attribute, $value) { public function setCardAttribute($attribute, $value) {
$this->requestContext->sendJSONrequest('PUT', '/index.php/apps/deck/cards/' . $this->card['id'], array_merge( $this->serverContext->sendJSONrequest('PUT', '/index.php/apps/deck/cards/' . $this->card['id'], array_merge(
$this->card, $this->card,
[$attribute => $value] [$attribute => $value]
)); ));
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$this->card = json_decode((string)$this->getResponse()->getBody(), true); $this->card = json_decode((string)$this->serverContext->getResponse()->getBody(), true);
} }
/** /**
@@ -214,11 +219,11 @@ class BoardContext implements Context {
} }
private function assignToCard($participant, $type) { private function assignToCard($participant, $type) {
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/cards/' . $this->card['id'] .'/assign', [ $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/cards/' . $this->card['id'] .'/assign', [
'userId' => $participant, 'userId' => $participant,
'type' => $type 'type' => $type
]); ]);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
} }
/** /**
@@ -229,7 +234,7 @@ class BoardContext implements Context {
return $label['title'] === $tag; return $label['title'] === $tag;
}); });
$label = array_shift($filteredLabels); $label = array_shift($filteredLabels);
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/cards/' . $this->card['id'] .'/label/' . $label['id']); $this->serverContext->sendJSONrequest('POST', '/index.php/apps/deck/cards/' . $this->card['id'] .'/label/' . $label['id']);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
} }
} }

View File

@@ -2,12 +2,14 @@
use Behat\Behat\Context\Context; use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use JuliusHaertl\NextcloudBehat\Context\ServerContext;
require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/autoload.php';
class CommentContext implements Context { class CommentContext implements Context {
use RequestTrait;
/** @var ServerContext */
protected $serverContext;
/** @var BoardContext */ /** @var BoardContext */
protected $boardContext; protected $boardContext;
@@ -15,6 +17,7 @@ class CommentContext implements Context {
public function gatherContexts(BeforeScenarioScope $scope) { public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment(); $environment = $scope->getEnvironment();
$this->serverContext = $environment->getContext(ServerContext::class);
$this->boardContext = $environment->getContext('BoardContext'); $this->boardContext = $environment->getContext('BoardContext');
} }
@@ -23,7 +26,7 @@ class CommentContext implements Context {
*/ */
public function postACommentWithContentOnTheCard($content) { public function postACommentWithContentOnTheCard($content) {
$card = $this->boardContext->getLastUsedCard(); $card = $this->boardContext->getLastUsedCard();
$this->requestContext->sendOCSRequest('POST', '/apps/deck/api/v1.0/cards/' . $card['id'] . '/comments', [ $this->serverContext->sendOCSRequest('POST', '/apps/deck/api/v1.0/cards/' . $card['id'] . '/comments', [
'message' => $content, 'message' => $content,
'parentId' => null 'parentId' => null
]); ]);

View File

@@ -21,26 +21,21 @@
* *
*/ */
declare(strict_types=1);
use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Context\Context;
require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/autoload.php';
class PendingContext implements Context {
trait RequestTrait { /** @var \JuliusHaertl\NextcloudBehat\Context\ServerContext */
private $serverContext;
/** @var RequestContext */
protected $requestContext;
/** @BeforeScenario */ /** @BeforeScenario */
public function gatherRequestTraitContext(BeforeScenarioScope $scope) { public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment(); $environment = $scope->getEnvironment();
$this->requestContext = $environment->getContext('RequestContext');
$this->serverContext = $environment->getContext(\JuliusHaertl\NextcloudBehat\Context\ServerContext::class);
} }
public function getResponse() {
return $this->requestContext->getResponse();
}
} }

View File

@@ -1,140 +0,0 @@
<?php
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use PHPUnit\Framework\Assert;
use Behat\Behat\Context\Context;
use Psr\Http\Message\ResponseInterface;
require_once __DIR__ . '/../../vendor/autoload.php';
class RequestContext implements Context {
private $response;
/** @var ServerContext */
private $serverContext;
/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment();
$this->serverContext = $environment->getContext('ServerContext');
}
private function getBaseUrl() {
}
/**
* @Then the response should have a status code :code
* @param string $code
* @throws InvalidArgumentException
*/
public function theResponseShouldHaveStatusCode($code) {
$currentCode = $this->response->getStatusCode();
if ($currentCode !== (int)$code) {
throw new InvalidArgumentException(
sprintf(
'Expected %s as code got %s',
$code,
$currentCode
)
);
}
}
/**
* @Then /^the response Content-Type should be "([^"]*)"$/
* @param string $contentType
*/
public function theResponseContentTypeShouldbe($contentType) {
Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')[0]);
}
/**
* @Then the response should be a JSON array with the following mandatory values
* @param TableNode $table
* @throws InvalidArgumentException
*/
public function theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues(TableNode $table) {
$this->response->getBody()->seek(0);
$expectedValues = $table->getColumnsHash();
$realResponseArray = json_decode($this->response->getBody()->getContents(), true);
foreach ($expectedValues as $value) {
if ((string)$realResponseArray[$value['key']] !== (string)$value['value']) {
throw new InvalidArgumentException(
sprintf(
'Expected %s for key %s got %s',
(string)$value['value'],
$value['key'],
(string)$realResponseArray[$value['key']]
)
);
}
}
}
/**
* @Then the response should be a JSON array with a length of :length
* @param int $length
* @throws InvalidArgumentException
*/
public function theResponseShouldBeAJsonArrayWithALengthOf($length) {
$this->response->getBody()->seek(0);
$realResponseArray = json_decode($this->response->getBody()->getContents(), true);
if ((int)count($realResponseArray) !== (int)$length) {
throw new InvalidArgumentException(
sprintf(
'Expected %d as length got %d',
$length,
count($realResponseArray)
)
);
}
}
public function sendJSONrequest($method, $url, $data = []) {
$client = new Client;
try {
$this->response = $client->request(
$method,
rtrim($this->serverContext->getBaseUrl(), '/') . '/' . ltrim($url, '/'),
[
'cookies' => $this->serverContext->getCookieJar(),
'json' => $data,
'headers' => [
'requesttoken' => $this->serverContext->getReqestToken(),
]
]
);
} catch (ClientException $e) {
$this->response = $e->getResponse();
}
}
public function sendOCSRequest($method, $url, $data = []) {
$client = new Client;
try {
$this->response = $client->request(
$method,
rtrim($this->serverContext->getBaseUrl(), '/') . '/ocs/v2.php/' . ltrim($url, '/'),
[
'cookies' => $this->serverContext->getCookieJar(),
'json' => $data,
'headers' => [
'requesttoken' => $this->serverContext->getReqestToken(),
'OCS-APIREQUEST' => 'true',
'Accept' => 'application/json'
]
]
);
} catch (ClientException $e) {
$this->response = $e->getResponse();
}
}
public function getResponse(): ResponseInterface {
return $this->response;
}
}

View File

@@ -3,12 +3,14 @@
use Behat\Behat\Context\Context; use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use JuliusHaertl\NextcloudBehat\Context\ServerContext;
require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/autoload.php';
class SearchContext implements Context { class SearchContext implements Context {
use RequestTrait;
/** @var ServerContext */
protected $serverContext;
/** @var BoardContext */ /** @var BoardContext */
protected $boardContext; protected $boardContext;
@@ -19,6 +21,7 @@ class SearchContext implements Context {
public function gatherContexts(BeforeScenarioScope $scope) { public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment(); $environment = $scope->getEnvironment();
$this->serverContext = $environment->getContext(ServerContext::class);
$this->boardContext = $environment->getContext('BoardContext'); $this->boardContext = $environment->getContext('BoardContext');
} }
@@ -27,10 +30,10 @@ class SearchContext implements Context {
* @param string $term * @param string $term
*/ */
public function searchingFor(string $term) { public function searchingFor(string $term) {
$this->requestContext->sendOCSRequest('GET', '/apps/deck/api/v1.0/search?term=' . urlencode($term), []); $this->serverContext->sendOCSRequest('GET', '/apps/deck/api/v1.0/search?term=' . urlencode($term), []);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$data = (string)$this->getResponse()->getBody(); $data = (string)$this->serverContext->getResponse()->getBody();
$this->searchResults = json_decode($data, true); $this->searchResults = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} }
/** /**
@@ -39,9 +42,9 @@ class SearchContext implements Context {
* https://cloud.nextcloud.com/ocs/v2.php/search/providers/talk-conversations/search?term=an&from=%2Fapps%2Fdashboard%2F * https://cloud.nextcloud.com/ocs/v2.php/search/providers/talk-conversations/search?term=an&from=%2Fapps%2Fdashboard%2F
*/ */
public function searchingForComments(string $term) { public function searchingForComments(string $term) {
$this->requestContext->sendOCSRequest('GET', '/search/providers/deck-comment/search?term=' . urlencode($term), []); $this->serverContext->sendOCSRequest('GET', '/search/providers/deck-comment/search?term=' . urlencode($term), []);
$this->requestContext->getResponse()->getBody()->seek(0); $this->serverContext->getResponse()->getBody()->seek(0);
$data = (string)$this->getResponse()->getBody(); $data = (string)$this->serverContext->getResponse()->getBody();
$this->unifiedSearchResult = json_decode($data, true); $this->unifiedSearchResult = json_decode($data, true);
} }

View File

@@ -1,49 +0,0 @@
<?php
use Behat\Behat\Context\Context;
use GuzzleHttp\Cookie\CookieJar;
require_once __DIR__ . '/../../vendor/autoload.php';
class ServerContext implements Context {
use WebDav {
WebDav::__construct as private __tConstruct;
}
public function __construct($baseUrl) {
$this->rawBaseUrl = $baseUrl;
$this->__tConstruct($baseUrl . '/index.php/ocs/', ['admin', 'admin'], '123456');
}
/** @var string */
private $mappedUserId;
private $lastInsertIds = [];
/**
* @BeforeSuite
*/
public static function addFilesToSkeleton() {
}
/**
* @Given /^acting as user "([^"]*)"$/
*/
public function actingAsUser($user) {
$this->cookieJar = new CookieJar();
$this->loggingInUsingWebAs($user);
$this->asAn($user);
}
public function getBaseUrl(): string {
return $this->rawBaseUrl;
}
public function getCookieJar(): CookieJar {
return $this->cookieJar;
}
public function getReqestToken(): string {
return $this->requestToken;
}
}

View File

@@ -5,10 +5,10 @@ Feature: decks
Given user "user0" exists Given user "user0" exists
Scenario: Create a new board Scenario: Create a new board
Given Logging in using web as "admin" Given Using web as user "admin"
When creates a board named "MyBoard" with color "000000" When creates a board named "MyBoard" with color "000000"
Then the response should have a status code "200" Then the HTTP status code should be "200"
And the response Content-Type should be "application/json; charset=utf-8" And the Content-Type should be "application/json; charset=utf-8"
And the response should be a JSON array with the following mandatory values And the response should be a JSON array with the following mandatory values
|key|value| |key|value|
|title|MyBoard| |title|MyBoard|

View File

@@ -3,7 +3,7 @@ Feature: Searching for cards
Background: Background:
Given user "admin" exists Given user "admin" exists
Given user "user0" exists Given user "user0" exists
Given Logging in using web as "admin" Given Using web as user "admin"
When creates a board named "MyBoard" with color "000000" When creates a board named "MyBoard" with color "000000"
When create a stack named "ToDo" When create a stack named "ToDo"
And create a card named "Example task 1" And create a card named "Example task 1"
@@ -83,7 +83,7 @@ Feature: Searching for cards
Then the card "Done task 2" is not found Then the card "Done task 2" is not found
Scenario: Search on shared boards Scenario: Search on shared boards
Given Logging in using web as "user0" Given Using web as user "user0"
When searching for "task" When searching for "task"
Then the card "Example task 1" is found Then the card "Example task 1" is found
Then the card "Example task 2" is found Then the card "Example task 2" is found

View File

@@ -19,12 +19,11 @@ Feature: File sharing
And shares the board with user "user1" And shares the board with user "user1"
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path
When User "user0" uploads file "../data/test.txt" to "/user0-file.txt" When User "user0" uploads file "../data/test.txt" to "/user0-file.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user0" Given acting as user "user0"
When share the file "/user0-file.txt" with the card When share the file "/user0-file.txt" with the card
Then the OCS status code should be "100" Then the OCS status code should be "200"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And as "user1" the file "/Deck/user0-file.txt" exists And as "user1" the file "/Deck/user0-file.txt" exists
@@ -40,12 +39,11 @@ Feature: File sharing
| permissionManage | 1 | | permissionManage | 1 |
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path
When User "user1" uploads file "../data/test.txt" to "/user1-file.txt" When User "user1" uploads file "../data/test.txt" to "/user1-file.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user1" Given acting as user "user1"
And share the file "/user1-file.txt" with the card And share the file "/user1-file.txt" with the card
Then the OCS status code should be "100" Then the OCS status code should be "200"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And as "user0" the file "/Deck/user1-file.txt" exists And as "user0" the file "/Deck/user1-file.txt" exists
@@ -59,13 +57,11 @@ Feature: File sharing
And shares the board with user "user1" And shares the board with user "user1"
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path Given acting as user "user1"
When User "user1" uploads file "../data/test.txt" to "/user1-file.txt" When User "user1" uploads file "../data/test.txt" to "/user1-file.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user1" When share the file "/user1-file.txt" with the card
And share the file "/user1-file.txt" with the card
Then the OCS status code should be "404" Then the OCS status code should be "404"
And the HTTP status code should be "200"
And as "user0" the file "/Deck/user1-file.txt" does not exist And as "user0" the file "/Deck/user1-file.txt" does not exist
Scenario: Share a file with a card by another user through a group Scenario: Share a file with a card by another user through a group
@@ -76,12 +72,11 @@ Feature: File sharing
And shares the board with group "group1" And shares the board with group "group1"
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path
When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt" When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user0" Given acting as user "user0"
When share the file "/user0-file2.txt" with the card When share the file "/user0-file2.txt" with the card
Then the OCS status code should be "100" Then the OCS status code should be "200"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And as "user2" the file "/Deck/user0-file2.txt" exists And as "user2" the file "/Deck/user0-file2.txt" exists
@@ -95,12 +90,11 @@ Feature: File sharing
And shares the board with group "group1" And shares the board with group "group1"
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path
When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt" When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user0" Given acting as user "user0"
When share the file "/user0-file2.txt" with the card When share the file "/user0-file2.txt" with the card
Then the OCS status code should be "100" Then the OCS status code should be "200"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And as "user2" the file "/Deck/user0-file2.txt" exists And as "user2" the file "/Deck/user0-file2.txt" exists
@@ -119,12 +113,11 @@ Feature: File sharing
And shares the board with group "group1" And shares the board with group "group1"
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
Given using new dav path
When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt" When User "user0" uploads file "../data/test.txt" to "/user0-file2.txt"
Then the HTTP status code should be "201" Then the HTTP status code should be "201"
Given acting as user "user0" Given acting as user "user0"
When share the file "/user0-file2.txt" with the card When share the file "/user0-file2.txt" with the card
Then the OCS status code should be "100" Then the OCS status code should be "200"
And the HTTP status code should be "200" And the HTTP status code should be "200"
And as "user2" the file "/Deck/user0-file2.txt" exists And as "user2" the file "/Deck/user0-file2.txt" exists

View File

@@ -5,11 +5,6 @@ OCC=${OC_PATH}occ
SCENARIO_TO_RUN=$1 SCENARIO_TO_RUN=$1
HIDE_OC_LOGS=$2 HIDE_OC_LOGS=$2
# Nextcloud integration tests composer
(
cd ${OC_PATH}build/integration
composer install
)
INSTALLED=$($OCC status | grep installed: | cut -d " " -f 5) INSTALLED=$($OCC status | grep installed: | cut -d " " -f 5)
if [ "$INSTALLED" == "true" ]; then if [ "$INSTALLED" == "true" ]; then
@@ -24,11 +19,11 @@ composer dump-autoload
# avoid port collision on jenkins - use $EXECUTOR_NUMBER # avoid port collision on jenkins - use $EXECUTOR_NUMBER
if [ -z "$EXECUTOR_NUMBER" ]; then if [ -z "$EXECUTOR_NUMBER" ]; then
EXECUTOR_NUMBER=0 EXECUTOR_NUMBER=1
fi fi
PORT=$((8080 + $EXECUTOR_NUMBER)) PORT=$((8080 + $EXECUTOR_NUMBER))
echo $PORT echo $PORT
php -S localhost:$PORT -t $OC_PATH & PHP_CLI_SERVER_WORKERS=10 php -S localhost:$PORT -t $OC_PATH &
PHPPID=$! PHPPID=$!
echo $PHPPID echo $PHPPID