Files for the Blog Post on testing Drupal projects with Behat in PhpStorm, see https://www.paragon-es.de/en/blog/drupal-testing-behat-phpstorm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: | |
suites: | |
default: | |
contexts: | |
- FeatureContext | |
- Drupal\DrupalExtension\Context\DrupalContext | |
- Drupal\DrupalExtension\Context\DrushContext | |
- Drupal\DrupalExtension\Context\MarkupContext | |
- Drupal\DrupalExtension\Context\MessageContext | |
- Drupal\DrupalExtension\Context\MinkContext | |
- Drupal\DrupalExtension\Context\RawDrupalContext | |
extensions: | |
Behat\MinkExtension: | |
goutte: ~ | |
Drupal\DrupalExtension: | |
blackbox: ~ | |
api_driver: "drush" | |
drupal: | |
drupal_root: "/var/www/test" | |
subcontexts: | |
paths: | |
- "/var/www/test/sites/all/modules" | |
region_map: | |
First sidebar: "#sidebar-first" | |
Main content: "#main .region" | |
selectors: | |
message_selector: ".messages, #absolute-messages-messages" | |
error_message_selector: "#absolute-messages-messages .absolute-messages-error, .alert.alert-danger" | |
success_message_selector: "#absolute-messages-messages .absolute-messages-status .content, #status-message-container .messages.status, .alert.alert-success" | |
text: | |
log_out: "Log out" | |
log_in: "Log in" | |
password_field: "Password" | |
username_field: "Username or e-mail address" | |
MainTest: | |
suites: | |
default: | |
paths: | |
- %paths.base%/features/basic | |
- %paths.base%/features/specific1 | |
extensions: | |
Behat\MinkExtension: | |
base_url: "http://site1.localhost" | |
Drupal\DrupalExtension: | |
drush: | |
alias: "site1" | |
SubTest: | |
suites: | |
default: | |
paths: | |
- %paths.base%/features/basic | |
- %paths.base%/features/specific2 | |
extensions: | |
Behat\MinkExtension: | |
base_url: "http://site2.localhost" | |
Drupal\DrupalExtension: | |
drush: | |
alias: "site2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Anonymous User Tests | |
In order to protect data of the company and its customers | |
As an anonymous user | |
I want to make sure that no data is available to anonymous visitors | |
Background: | |
Given I am not logged in | |
Scenario: Check general availability of the site | |
When I am on "user" | |
Then I should see the text "User account" | |
And I should not see the text "Access denied" | |
Scenario: Test the user login form and error messages | |
When I am on "user" | |
And I press "Log in" | |
Then I should see the following error messages: | |
| error messages | | |
| Username or e-mail address field is required | | |
| Password field is required | | |
And I should not see the following error messages: | |
| error messages | | |
| Sorry, unrecognized username or password | | |
| Unable to send e-mail. Contact the site administrator if the problem persists | | |
Scenario Outline: Make sure certain urls are not available | |
When I am on "<url>" | |
Then I should get a "403" HTTP response | |
And I should see the text "Access denied" | |
Examples: | |
| url | | |
| admin | | |
| node/add | | |
| user/1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Behat\Behat\Context\SnippetAcceptingContext; | |
use Drupal\DrupalExtension\Context\RawDrupalContext; | |
/** | |
* Defines application features from the specific context. | |
*/ | |
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext { | |
/** | |
* Initializes context. | |
* | |
* Every scenario gets its own context instance. | |
* You can also pass arbitrary arguments to the | |
* context constructor through behat.yml. | |
*/ | |
public function __construct() | |
{ | |
} | |
/** | |
* @BeforeStep | |
*/ | |
public function beforeEachStep($event) { | |
} | |
/** | |
* @AfterStep | |
*/ | |
public function afterEachStep($event) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment