View source
<?php
namespace Drupal\Tests\url_embed\Functional;
use Drupal\editor\Entity\Editor;
class UrlEmbedDialogTest extends UrlEmbedTestBase {
public function testUrlEmbedDialog() {
$this
->getEmbedDialog();
$this
->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');
$this
->getEmbedDialog('custom_format');
$this
->assertResponse(404, 'Embed dialog is not accessible without specifying embed button.');
$this
->getEmbedDialog('custom_format', 'invalid_button');
$this
->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');
$this
->getEmbedDialog('plain_text', 'url');
$this
->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');
$editor = Editor::create([
'format' => 'plain_text',
'editor' => 'ckeditor',
]);
$editor
->save();
$this
->getEmbedDialog('plain_text', 'url');
$this
->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');
$this
->getEmbedDialog('custom_format', 'url');
$this
->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
}
public function testUrlEmbedButtonMarkup() {
$this
->getEmbedDialog('plain_text', 'url');
$this
->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');
$editor = Editor::create([
'format' => 'plain_text',
'editor' => 'ckeditor',
]);
$editor
->save();
$this
->getEmbedDialog('plain_text', 'url');
$this
->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');
$this
->getEmbedDialog('custom_format', 'url');
$this
->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
$this
->assertFieldByName('attributes[data-embed-url]', '', 'URL field is present.');
$this
->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');
$edit = [
'attributes[data-embed-url]' => static::FLICKR_URL,
];
$this
->drupalPostForm(NULL, $edit, 'Embed');
}
public function getEmbedDialog($filter_format_id = NULL, $embed_button_id = NULL) {
$url = 'url-embed/dialog';
if (!empty($filter_format_id)) {
$url .= '/' . $filter_format_id;
if (!empty($embed_button_id)) {
$url .= '/' . $embed_button_id;
}
}
return $this
->drupalGet($url);
}
}