3 namespace Drupal\entity_embed\Tests;
6 * Tests Twig extension provided by entity_embed.
10 class EntityEmbedTwigTest extends EntityEmbedTestBase {
15 protected function setUp() {
17 \Drupal::service('theme_handler')->install(array('test_theme'));
21 * Tests that the provided Twig extension loads the service appropriately.
23 public function testTwigExtensionLoaded() {
24 $twig_service = \Drupal::service('twig');
26 $ext = $twig_service->getExtension('entity_embed.twig.entity_embed_twig_extension');
28 // @todo why is the string
29 // 'Drupal\\entity_embed\\Twig\\EntityEmbedTwigExtension'
30 // and not '\Drupal\entity_embed\Twig\EntityEmbedTwigExtension' ?
31 $this->assertEqual(get_class($ext), 'Drupal\\entity_embed\\Twig\\EntityEmbedTwigExtension', 'Extension loaded successfully.');
35 * Tests that the Twig extension's filter produces expected output.
37 public function testEntityEmbedTwigFunction() {
38 // Test embedding a node using entity ID.
39 $this->drupalGet('entity_embed_twig_test/id');
40 $this->assertText($this->node->body->value, 'Embedded node exists in page');
42 // Test 'Label' Entity Embed Display plugin.
43 $this->drupalGet('entity_embed_twig_test/label_plugin');
44 $this->assertText($this->node->title->value, 'Title of the embedded node exists in page.');
45 $this->assertNoText($this->node->body->value, 'Body of embedded node does not exists in page when "Label" plugin is used.');
46 $this->assertLinkByHref('node/' . $this->node->id(), 0, 'Link to the embedded node exists when "Label" plugin is used.');
48 // Test 'Label' Entity Embed Display plugin without linking to the node.
49 $this->drupalGet('entity_embed_twig_test/label_plugin_no_link');
50 $this->assertText($this->node->title->value, 'Title of the embedded node exists in page.');
51 $this->assertNoText($this->node->body->value, 'Body of embedded node does not exists in page when "Label" plugin is used.');
52 $this->assertNoLinkByHref('node/' . $this->node->id(), 0, 'Link to the embedded node does not exists.');