|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Contains \Drupal\url_embed\Tests\UrlEmbedTestBase. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Drupal\url_embed\Tests; |
|
9
|
|
|
|
|
10
|
|
|
use Drupal\editor\Entity\Editor; |
|
11
|
|
|
use Drupal\filter\Entity\FilterFormat; |
|
12
|
|
|
use Drupal\simpletest\WebTestBase; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Base class for all url_embed tests. |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class UrlEmbedTestBase extends WebTestBase { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Modules to enable. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
public static $modules = array('url_embed', 'node', 'ckeditor'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The test user. |
|
28
|
|
|
* |
|
29
|
|
|
* @var \Drupal\user\UserInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $webUser; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The test Flickr URL. |
|
35
|
|
|
*/ |
|
36
|
|
|
const FLICKR_URL = 'http://www.flickr.com/photos/bees/2341623661/'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The expected output of the Flickr URL in a link field. |
|
40
|
|
|
*/ |
|
41
|
|
|
const FLICKR_OUTPUT_FIELD = '<a data-flickr-embed="true" href="https://www.flickr.com/photos/bees/2341623661/" title="ZB8T0193 by bees, on Flickr"><img src="https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_b.jpg" width="1024" height="683" alt="ZB8T0193"></a><script async src="https://embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The expected output of the Flickr URL in a WYSIWYG. |
|
45
|
|
|
* |
|
46
|
|
|
* Embeds rendered via the url_embed filter generate XHTML4 markup due to |
|
47
|
|
|
* deficiencies with libxml2. |
|
48
|
|
|
* |
|
49
|
|
|
* @todo Remove once https://www.drupal.org/node/1333730 lands. |
|
50
|
|
|
*/ |
|
51
|
|
|
const FLICKR_OUTPUT_WYSIWYG = '<a data-flickr-embed="true" href="https://www.flickr.com/photos/bees/2341623661/" title="ZB8T0193 by bees, on Flickr"><img src="https://farm4.staticflickr.com/3123/2341623661_7c99f48bbf_b.jpg" width="1024" height="683" alt="ZB8T0193" /></a><script async="" src="https://embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>'; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* A set up for all tests. |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function setUp() { |
|
57
|
|
|
parent::setUp(); |
|
58
|
|
|
|
|
59
|
|
|
// Create a page content type. |
|
60
|
|
|
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
// Create a text format and enable the url_embed filter. |
|
64
|
|
|
$format = FilterFormat::create([ |
|
65
|
|
|
'format' => 'custom_format', |
|
66
|
|
|
'name' => 'Custom format', |
|
67
|
|
|
'filters' => [ |
|
68
|
|
|
'url_embed' => [ |
|
69
|
|
|
'status' => 1, |
|
70
|
|
|
], |
|
71
|
|
|
], |
|
72
|
|
|
]); |
|
73
|
|
|
$format->save(); |
|
74
|
|
|
|
|
75
|
|
|
$editor_group = [ |
|
76
|
|
|
'name' => 'URL Embed', |
|
77
|
|
|
'items' => [ |
|
78
|
|
|
'url', |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
$editor = Editor::create([ |
|
82
|
|
|
'format' => 'custom_format', |
|
83
|
|
|
'editor' => 'ckeditor', |
|
84
|
|
|
'settings' => [ |
|
85
|
|
|
'toolbar' => [ |
|
86
|
|
|
'rows' => [[$editor_group]], |
|
87
|
|
|
], |
|
88
|
|
|
], |
|
89
|
|
|
]); |
|
90
|
|
|
$editor->save(); |
|
91
|
|
|
|
|
92
|
|
|
// Create a user with required permissions. |
|
93
|
|
|
$this->webUser = $this->drupalCreateUser(array( |
|
94
|
|
|
'access content', |
|
95
|
|
|
'create page content', |
|
96
|
|
|
'use text format custom_format', |
|
97
|
|
|
)); |
|
98
|
|
|
$this->drupalLogin($this->webUser); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|