Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Step-definition for complex node structure (field collection + entity reference).

View FeatureContext.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
<?php
/**
* @Given /^I am viewing a product with the following related products:$/
*/
public function assertRelatedProducts(TableNode $relatedProducts) {
// First, create a product.
$product = (object) array(
'title' => 'Parent Product',
'type' => 'product',
'uid' => 1,
);
$product = $this->getDriver()->createNode($product);
// Create and reference related nodes.
foreach ($relatedProducts->getHash() as $relatedProduct) {
$relatedProduct = (object) $relatedProduct;
$relatedProduct->type = 'product';
$saved = $this->getDriver()->createNode($relatedProduct);
$this->nodes[] = $saved;
// Create field collection item.
$fieldCollectionItem = entity_create('field_collection_item', array('field_name' => 'field_related_products'));
$fieldCollectionItem->setHostEntity('node', $product);
$fieldCollectionItem->field_product_reference[LANGUAGE_NONE][0]['target_id'] = $saved->nid;
$fieldCollectionItem->field_is_component[LANGUAGE_NONE][0]['value'] = $relatedProduct->component;
$fieldCollectionItem->save();
}
// Resave product node.
node_save($product);
$this->nodes[] = $product;
// Set internal page on the product.
$this->getSession()->visit($this->locatePath('/node/' . $product->nid));
}
}
View FeatureContext.php
1 2 3 4 5 6 7 8 9 10 11 12
Scenario: Related products and components
Given I am viewing a product with the following related products:
| title | component |
| Related product 1 | 0 |
| Related product 2 | 0 |
| Related component 1 | 1 |
| Related component 2 | 1 |
Then I should see the heading "Related Products"
And I should see the link "Related product 1"
And I should see the link "Related product 2"
And I should see the link "Related component 1"
And I should see the link "Related component 2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.