Skip to content

Instantly share code, notes, and snippets.

@melissamcewen
Created July 12, 2016 19:32
Show Gist options
  • Save melissamcewen/f0ccb6e3531b5c77d92f6ddc64f7a8a5 to your computer and use it in GitHub Desktop.
Save melissamcewen/f0ccb6e3531b5c77d92f6ddc64f7a8a5 to your computer and use it in GitHub Desktop.
Behat Tests for Drupal Paragraphs
<?php
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Exception\ExpectationException;
use Behat\Behat\Event\StepEvent;
/**
* 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()
{
}
/**
* @Then /^the "([^"]*)" entity type "([^"]*)" should have field "([^"]*)" of type "([^"]*)"$/
*/
public function assertFieldNameAndType($entity_type, $bundle, $field_name, $type)
{
if (!$field = field_info_field($field_name)) {
throw new ExpectationException('Field does not exist.', $this->getSession());
}
if (!$instance = field_info_instance($entity_type, $field_name, $bundle)) {
throw new ExpectationException('Field not found on node type.', $this->getSession());
}
if ($field['type'] != $type) {
throw new ExpectationException("Field is type {$field['type']}.", $this->getSession());
}
}
}
Feature: Add video component
In order to share videos on content
As a super user or basic author I should be able to add a video component to an article
@api
Scenario Outline: A super user or basic author should be able to add videos
Given I am logged in as a user with the "<role>" role
When I go to "node/add/article"
Then I should see "Add Video"
Examples:
| role |
| Super User |
| Basic Author |
@api
Scenario: A video component should allow you to add a video, headline, and caption
Then the "paragraphs_item" entity type "video" should have field "field_video" of type "file"
Then the "paragraphs_item" entity type "video" should have field "field_image_headline" of type "text"
Then the "paragraphs_item" entity type "video" should have field "field_caption" of type "text_long"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment