Skip to content

@jhedstrom /FeatureContext.php
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Step-definition for complex node structure (field collection + entity reference).
<?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));
}
}
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.