Add acceptance tests related to access levels

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-04-04 17:24:30 +02:00
parent 1203369ea6
commit c4613733eb
2 changed files with 70 additions and 3 deletions

View File

@ -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

View File

@ -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) {
}
}
}