public function FieldCollectionRulesIntegrationTestCase::testCreation in Field collection 7
Test creation field collection items.
File
- ./
field_collection.test, line 510 - Tests for field_collections.
Class
- FieldCollectionRulesIntegrationTestCase
- Test using field collection with Rules.
Code
public function testCreation() {
$this
->createFields();
$node = $this
->drupalCreateNode(array(
'type' => 'article',
));
// Create a field collection.
$action_set = rules_action_set(array(
'node' => array(
'type' => 'node',
'bundle' => 'article',
),
));
$action_set
->action('entity_create', array(
'type' => 'field_collection_item',
'param_field_name' => $this->field_name,
'param_host_entity:select' => 'node',
));
$action_set
->action('data_set', array(
'data:select' => 'entity-created:field-text',
'value' => 'foo',
));
$action_set
->execute($node);
$node = node_load($node->nid, NULL, TRUE);
$this
->assertTrue(!empty($node->{$this->field_name}[LANGUAGE_NONE][0]['value']), 'A field_collection has been successfully created.');
$this
->assertTrue(!empty($node->{$this->field_name}[LANGUAGE_NONE][0]['revision_id']), 'A field_collection has been successfully created (revision).');
// Now try making use of the field collection in rules.
$action_set = rules_action_set(array(
'node' => array(
'type' => 'node',
'bundle' => 'article',
),
));
$action_set
->action('drupal_message', array(
'message:select' => 'node:field-test-collection:0:field-text',
));
$action_set
->execute($node);
$msg = drupal_get_messages();
$this
->assertEqual(array_pop($msg['status']), 'foo', 'Field collection can be used.');
RulesLog::logger()
->checkLog();
}