Skip to content

Instantly share code, notes, and snippets.

@sayak-sarkar
Created March 26, 2012 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayak-sarkar/2210590 to your computer and use it in GitHub Desktop.
Save sayak-sarkar/2210590 to your computer and use it in GitHub Desktop.
BDD for SilverStripe sample
# 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 "bad@example.com" 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('sam@silverstripe.com', '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