|
| 1 | +<?php |
| 2 | + |
| 3 | +use Behat\Behat\Context\Context; |
| 4 | +use Behat\Gherkin\Node\TableNode; |
| 5 | +use GuzzleHttp\Client; |
| 6 | +use Behat\Gherkin\Node\PyStringNode; |
| 7 | +use GuzzleHttp\Exception\ClientException; |
| 8 | +use PHPUnit\Framework\Assert; |
| 9 | + |
| 10 | +require_once __DIR__ . '/../../vendor/autoload.php'; |
| 11 | + |
| 12 | +class BoardContext implements Context { |
| 13 | + use RequestTrait; |
| 14 | + |
| 15 | + /** @var array Last board response */ |
| 16 | + private $board = null; |
| 17 | + /** @var array last stack response */ |
| 18 | + private $stack = null; |
| 19 | + /** @var array last card response */ |
| 20 | + private $card = null; |
| 21 | + |
| 22 | + /** |
| 23 | + * @Given /^creates a board named "([^"]*)" with color "([^"]*)"$/ |
| 24 | + */ |
| 25 | + public function createsABoardNamedWithColor($title, $color) { |
| 26 | + $this->sendJSONrequest('POST', '/index.php/apps/deck/boards', [ |
| 27 | + 'title' => $title, |
| 28 | + 'color' => $color |
| 29 | + ]); |
| 30 | + $this->response->getBody()->seek(0); |
| 31 | + $this->board = json_decode((string)$this->response->getBody(), true); |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @When /^fetches the board named "([^"]*)"$/ |
| 37 | + */ |
| 38 | + public function fetchesTheBoardNamed($boardName) { |
| 39 | + $this->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $this->board['id'], []); |
| 40 | + $this->response->getBody()->seek(0); |
| 41 | + $this->board = json_decode((string)$this->response->getBody(), true); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @When shares the board with user :user |
| 46 | + */ |
| 47 | + public function sharesTheBoardWithUser($user) |
| 48 | + { |
| 49 | + $this->sendJSONrequest('POST', '/index.php/apps/deck/boards/' . $this->board['id'] . '/acl', [ |
| 50 | + 'type' => 0, |
| 51 | + 'participant' => $user, |
| 52 | + 'permissionEdit' => true, |
| 53 | + 'permissionShare' => true, |
| 54 | + 'permissionManage' => true, |
| 55 | + ]); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + /** |
| 60 | + * @When /^fetching the board list$/ |
| 61 | + */ |
| 62 | + public function fetchingTheBoardList() { |
| 63 | + $this->sendJSONrequest('GET', '/index.php/apps/deck/boards'); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @When /^fetching the board with id "([^"]*)"$/ |
| 68 | + */ |
| 69 | + public function fetchingTheBoardWithId($id) { |
| 70 | + $this->sendJSONrequest('GET', '/index.php/apps/deck/boards/' . $id); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @Given /^create a stack named "([^"]*)"$/ |
| 75 | + */ |
| 76 | + public function createAStackNamed($name) { |
| 77 | + $this->sendJSONrequest('POST', '/index.php/apps/deck/stacks', [ |
| 78 | + 'title' => $name, |
| 79 | + 'boardId' => $this->board['id'] |
| 80 | + ]); |
| 81 | + $this->response->getBody()->seek(0); |
| 82 | + $this->stack = json_decode((string)$this->response->getBody(), true); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @Given /^create a card named "([^"]*)"$/ |
| 87 | + */ |
| 88 | + public function createACardNamed($name) { |
| 89 | + $this->sendJSONrequest('POST', '/index.php/apps/deck/cards', [ |
| 90 | + 'title' => $name, |
| 91 | + 'stackId' => $this->stack['id'] |
| 92 | + ]); |
| 93 | + $this->response->getBody()->seek(0); |
| 94 | + $this->card = json_decode((string)$this->response->getBody(), true); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @Given /^the current user should have read permissions on the board$/ |
| 99 | + */ |
| 100 | + public function theCurrentUserShouldHaveReadPermissionsOnTheBoard() { |
| 101 | + Assert::assertTrue($this->board['permissions']['PERMISSION_READ']); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @Given /^the current user should have write permissions on the board$/ |
| 106 | + */ |
| 107 | + public function theCurrentUserShouldHaveWritePermissionsOnTheBoard() { |
| 108 | + Assert::assertTrue($this->board['permissions']['PERMISSION_EDIT']); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @Given /^the current user should have share permissions on the board$/ |
| 113 | + */ |
| 114 | + public function theCurrentUserShouldHaveSharePermissionsOnTheBoard() { |
| 115 | + Assert::assertTrue($this->board['permissions']['PERMISSION_SHARE']); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @Given /^the current user should have manage permissions on the board$/ |
| 120 | + */ |
| 121 | + public function theCurrentUserShouldHaveManagePermissionsOnTheBoard() { |
| 122 | + Assert::assertTrue($this->board['permissions']['PERMISSION_MANAGE']); |
| 123 | + } |
| 124 | + |
| 125 | +} |
0 commit comments