Behat/Drupal Workshop

Behavior-Driven Development for Drupal with Behat

Building Websites

Implement your website according to spec.

Case Study: ITS Website Migration

Approach

  1. Cover the D6 site with feature tests
  2. Rebuild the site in D7
  3. Migrate content over
  4. Run the same feature tests against D7 site
  5. Success!

What To Test

Hands-on Demo

  1. Follow the install instructions
    • Skip the steps for setting up PhantomJS
    • Composer installation instructions for Windows, Mac and Linux
  2. Grab the code from the GitHub repo
  3. Run the tests in the web-browser

Questions? Problems?

Let's take it apart...

Configuration

Implementation

Features

Step Definitions

<?php
    /**
     * @Then /^I should see (\d+) image-links in the "([^"]*)" region$/
     */
    public function iShouldSeeImageLinksInTheRegion($num, $region) {
        $regionObj = $this->getRegion($region);
        if (! $regionObj) {
            throw new \Exception(sprintf('Region "%s" on the page %s does not exist.', $region, $this->getSession()->getCurrentUrl()));
        }
        $regionId = $regionObj->getAttribute('id');
        $this->assertNumElements((int) $num, "#{$regionId} a > img");
    }

Learn More