View source
<?php
namespace Drupal\Tests\entity_embed\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
class EntityEmbedDialogTest extends EntityEmbedTestBase {
public static $modules = [
'image',
];
protected $webUser;
protected $node;
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$format = FilterFormat::create([
'format' => 'custom_format',
'name' => 'Custom format',
'filters' => [
'entity_embed' => [
'status' => 1,
],
],
]);
$format
->save();
$editor_group = [
'name' => 'Entity Embed',
'items' => [
'node',
],
];
$editor = Editor::create([
'format' => 'custom_format',
'editor' => 'ckeditor',
'settings' => [
'toolbar' => [
'rows' => [
[
$editor_group,
],
],
],
],
]);
$editor
->save();
$this->webUser = $this
->drupalCreateUser([
'access content',
'create page content',
'use text format custom_format',
]);
$this
->drupalLogin($this->webUser);
$settings = [];
$settings['type'] = 'page';
$settings['title'] = 'Embed Test Node';
$settings['body'] = [
'value' => 'This node is to be used for embedding in other nodes.',
'format' => 'custom_format',
];
$this->node = $this
->drupalCreateNode($settings);
}
public function testEntityEmbedButtonMarkup() {
$this
->drupalGet('/entity-embed/dialog/custom_format/node');
$this
->assertSession()
->fieldExists('entity_id');
$this
->assertSession()
->elementExists('xpath', '//input[contains(@class, "button--primary")]');
$title = $this->node
->getTitle() . ' (' . $this->node
->id() . ')';
$this
->assertSession()
->fieldExists('entity_id')
->setValue($title);
$this
->assertSession()
->buttonExists('Next')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'view_mode:node.full',
'view_mode:node.rss',
'view_mode:node.search_index',
'view_mode:node.search_result',
'view_mode:node.teaser',
];
foreach ($plugins as $plugin) {
$this
->assertSession()
->optionExists('Display as', $plugin);
}
$this->container
->get('config.factory')
->getEditable('entity_embed.settings')
->set('rendered_entity_mode', TRUE)
->save();
$this->container
->get('plugin.manager.entity_embed.display')
->clearCachedDefinitions();
$this
->drupalGet('/entity-embed/dialog/custom_format/node');
$title = $this->node
->getTitle() . ' (' . $this->node
->id() . ')';
$this
->assertSession()
->fieldExists('entity_id')
->setValue($title);
$this
->assertSession()
->buttonExists('Next')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$plugins = [
'entity_reference:entity_reference_label',
'entity_reference:entity_reference_entity_id',
'entity_reference:entity_reference_entity_view',
];
foreach ($plugins as $plugin) {
$this
->assertSession()
->optionExists('Display as', $plugin);
}
}
}