1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains \Drupal\url_embed\Tests\LinkEmbedFormatterTest. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Drupal\url_embed\Tests; |
9
|
|
|
|
10
|
|
|
use Drupal\Component\Utility\Unicode; |
11
|
|
|
use Drupal\entity_test\Entity\EntityTest; |
12
|
|
|
use Drupal\link\LinkItemInterface; |
13
|
|
|
use Drupal\link\Tests\LinkFieldTest; |
14
|
|
|
use Drupal\url_embed\Tests\UrlEmbedTestBase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tests url_embed link field formatter. |
18
|
|
|
* |
19
|
|
|
* @group url_embed |
20
|
|
|
*/ |
21
|
|
|
class LinkEmbedFormatterTest extends LinkFieldTest{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Modules to enable. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
public static $modules = array('url_embed'); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Tests the 'url_embed' formatter. |
32
|
|
|
*/ |
33
|
|
|
function testLinkEmbedFormatter() { |
|
|
|
|
34
|
|
|
$field_name = Unicode::strtolower($this->randomMachineName()); |
35
|
|
|
// Create a field with settings to validate. |
36
|
|
|
$this->fieldStorage = entity_create('field_storage_config', array( |
37
|
|
|
'field_name' => $field_name, |
38
|
|
|
'entity_type' => 'entity_test', |
39
|
|
|
'type' => 'link', |
40
|
|
|
'cardinality' => 2, |
41
|
|
|
)); |
42
|
|
|
$this->fieldStorage->save(); |
43
|
|
|
entity_create('field_config', array( |
44
|
|
|
'field_storage' => $this->fieldStorage, |
45
|
|
|
'bundle' => 'entity_test', |
46
|
|
|
'settings' => array( |
47
|
|
|
'title' => DRUPAL_OPTIONAL, |
48
|
|
|
'link_type' => LinkItemInterface::LINK_GENERIC, |
49
|
|
|
), |
50
|
|
|
))->save(); |
51
|
|
|
entity_get_form_display('entity_test', 'entity_test', 'default') |
52
|
|
|
->setComponent($field_name, array( |
53
|
|
|
'type' => 'link_default', |
54
|
|
|
)) |
55
|
|
|
->save(); |
56
|
|
|
$display_options = array( |
57
|
|
|
'type' => 'url_embed', |
58
|
|
|
'label' => 'hidden', |
59
|
|
|
); |
60
|
|
|
entity_get_display('entity_test', 'entity_test', 'full') |
61
|
|
|
->setComponent($field_name, $display_options) |
62
|
|
|
->save(); |
63
|
|
|
|
64
|
|
|
// Create an entity to test the embed formatter. |
65
|
|
|
$url = UrlEmbedTestBase::FLICKR_URL; |
66
|
|
|
$entity = EntityTest::create(); |
67
|
|
|
$entity->set($field_name, $url); |
68
|
|
|
$entity->save(); |
69
|
|
|
|
70
|
|
|
// Render the entity and verify that the link is output as an embed. |
71
|
|
|
$this->renderTestEntity($entity->id()); |
72
|
|
|
$this->assertRaw(UrlEmbedTestBase::FLICKR_OUTPUT_FIELD); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.