|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\entity_embed\Tests; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Tests Twig extension provided by entity_embed. |
|
7
|
|
|
* |
|
8
|
|
|
* @group entity_embed |
|
9
|
|
|
*/ |
|
10
|
|
|
class EntityEmbedTwigTest extends EntityEmbedTestBase { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function setUp() { |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
\Drupal::service('theme_handler')->install(array('test_theme')); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Tests that the provided Twig extension loads the service appropriately. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testTwigExtensionLoaded() { |
|
24
|
|
|
$twig_service = \Drupal::service('twig'); |
|
25
|
|
|
|
|
26
|
|
|
$ext = $twig_service->getExtension('entity_embed.twig.entity_embed_twig_extension'); |
|
27
|
|
|
|
|
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.'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Tests that the Twig extension's filter produces expected output. |
|
36
|
|
|
*/ |
|
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'); |
|
41
|
|
|
|
|
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.'); |
|
47
|
|
|
|
|
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.'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|