function EntityEmbedHooksTest::testEntityEmbedHooks in Entity Embed 7.3
Same name and namespace in other branches
- 7 entity_embed.test \EntityEmbedHooksTest::testEntityEmbedHooks()
- 7.2 entity_embed.test \EntityEmbedHooksTest::testEntityEmbedHooks()
Tests the hooks provided by entity_embed module.
This method tests all the hooks provided by entity_embed.
File
- ./
entity_embed.test, line 407 - Test integration for the entity_embed module.
Class
- EntityEmbedHooksTest
- Tests the hooks provided by entity_embed.
Code
function testEntityEmbedHooks() {
// Enable entity_embed_test.module's hook_entity_embed_alter()
// implementation and ensure it is working as designed.
variable_set('entity_embed_test_entity_embed_alter', TRUE);
$content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid . '" data-entity-embed-display="default" data-entity-embed-settings=\'{"view_mode":"teaser"}\'>This placeholder should not be rendered.</drupal-entity>';
$settings = array();
$settings['type'] = 'page';
$settings['title'] = 'Test hook_entity_embed_alter()';
$settings['body'] = array(
LANGUAGE_NONE => array(
array(
'value' => $content,
'format' => 'custom_format',
),
),
);
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($this->node->body[LANGUAGE_NONE][0]['value'], 'Embedded node exists in page');
$this
->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.');
// Ensure that embedded node's title has been replaced.
$this
->assertText('Title set by hook_entity_embed_alter', 'Title of the embedded node is replaced by hook_entity_embed_alter()');
$this
->assertNoText($this->node->title, 'Original title of the embedded node is not visible.');
variable_set('entity_embed_test_entity_embed_alter', FALSE);
// Enable entity_embed_test.module's hook_entity_embed_context_alter()
// implementation and ensure it is working as designed.
variable_set('entity_embed_test_entity_embed_context_alter', TRUE);
$content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid . '" data-entity-embed-display="default" data-entity-embed-settings=\'{"view_mode":"teaser"}\'>This placeholder should not be rendered.</drupal-entity>';
$settings = array();
$settings['type'] = 'page';
$settings['title'] = 'Test hook_entity_embed_context_alter()';
$settings['body'] = array(
LANGUAGE_NONE => array(
array(
'value' => $content,
'format' => 'custom_format',
),
),
);
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.');
// To ensure that 'label' plugin is used, verify that the body of the
// embedded node is not visible and the title links to the embedded node.
$this
->assertNoText($this->node->body[LANGUAGE_NONE][0]['value'], 'Body of the embedded node does not exist in page.');
// $this->assertText('Title set by hook_entity_embed_context_alter', 'Title of the embedded node is replaced by hook_entity_embed_context_alter()');
// $this->assertNoText($this->node->title, 'Original title of the embedded node is not visible.');
$this
->assertLinkByHref('node/' . $this->node->nid, 0, 'Link to the embedded node exists.');
variable_set('entity_embed_test_entity_embed_context_alter', FALSE);
}