From a2ef5a88e62f6b2b26092d755832df629e761911 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Dec 2015 11:46:06 +0100 Subject: Add integration tests for deleting a notification --- .../features/bootstrap/FeatureContext.php | 71 +++++++++++++++++++++- .../features/delete-notifications.feature | 23 +++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/integration/features/delete-notifications.feature (limited to 'tests') diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 66576ce..948aba2 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -13,11 +13,19 @@ use GuzzleHttp\Message\ResponseInterface; */ class FeatureContext implements Context, SnippetAcceptingContext { + /** @var array[] */ + protected $notificationIds; + + /** @var int */ + protected $deletedNotification; + use BasicStructure; use Provisioning; /** * @Given /^list of notifiers (is|is not) empty$/ + * + * @param string $noNotifiers */ public function hasNotifiers($noNotifiers) { if ($noNotifiers === 'is') { @@ -33,6 +41,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { /** * @Given /^user "([^"]*)" has notifications$/ + * + * @param string $user */ public function hasNotifications($user) { if ($user === 'test1') { @@ -44,10 +54,69 @@ class FeatureContext implements Context, SnippetAcceptingContext { /** * @Then /^list of notifications has (\d+) entries$/ + * + * @param int $numNotifications */ public function checkNumNotifications($numNotifications) { $notifications = $this->getArrayOfNotificationsResponded($this->response); PHPUnit_Framework_Assert::assertCount((int) $numNotifications, $notifications); + + $notificationIds = []; + foreach ($notifications as $notification) { + $notificationIds[] = (int) $notification['notification_id']; + } + + $this->notificationIds[] = $notificationIds; + } + + /** + * @Then /^user "([^"]*)" has (\d+) notifications(| missing the last one| missing the first one)$/ + * + * @param string $user + * @param int $numNotifications + * @param string $missingLast + */ + public function userNumNotifications($user, $numNotifications, $missingLast) { + if ($user === 'test1') { + $this->sendingTo('GET', '/apps/notifications/api/v1/notifications?format=json'); + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + + $previousNotificationIds = []; + if ($missingLast) { + PHPUnit_Framework_Assert::assertNotEmpty($this->notificationIds); + $previousNotificationIds = end($this->notificationIds); + } + + $this->checkNumNotifications((int) $numNotifications); + + if ($missingLast) { + $now = end($this->notificationIds); + if ($missingLast === ' missing the last one') { + array_unshift($now, $this->deletedNotification); + } else { + $now[] = $this->deletedNotification; + } + + PHPUnit_Framework_Assert::assertEquals($previousNotificationIds, $now); + } + + } + } + + /** + * @Then /^delete (first|last) notification$/ + * + * @param string $firstOrLast + */ + public function deleteNotification($firstOrLast) { + PHPUnit_Framework_Assert::assertNotEmpty($this->notificationIds); + $lastNotificationIds = end($this->notificationIds); + if ($firstOrLast === 'first') { + $this->deletedNotification = end($lastNotificationIds); + } else { + $this->deletedNotification = reset($lastNotificationIds); + } + $this->sendingTo('DELETE', '/apps/notifications/api/v1/notifications/' . $this->deletedNotification); } /** @@ -55,7 +124,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param ResponseInterface $resp * @return array */ - public function getArrayOfNotificationsResponded($resp) { + public function getArrayOfNotificationsResponded(ResponseInterface $resp) { $jsonResponse = json_decode($resp->getBody()->getContents(), 1); return $jsonResponse['ocs']['data']; } diff --git a/tests/integration/features/delete-notifications.feature b/tests/integration/features/delete-notifications.feature new file mode 100644 index 0000000..679e748 --- /dev/null +++ b/tests/integration/features/delete-notifications.feature @@ -0,0 +1,23 @@ +Feature: delete-notifications + Background: + Given using api version "2" + Given user "test1" exists + Given As an "test1" + + Scenario: Delete first notification + Given list of notifiers is not empty + Given user "test1" has notifications + Given user "test1" has notifications + Given user "test1" has notifications + Then user "test1" has 3 notifications + And delete first notification + And user "test1" has 2 notifications missing the first one + + Scenario: Delete last notification + Given list of notifiers is not empty + Given user "test1" has notifications + Given user "test1" has notifications + Given user "test1" has notifications + Then user "test1" has 3 notifications + And delete last notification + And user "test1" has 2 notifications missing the last one -- cgit v1.2.3