Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BehatDrushHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function DisplaySearchResults($test_id) {
foreach ($logs as $feature => $steps) {
BehatDrushHelper::coolLog($feature);

foreach ($steps as $step) {
foreach ($steps as $delta => $step) {
if ($step['status'] == 'pass') {
BehatDrushHelper::coolLog($step['step'], 'green', 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BehatTestsAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BehatTestsAbstract extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['behat'];
public static $modules = ['behat', 'node'];

/**
* @var array
Expand Down
6 changes: 4 additions & 2 deletions src/Features/comment_crud.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Feature: Comment crud.

Scenario: Testing the login form.
Given I visit "user"
@comment
Scenario: Testing comment creation.
Given I login as user "@user-name"
And I create a node
37 changes: 0 additions & 37 deletions src/FeaturesTraits/BasicTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,5 @@

trait BasicTrait {

/**
* @Given /^I fill in "([^"]*)" with "([^"]*)"$/
*/
public function iFillInWith($name, $value) {
$this->assertSession()->fieldExists($name);
$this->edit[$name] = $value;
}

/**
* @Given /^I press "([^"]*)"$/
*/
public function iPress($element) {
$button = $this->assertSession()->buttonExists($element);

if ($button->getAttribute('type') == 'submit') {
// This is a submit element. Call the submit form method.
$this->submitForm($this->edit, $element);
}
else {
// Normal button. Press it.
$button->press();
}
}

/**
* @Given /^I should see "([^"]*)"$/
*/
public function iShouldSee($text) {
$this->assertSession()->pageTextContains($text);
}

/**
* @Given /^I visit "([^"]*)"$/
*/
public function iVisit($url) {
$this->drupalGet($url);
}

}
125 changes: 120 additions & 5 deletions src/Plugin/FeatureContext/FeatureContextBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

use Behat\Gherkin\Node\ScenarioInterface;
use Drupal\behat\BehatTestsAbstract;
use Drupal\behat\FeaturesTraits\BasicTrait;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\User;

/**
* @FeatureContext(
Expand All @@ -20,18 +22,131 @@
*/
class FeatureContextBase extends BehatTestsAbstract {

use BasicTrait;
/**
* @var User
*
* The user object.
*/
protected $account;

/**
* @var Node
*/
protected $node;

/**
* {@inheritdoc}
*/
public function beforeScenario(ScenarioInterface $scenarioInterface = NULL) {
parent::beforeScenario($scenarioInterface);

$account = $this->drupalCreateUser();
$permissions = [];
if ($tags = $scenarioInterface->getTags()) {
// Keep the permissions for tests with entity.
$tests_permissions = [
'comment' => ['post comments'],
'node' => ['create node'],
'taxonomy-term' => 'create terms',
];

$entity_feature = $tags[0];
$permissions = $tests_permissions[$entity_feature];
}

$this->account = $this->drupalCreateUser();
$this->placeholders = [
'@user-name' => $account->label(),
'@user-pass' => $account->passRaw,
'@user-name' => $this->account->label(),
'@user-pass' => $this->account->passRaw,
];
}

/**
* Creates a node based on default settings.
*
* @param array $settings
* (optional) An associative array of settings for the node, as used in
* entity_create(). Override the defaults by specifying the key and value
* in the array, for example:
* @code
* $this->drupalCreateNode(array(
* 'title' => t('Hello, world!'),
* 'type' => 'article',
* ));
* @endcode
* The following defaults are provided:
* - body: Random string using the default filter format:
* @code
* $settings['body'][0] = array(
* 'value' => $this->randomMachineName(32),
* 'format' => filter_default_format(),
* );
* @endcode
* - title: Random string.
* - type: 'page'.
* - uid: The currently logged in user, or anonymous.
*
* @return \Drupal\node\NodeInterface
* The created node entity.
*/
protected function drupalCreateNode(array $settings = array()) {
$node = entity_create('node', $settings);
$node->save();

return $node;
}

/**
* @Given /^I fill in "([^"]*)" with "([^"]*)"$/
*/
public function iFillInWith($name, $value) {
$this->assertSession()->fieldExists($name);
$this->edit[$name] = $value;
}

/**
* @Given /^I press "([^"]*)"$/
*/
public function iPress($element) {
$button = $this->assertSession()->buttonExists($element);

if ($button->getAttribute('type') == 'submit') {
// This is a submit element. Call the submit form method.
$this->submitForm($this->edit, $element);
}
else {
// Normal button. Press it.
$button->press();
}
}

/**
* @Given /^I should see "([^"]*)"$/
*/
public function iShouldSee($text) {
$this->assertSession()->pageTextContains($text);
}

/**
* @Given /^I visit "([^"]*)"$/
*/
public function iVisit($url) {
$this->drupalGet($url);
}

/**
* @Given /^I login as user "([^"]*)"$/
*/
public function iLogInAsUser($name) {
// todo: handle multiple users in the test.
$this->drupalLogin($this->account);
}

/**
* @Given /^I create a node$/
*/
public function iCreateNode() {
NodeType::create(['name' => 'page', 'type' => 'page'])->save();
Node::create(['type' => 'page', 'title' => 'foo', 'uid' => 1])->save();
// $this->ivisit($this->node->url());
}
}