automation in drupal
DESCRIPTION
In this session we will cover as much as possible the following topics: - Quick intro to TDD (Test-Driven Development) and BDD (Behavior-Driven Development) - Gherkin - Behat - Mink - Drupal extension with Drush integration - Acceptance criteria - Demonstrations and show casesTRANSCRIPT
Automation in Drupalby Bozhidar Boshnakov
About me
• Bozhidar Boshnakov• Team leader @ ProPeople• [email protected]• Skype: bo6nakov• Drupal.org – bboshnakov• linkedin.com/in/bboshnakov
Table of contents• TDD – Test-Driven Development• BDD – Behavior-Driven Development• Gherkin• Behat• Mink• Drupal extension• Acceptance criteria• Demonstrations and show cases
INTELLIGENCE IS
A LIABILITY!
SMART PEOPLE
Can make progress …… without process
This is not a good thing !!!
Professionals• Design, plan and prepare first• …then do the work
• This produces better results FASTER !!!
Process is the difference between
Software Engineering & Programming
In order to verify application behaviorAs a software developer
I need tests
Preferably automated tests
Test-Driven Development
• Write a test• Ensure the new test fails• Write code to satisfy the test• Ensure all tests pass• Refactor• Repeat
…is an iterative design process
Behavior-Driven Development
• Write test cases in a natural language– Understood by developers and business folks alike– Helps relate domain language of requirements to
the code• Do this with user stories and scenarios– User stories describe a feature’s benefit in context– Scenarios are executable acceptance criteria
…builds upon TDD
GherkinGherkin is a Business Readable, Domain Specific Language created especially for behavior descriptions. It gives you the
ability to remove logic details from behavior tests.
Gherkin Syntax
Gherkin Syntax
Feature: Banana CalculatorAs Bob the Banana merchant,I want a calculator that can add the amount of bananas so that I can know how many bananas I currently haveScenario: Will add 2 banana amounts Given I have 3 Bananas When I add 5 Bananas Then I should have 8 Banana
This is where
and come in
Behat is an open source behavior-driven development framework for
PHP 5.3 and 5.4.
The simplest way to install Behat is through
Composer.
Before you begin, ensure that you have at least PHP 5.3.1 installed.
Composer.json{ "require": { "behat/mink": "*", "behat/mink-goutte-driver": "*", "behat/behat": "*", "behat/mink-extension": "*", "drupal/drupal-extension": "*" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" }}
Composer.phar
Then download composer.phar and run install command:
$ curl http://getcomposer.org/installer | php$ php composer.phar install
Behat.ymldefault: extensions: Behat\MinkExtension\Extension: base_url: http://wearepropeople.com goutte: ~ selenium2: ~ paths: features: features bootstrap: features/bootstrap
And the last step…
php bin/behat --init
And now you have your Features folder where you can create the magic!!!
What are the features?
Let's Have Behat Analyze Our Feature
Behat Creates the Glue...but the rest is up to you
Not so fast. What about Mink?
Understanding Mink
One of the most important parts in the web is a browser. A browser is the window through which web application users interact with the application and other users.
Headless browser
emulatorsVS Browser
controllers
Selenium2Driver
• Control the Browser – Session• Cookies and Headers management• HTTP Authentication• Traverse the Page - Selectors• Manipulate the Page
Mink Context Defines Steps...for making requests
Mink Context Defines Steps...for interacting with forms
Mink Context Defines Steps...for querying the DOM
Mink Context Defines Steps...for examining responses
Now…Let’s get away from the theory and show some
action!
TagsTags are a great way to organize your features and scenarios:
A Scenario or Feature can have as many tags as you like, just separate them with spaces:
TagsHow to execute the tags?
If a tag exists on a Feature, Behat will assign that tag to all child
Scenarios and Scenario Outlines too!
Behat.yml
All configuration happens inside a single configuration file in the
YAML format.
Imports…or share your feature configurations
Profiles
$bin/behat –p google features/feature1
The Drupal extension• Overrides default behaviors:
– Snippets follow Drupal coding standards– Mink Extension steps get synonyms for readability
• Provides drivers to facilitate data setup– Blackbox– Drush– Drupal API
• Adds support for Drupal:– Regions– Node types– Users and Roles– Taxonomy– Subcontexts for Contributed Modules
Provides drivers for data set up
• Works with Drupal 6, 7, and 8• Connect with no privileges (local or remote)• Connect with Drush (local or remote)• Connect with the Drupal API (local only)
About data setup• Every scenario must be able to run
independent of other scenarios• Often work with a fresh copy of the
production database• Can’t always assume the database has specific
content• Separate architectural elements from content
elements• Insert data to get reliable checks
Drush: alias file
http://drush.ws/examples/example.aliases.drushrc.php
Drush: behat.yml
Drupal API: behat.yml
Region map: behat.yml
RegionsRequires a map in the behat.yml file
• label => css selector• This means regions don’t have to map directly to
Drupal theme regions
Structure > Blocks > (Theme) > Demonstrate block regions
Nodes
Users, roles and taxonomies
Relational data
Relational data
If you have any questions or you want access for the full installation guideline feel
free to contact me on my email address:[email protected]
Special thanks to:
• Nikolay Ignatov• Boyan Borisov• Miroslav Banov• Toni Kolev
Resources
• http://dspeak.com/pnwds/6-drupalextension.html• http://docs.behat.org/guides/7.config.html• http://behat.org/• http://mink.behat.org/
Thank you!!!