From c4613733eb4076f6e641e27e953365feb88e98ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Tue, 4 Apr 2017 17:24:30 +0200 Subject: [PATCH] Add acceptance tests related to access levels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../acceptance/features/access-levels.feature | 21 ++++++++ .../bootstrap/SettingsMenuContext.php | 52 +++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 build/acceptance/features/access-levels.feature diff --git a/build/acceptance/features/access-levels.feature b/build/acceptance/features/access-levels.feature new file mode 100644 index 0000000000..57998899a5 --- /dev/null +++ b/build/acceptance/features/access-levels.feature @@ -0,0 +1,21 @@ +Feature: access-levels + + Scenario: regular users can not see admin-level items in the Settings menu + Given I am logged in + When I open the Settings menu + Then I see that the Settings menu is shown + And I see that the "Personal" item in the Settings menu is shown + And I see that the "Admin" item in the Settings menu is not shown + And I see that the "Users" item in the Settings menu is not shown + And I see that the "Help" item in the Settings menu is shown + And I see that the "Log out" item in the Settings menu is shown + + Scenario: admin users can see admin-level items in the Settings menu + Given I am logged in as the admin + When I open the Settings menu + Then I see that the Settings menu is shown + And I see that the "Personal" item in the Settings menu is shown + And I see that the "Admin" item in the Settings menu is shown + And I see that the "Users" item in the Settings menu is shown + And I see that the "Help" item in the Settings menu is shown + And I see that the "Log out" item in the Settings menu is shown diff --git a/build/acceptance/features/bootstrap/SettingsMenuContext.php b/build/acceptance/features/bootstrap/SettingsMenuContext.php index 78a29b08a1..9ce8df4cae 100644 --- a/build/acceptance/features/bootstrap/SettingsMenuContext.php +++ b/build/acceptance/features/bootstrap/SettingsMenuContext.php @@ -35,6 +35,14 @@ class SettingsMenuContext implements Context, ActorAwareInterface { describedAs("Settings menu button"); } + /** + * @return Locator + */ + public static function settingsMenu() { + return Locator::forThe()->id("expanddiv")->descendantOf(self::settingsMenuButton())-> + describedAs("Settings menu"); + } + /** * @return Locator */ @@ -53,15 +61,23 @@ class SettingsMenuContext implements Context, ActorAwareInterface { * @return Locator */ private static function menuItemFor($itemText) { - return Locator::forThe()->content($itemText)->descendantOf(self::settingsMenuButton())-> + return Locator::forThe()->content($itemText)->descendantOf(self::settingsMenu())-> describedAs($itemText . " item in Settings menu"); } + /** + * @When I open the Settings menu + */ + public function iOpenTheSettingsMenu() { + $this->actor->find(self::settingsMenuButton(), 10)->click(); + } + /** * @When I open the User settings */ public function iOpenTheUserSettings() { - $this->actor->find(self::settingsMenuButton(), 10)->click(); + $this->iOpenTheSettingsMenu(); + $this->actor->find(self::usersMenuItem(), 2)->click(); } @@ -69,8 +85,38 @@ class SettingsMenuContext implements Context, ActorAwareInterface { * @When I log out */ public function iLogOut() { - $this->actor->find(self::settingsMenuButton(), 10)->click(); + $this->iOpenTheSettingsMenu(); + $this->actor->find(self::logOutMenuItem(), 2)->click(); } + /** + * @Then I see that the Settings menu is shown + */ + public function iSeeThatTheSettingsMenuIsShown() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::settingsMenu(), 10)->isVisible()); + } + + /** + * @Then I see that the :itemText item in the Settings menu is shown + */ + public function iSeeThatTheItemInTheSettingsMenuIsShown($itemText) { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::menuItemFor($itemText), 10)->isVisible()); + } + + /** + * @Then I see that the :itemText item in the Settings menu is not shown + */ + public function iSeeThatTheItemInTheSettingsMenuIsNotShown($itemText) { + $this->iSeeThatTheSettingsMenuIsShown(); + + try { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::menuItemFor($itemText))->isVisible()); + } catch (NoSuchElementException $exception) { + } + } + }