Created
March 26, 2012 23:24
-
-
Save sayak-sarkar/2210590 to your computer and use it in GitHub Desktop.
BDD for SilverStripe sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# features/log-in.feature | |
Feature: Create a page | |
As an site owner | |
I want to access to the CMS to be secure | |
So that only my team can make content changes | |
Scenario: Bad login | |
When I log in with "[email protected]" and "badpassword" | |
Then I will see a bad log-in message | |
And if I visit admin | |
Then I will be redirected to Security/login | |
# features/step_definitions/CMSSteps.php | |
# Incomplete, and custom base class (WebDriverSteps) contains more functionality | |
<?php | |
/** | |
* Steps relating the to the general behavior of the CMS | |
*/ | |
class CMSSteps extends WebDriverSteps { | |
/** | |
* Given /^I am logged into the CMS$/ | |
**/ | |
public function stepIAmLoggedIntoTheCMS() { | |
$this->stepILogInWith('[email protected]', 'password'); | |
$this->natural->visit("admin"); | |
} | |
/** | |
* When /^I log in with "([^"]*)" and "([^"]*)"$/ | |
**/ | |
public function stepILogInWith($email,$password) { | |
$this->session->open($this->site->baseURL() . "Security/login"); | |
$this->natural->visit("Security/login"); | |
$this->natural->field("Email")->setTo($email); | |
$this->natural->field("Password")->setTo($password); | |
$this->natural->button("Log in")->click(); | |
} | |
/** | |
* Then /^I will see a bad log\-in message$/ | |
**/ | |
public function stepIWillSeeABadLogInMessage() { | |
$this->assertTrue($this->natural->textIsVisible("That doesn't seem to be the right e-mail address or password")); | |
} | |
/** | |
* When /^I click "([^"]*)" in the CMS menu$/ | |
**/ | |
public function stepIClickParameterInTheCMSMenu($menuItem) { | |
$el = $this->natural->panel('#cms-menu')->link($menuItem); | |
$el->click(); | |
sleep(1); | |
} | |
/** | |
* When /^I toggle "([^"]*)" in the CMS menu$/ | |
**/ | |
public function stepIToggleParameterInTheCMSMenu($menuItem) { | |
$el = $this->natural->panel('#cms-menu')->link($menuItem); | |
if(!$el) throw new LogicException("Couldn't find '$menuItem' in the CMS tree."); | |
$el->wd()->element('css selector', '.toggle-children')->click(); | |
sleep(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment