4 Before Behat 3, each test suite was limited to a single context class. As of
5 Behat 3, it is possible to flexibly structure your code by using multiple
6 contexts in a single test suite.
11 In accordance with this new capability, The Drupal Extension includes the
15 A context that provides no step definitions, but all of the
16 necessary functionality for interacting with Drupal, and with the
17 browser via Mink sessions.
20 Provides step-definitions for creating users, terms, and nodes.
23 Builds on top of the Mink Extension and adds steps specific to regions and
27 Contains step definitions that deal with low-level markup (such as tags,
28 classes, and attributes).
31 Step-definitions that are specific to Drupal messages that get displayed
32 (notice, warning, and error).
35 Allows steps to directly call drush commands.
40 You can structure your own code with additional contexts. See Behat's `testing features <http://docs.behat.org/en/latest/guides/4.contexts.html>`_ documentation for a detailed discussion of how contexts work.
44 Every context you want to use in a suite must declare it in the behat.yml
50 In this example, you would have access to:
52 * pre-written step definitions for users, terms, and nodes
53 (from the ``DrupalContext``)
54 * steps you've implemented in the main
55 ``features/bootstrap/FeatureContext.php`` file
56 * steps you've implemented in the ``CustomContext`` class
58 You would not have access to the steps from the ``MarkupContext``,
59 ``MessageContext``, or ``DrushContext``, however.
68 - Drupal\DrupalExtension\Context\DrupalContext
75 Since Behat 3 can have many concurrent contexts active, communication between those contexts can be important.
77 The following will gather any specified contexts before a given scenario is run:
79 .. literalinclude:: _static/snippets/context-communication.inc
83 Drupal Extension Hooks
84 ----------------------
86 In addition to the `hooks provided by Behat
87 <http://behat.readthedocs.org/en/v2.5/guides/3.hooks.html>`_, the Drupal
88 Extension provides three additional ways to tag the methods in your
89 ``CustomContext`` class in order to have them fire before certain events.
91 1. ``@beforeNodeCreate``
92 2. ``@beforeTermCreate``
93 3. ``@beforeUserCreate``
101 use Drupal\DrupalExtension\Hook\Scope\EntityScope;
104 * Call this function before nodes are created.
108 public function alterNodeObject(EntityScope $scope) {
109 $node = $scope->getEntity();
110 // Alter node object as needed.