Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-10-31 13:46:29 +0300
committerJulius Härtl <jus@bitgrid.net>2022-10-31 14:48:50 +0300
commit39c59a3bd60c45e75482760c6eadff39591b15af (patch)
tree9c4b66c66336b8dfa548ba051f9128a07e6952ed
parentf35a9d08e538958a78929526e4ea4b7fdd7f6444 (diff)
Add integration test for attachment handling on cards
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--tests/integration/config/behat.yml1
-rw-r--r--tests/integration/features/bootstrap/AttachmentContext.php89
-rw-r--r--tests/integration/features/bootstrap/BoardContext.php21
-rw-r--r--tests/integration/features/bootstrap/RequestContext.php29
-rw-r--r--tests/integration/features/bootstrap/ServerContext.php1
-rw-r--r--tests/integration/features/sharing.feature28
6 files changed, 169 insertions, 0 deletions
diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml
index b8673a67..6ef85a65 100644
--- a/tests/integration/config/behat.yml
+++ b/tests/integration/config/behat.yml
@@ -9,4 +9,5 @@ default:
- RequestContext
- BoardContext
- CommentContext
+ - AttachmentContext
- SearchContext
diff --git a/tests/integration/features/bootstrap/AttachmentContext.php b/tests/integration/features/bootstrap/AttachmentContext.php
new file mode 100644
index 00000000..38172075
--- /dev/null
+++ b/tests/integration/features/bootstrap/AttachmentContext.php
@@ -0,0 +1,89 @@
+<?php
+
+use Behat\Behat\Context\Context;
+use Behat\Behat\Hook\Scope\BeforeScenarioScope;
+use PHPUnit\Framework\Assert;
+
+require_once __DIR__ . '/../../vendor/autoload.php';
+
+class AttachmentContext implements Context {
+ use RequestTrait;
+
+ /** @var BoardContext */
+ protected $boardContext;
+ /** @var ServerContext */
+ private $serverContext;
+
+ protected $lastAttachment = null;
+ protected array $rememberedAttachments = [];
+
+ /** @BeforeScenario */
+ public function gatherContexts(BeforeScenarioScope $scope) {
+ $environment = $scope->getEnvironment();
+
+ $this->boardContext = $environment->getContext('BoardContext');
+ $this->serverContext = $environment->getContext('ServerContext');
+ }
+
+ public function delete(int $cardId, int $attachmentId) {
+ $this->requestContext->sendPlainRequest('DELETE', '/index.php/apps/deck/cards/' . $cardId . '/attachment/file:' . $attachmentId);
+ $response = $this->requestContext->getResponseBodyFromJson();
+ }
+
+ /**
+ * @When deleting the attachment :attachmentReference for the card :cardReference
+ */
+ public function deletingTheAttachmentForTheCard($attachmentReference, $cardReference) {
+ $cardId = $this->boardContext->getRememberedCard($cardReference)['id'] ?? null;
+ $attachmentId = $this->getRememberedAttachment($attachmentReference)['id'] ?? null;
+ Assert::assertNotNull($cardId, 'Card needs to be available');
+ Assert::assertNotNull($attachmentId, 'Attachment needs to be available');
+ $this->delete($cardId, $attachmentId);
+ }
+
+ /**
+ * @Given /^uploads an attachment to the last used card$/
+ */
+ public function uploadsAnAttachmentToTheLastUsedCard() {
+ $cardId = $this->boardContext->getLastUsedCard()['id'] ?? null;
+ Assert::assertNotNull($cardId, 'Card data is not set');
+
+ $this->requestContext->sendPlainRequest('POST', '/index.php/apps/deck/cards/' . $cardId . '/attachment', [
+ 'multipart' => [
+ [
+ 'name' => 'file',
+ 'contents' => 'Example content',
+ 'filename' => 'test.txt',
+ ],
+ [
+ 'name' => 'type',
+ 'contents' => 'file'
+ ]
+ ]
+ ]);
+ }
+
+ /**
+ * @Given remember the last attachment as :arg1
+ */
+ public function rememberTheLastAttachmentAs($arg1) {
+ $this->lastAttachment = $this->requestContext->getResponseBodyFromJson();
+ $this->rememberedAttachments[$arg1] = $this->lastAttachment;
+ }
+
+ public function getRememberedAttachment($name) {
+ return $this->rememberedAttachments[$name] ?? null;
+ }
+
+ /**
+ * @When fetching the attachment :attachmentReference for the card :cardReference
+ */
+ public function fetchingTheAttachmentForTheCard($attachmentReference, $cardReference) {
+ $cardId = $this->boardContext->getRememberedCard($cardReference)['id'] ?? null;
+ $attachmentId = $this->getRememberedAttachment($attachmentReference)['id'] ?? null;
+ Assert::assertNotNull($cardId, 'Card needs to be available');
+ Assert::assertNotNull($attachmentId, 'Attachment needs to be available');
+
+ $this->requestContext->sendPlainRequest('GET', '/index.php/apps/deck/cards/' . $cardId . '/attachment/file:' . $attachmentId);
+ }
+}
diff --git a/tests/integration/features/bootstrap/BoardContext.php b/tests/integration/features/bootstrap/BoardContext.php
index fb412063..420a7d41 100644
--- a/tests/integration/features/bootstrap/BoardContext.php
+++ b/tests/integration/features/bootstrap/BoardContext.php
@@ -16,6 +16,7 @@ class BoardContext implements Context {
private $stack = null;
/** @var array last card response */
private $card = null;
+ private array $storedCards = [];
/** @var ServerContext */
private $serverContext;
@@ -32,6 +33,15 @@ class BoardContext implements Context {
}
/**
+ * @Given /^creates a board with example content$/
+ */
+ public function createExampleContent() {
+ $this->createsABoardNamedWithColor('Example board', 'ff0000');
+ $this->createAStackNamed('ToDo');
+ $this->createACardNamed('My example card');
+ }
+
+ /**
* @Given /^creates a board named "([^"]*)" with color "([^"]*)"$/
*/
public function createsABoardNamedWithColor($title, $color) {
@@ -232,4 +242,15 @@ class BoardContext implements Context {
$this->requestContext->sendJSONrequest('POST', '/index.php/apps/deck/cards/' . $this->card['id'] .'/label/' . $label['id']);
$this->requestContext->getResponse()->getBody()->seek(0);
}
+
+ /**
+ * @When remember the last card as :arg1
+ */
+ public function rememberTheLastCardAs($arg1) {
+ $this->storedCards[$arg1] = $this->getLastUsedCard();
+ }
+
+ public function getRememberedCard($arg1) {
+ return $this->storedCards[$arg1] ?? null;
+ }
}
diff --git a/tests/integration/features/bootstrap/RequestContext.php b/tests/integration/features/bootstrap/RequestContext.php
index f3aedc8d..9df6be20 100644
--- a/tests/integration/features/bootstrap/RequestContext.php
+++ b/tests/integration/features/bootstrap/RequestContext.php
@@ -134,7 +134,36 @@ class RequestContext implements Context {
}
}
+ public function sendPlainRequest(string $method, $uri = '', array $options = []) {
+ $client = new Client;
+ try {
+ $this->response = $client->request(
+ $method,
+ rtrim($this->serverContext->getBaseUrl(), '/') . '/' . ltrim($uri, '/'),
+ array_merge(
+ [
+ 'cookies' => $this->serverContext->getCookieJar(),
+ 'headers' => [
+ 'requesttoken' => $this->serverContext->getReqestToken(),
+ 'OCS-APIREQUEST' => 'true',
+ 'Accept' => 'application/json'
+ ]
+ ],
+ $options,
+ )
+ );
+ } catch (ClientException $e) {
+ $this->response = $e->getResponse();
+ }
+ }
+
+
public function getResponse(): ResponseInterface {
return $this->response;
}
+
+ public function getResponseBodyFromJson() {
+ $this->getResponse()->getBody()->seek(0);
+ return json_decode((string)$this->getResponse()->getBody(), true);
+ }
}
diff --git a/tests/integration/features/bootstrap/ServerContext.php b/tests/integration/features/bootstrap/ServerContext.php
index e4ed567f..87b068ec 100644
--- a/tests/integration/features/bootstrap/ServerContext.php
+++ b/tests/integration/features/bootstrap/ServerContext.php
@@ -40,6 +40,7 @@ class ServerContext implements Context {
}
public function getCookieJar(): CookieJar {
+ echo $this->currentUser;
return $this->cookieJar;
}
diff --git a/tests/integration/features/sharing.feature b/tests/integration/features/sharing.feature
index c99688bd..56baaf38 100644
--- a/tests/integration/features/sharing.feature
+++ b/tests/integration/features/sharing.feature
@@ -135,3 +135,31 @@ Feature: File sharing
When Deleting last share
And as "user2" the file "/Deck/user0-file2.txt" does not exist
And as "user3" the file "/Deck/user0-file2.txt" does not exist
+
+ Scenario: Remove a share through the deck API
+ Given acting as user "user0"
+ When creates a board with example content
+ And remember the last card as "user0-card"
+ And uploads an attachment to the last used card
+ And remember the last attachment as "user0-attachment"
+
+ Given acting as user "user1"
+ When creates a board with example content
+ And remember the last card as "user1-card"
+ And uploads an attachment to the last used card
+ And remember the last attachment as "user1-attachment"
+
+ Given acting as user "user0"
+ When fetching the attachment "user1-attachment" for the card "user0-card"
+ Then the response should have a status code 403
+ When deleting the attachment "user1-attachment" for the card "user0-card"
+ Then the response should have a status code 403
+
+ When fetching the attachment "user0-attachment" for the card "user0-card"
+ Then the response should have a status code 200
+ When deleting the attachment "user0-attachment" for the card "user0-card"
+ Then the response should have a status code 200
+
+ Given acting as user "user1"
+ When deleting the attachment "user1-attachment" for the card "user1-card"
+ Then the response should have a status code 200