1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains \Drupal\url_embed\Tests\UrlEmbedDialogTest. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Drupal\url_embed\Tests; |
9
|
|
|
|
10
|
|
|
use Drupal\editor\Entity\Editor; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Tests the url_embed dialog controller and route. |
14
|
|
|
* |
15
|
|
|
* @group url_embed |
16
|
|
|
*/ |
17
|
|
|
class UrlEmbedDialogTest extends UrlEmbedTestBase { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Tests the URL embed dialog. |
21
|
|
|
*/ |
22
|
|
|
public function testUrlEmbedDialog() { |
23
|
|
|
// Ensure that the route is not accessible without specifying all the |
24
|
|
|
// parameters. |
25
|
|
|
$this->getEmbedDialog(); |
26
|
|
|
$this->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.'); |
27
|
|
|
$this->getEmbedDialog('custom_format'); |
28
|
|
|
$this->assertResponse(404, 'Embed dialog is not accessible without specifying embed button.'); |
29
|
|
|
|
30
|
|
|
// Ensure that the route is not accessible with an invalid embed button. |
31
|
|
|
$this->getEmbedDialog('custom_format', 'invalid_button'); |
32
|
|
|
$this->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.'); |
33
|
|
|
|
34
|
|
|
// Ensure that the route is not accessible with text format without the |
35
|
|
|
// button configured. |
36
|
|
|
$this->getEmbedDialog('plain_text', 'url'); |
37
|
|
|
$this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.'); |
38
|
|
|
|
39
|
|
|
// Add an empty configuration for the plain_text editor configuration. |
40
|
|
|
$editor = Editor::create([ |
41
|
|
|
'format' => 'plain_text', |
42
|
|
|
'editor' => 'ckeditor', |
43
|
|
|
]); |
44
|
|
|
$editor->save(); |
45
|
|
|
$this->getEmbedDialog('plain_text', 'url'); |
46
|
|
|
$this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.'); |
47
|
|
|
|
48
|
|
|
// Ensure that the route is accessible with a valid embed button. |
49
|
|
|
// 'URL' embed button is provided by default by the module and hence the |
50
|
|
|
// request must be successful. |
51
|
|
|
$this->getEmbedDialog('custom_format', 'url'); |
52
|
|
|
$this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tests the URL embed button markup. |
57
|
|
|
*/ |
58
|
|
|
public function testUrlEmbedButtonMarkup() { |
59
|
|
|
// Ensure that the route is not accessible with text format without the |
60
|
|
|
// button configured. |
61
|
|
|
$this->getEmbedDialog('plain_text', 'url'); |
62
|
|
|
$this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.'); |
63
|
|
|
// Add an empty configuration for the plain_text editor configuration. |
64
|
|
|
$editor = Editor::create([ |
65
|
|
|
'format' => 'plain_text', |
66
|
|
|
'editor' => 'ckeditor', |
67
|
|
|
]); |
68
|
|
|
$editor->save(); |
69
|
|
|
$this->getEmbedDialog('plain_text', 'url'); |
70
|
|
|
$this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.'); |
71
|
|
|
// Ensure that the route is accessible with a valid embed button. |
72
|
|
|
// 'URL' embed button is provided by default by the module and hence the |
73
|
|
|
// request must be successful. |
74
|
|
|
$this->getEmbedDialog('custom_format', 'url'); |
75
|
|
|
$this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.'); |
76
|
|
|
// Ensure form structure of the url_embed_dialog form. |
77
|
|
|
$this->assertFieldByName('attributes[data-embed-url]', '', 'URL field is present.'); |
78
|
|
|
// Check that 'Embed' is a primary button. |
79
|
|
|
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button'); |
80
|
|
|
$edit = ['attributes[data-embed-url]' => static::FLICKR_URL]; |
81
|
|
|
$this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Embed'))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Retrieves an embed dialog based on given parameters. |
86
|
|
|
* |
87
|
|
|
* @param string $filter_format_id |
88
|
|
|
* ID of the filter format. |
89
|
|
|
* @param string $embed_button_id |
90
|
|
|
* ID of the embed button. |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
* The retrieved HTML string. |
94
|
|
|
*/ |
95
|
|
|
public function getEmbedDialog($filter_format_id = NULL, $embed_button_id = NULL) { |
96
|
|
|
$url = 'url-embed/dialog'; |
97
|
|
|
if (!empty($filter_format_id)) { |
98
|
|
|
$url .= '/' . $filter_format_id; |
99
|
|
|
if (!empty($embed_button_id)) { |
100
|
|
|
$url .= '/' . $embed_button_id; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
return $this->drupalGet($url); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|