Last active
August 29, 2015 14:08
-
-
Save mariacha/ede623d000f709e0c3fe to your computer and use it in GitHub Desktop.
Behat Drupal setup for Field Collection
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 | |
/** | |
* @file | |
* Project-specific functions | |
*/ | |
use Behat\Behat\Context\ClosuredContextInterface, | |
Behat\Behat\Context\TranslatedContextInterface, | |
Behat\Behat\Context\BehatContext, | |
Behat\Behat\Exception\PendingException; | |
use Behat\Gherkin\Node\PyStringNode, | |
Behat\Gherkin\Node\TableNode; | |
use Behat\Mink\Exception\ElementNotFoundException; | |
// | |
// Require 3rd-party libraries here: | |
// | |
// require_once 'PHPUnit/Autoload.php'; | |
// require_once 'PHPUnit/Framework/Assert/Functions.php'; | |
// | |
/** | |
* Features context. | |
*/ | |
class FeatureContext extends Drupal\DrupalExtension\Context\DrupalContext { | |
/** | |
* @Given /^I create the following "([^"]*)" field collections$/ | |
*/ | |
public function iCreateTheFollowingFieldCollections($label, TableNode $fcTable) { | |
$page = $this->getSession()->getPage(); | |
// Assumes field collections will be in a sortable table. | |
$table_xpath = 'table[contains(@class,"field-multiple-table")][contains(.,"' . $label. '")]'; | |
$field_collection_region = $page->find('xpath', '//div[contains(@class,"field-type-field-collection")]'); | |
$field_collection_table = $page->find('xpath', '//' . $table_xpath); | |
$row = 1; | |
foreach ($fcTable->getHash() as $fcRow) { | |
$this_row = $field_collection_table->find('xpath', '//tbody/tr[' . $row . ']'); | |
if (!$this_row) { | |
throw new \Exception("Could not find table row $row"); | |
} | |
// Little hack to make sure wysiwyg will be filled. | |
$this_row->findLink('Switch to plain text editor')->click(); | |
foreach ($fcRow as $key => $value) { | |
$this_row->fillField($key, $value); | |
} | |
$field_collection_region->findButton('Add another item')->click(); | |
$this->iWaitForAjaxToFinish(); | |
$row++; | |
} | |
} | |
} |
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: Content Type: Opportunity | |
As an author | |
I want to publish opportunities | |
so that a site visitor can find opportunities and apply. | |
@api @javascript | |
Scenario: Create a Opportunity node | |
Given I am logged in as a user with the "administrator" role | |
When I visit "/node/add/opportunity" | |
Then I should see the heading "Create Opportunity" | |
And I fill in the following: | |
| Title | Barista | | |
| City | Portland | | |
| State | OR | | |
| Job Description | Make coffee for a city that loves coffee! | | |
| URL | http://starbucks.com | | |
And I create the following "More info" field collections | |
| Title | More information | | |
| Pay | Minimal | | |
| Requirements | Ability to put up with uncaffienated and overcaffienated people | | |
And I press "Save" | |
Then I should see "Barista" | |
And I should see "Portland" | |
And I should see "OR" | |
And I should see "Make coffee for a city that loves coffee!" | |
And the link "Apply" should go to "http://starbucks.com" | |
And I should see "Pay" | |
And I should see "Minimal" | |
And I should see "Requirements" | |
And I should see "Ability to put up with uncaffienated and overcaffienated people" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment