Skip to content

Instantly share code, notes, and snippets.

@anselmdk
Last active May 24, 2016 04:08
Show Gist options
  • Save anselmdk/ee38e089080e3c0b4b88 to your computer and use it in GitHub Desktop.
Save anselmdk/ee38e089080e3c0b4b88 to your computer and use it in GitHub Desktop.
Behat tests for SilverStripe modules

Behat tests on SilverStripe modules

setup for modules

Create the following structure:

mymodule
  tests
    behat
      mymodule.feature
      bootstrap
        FeatureContext.php

setup for execution

Read instructions here: https://github.com/silverstripe-labs/silverstripe-behat-extension

Prerequisites

  • In order to run behat tests you need to have either phantomjs or selenium running locally.
  • Also make sure you've got $_FILE_TO_URL_MAPPING set up in your _ss_environment.php file.

Selenium

OSX

brew update
brew install selenium-server-standalone
brew upgrade selenium-server-standalone

Additionally you'll need the Chrome Driver. Download it from https://sites.google.com/a/chromium.org/chromedriver/downloads and move it your bin directory, e.g. mv chromedriver /usr/local/bin

Linux

Download latest selenium server from http://www.seleniumhq.org/download/

java -jar selenium-server-standalone-2.44.0.jar

PhantomJS

OSX

brew update
brew install phantomjs

Linux

./phantomjs --webdriver=4444

<?php
namespace SilverStripe\Mysite\Test\Behaviour;
use SilverStripe\Cms\Test\Behaviour;
// PHPUnit
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
/**
* Features context
*
* Context automatically loaded by Behat.
* Uses subcontexts to extend functionality.
*/
class FeatureContext extends \SilverStripe\Cms\Test\Behaviour\FeatureContext
{
/**
* Initializes context.
* Every scenario gets it's own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
//make sure that the CMS is loaded in English for non-english sites
\i18n::set_locale('en_US');
parent::__construct($parameters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment