ViewModeFieldFormatterTest.php in Entity Embed 8
File
tests/src/Functional/ViewModeFieldFormatterTest.php
View source
<?php
namespace Drupal\Tests\entity_embed\Functional;
use Drupal\Core\Form\FormState;
class ViewModeFieldFormatterTest extends EntityEmbedTestBase {
protected $defaultTheme = 'classy';
private $plugins = [
'view_mode:node.full',
'view_mode:node.rss',
'view_mode:node.search_index',
'view_mode:node.search_result',
'view_mode:node.teaser',
];
public function testViewModeFieldFormatter() {
foreach ($this->plugins as $plugin) {
$form = [];
$form_state = new FormState();
$display = $this->container
->get('plugin.manager.entity_embed.display')
->createInstance($plugin, []);
$display
->setContextValue('entity', $this->node);
$conf_form = $display
->buildConfigurationForm($form, $form_state);
$this
->assertSame([], array_keys($conf_form));
}
}
public function testFilterViewModePlugins() {
foreach ($this->plugins as $plugin) {
$content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node
->uuid() . '" data-entity-embed-display="' . $plugin . '"></drupal-entity>';
$settings = [];
$settings['type'] = 'page';
$settings['title'] = 'Test ' . $plugin . ' Entity Embed Display plugin';
$settings['body'] = [
[
'value' => $content,
'format' => 'custom_format',
],
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node
->id());
$plugin = explode('.', $plugin);
$view_mode = str_replace('_', '-', end($plugin));
$this
->assertSession()
->responseContains('node--view-mode-' . $view_mode, 'Node rendered in the correct view mode: ' . $view_mode . '.');
}
}
public function testViewModeDependencies() {
$button = $this->container
->get('entity_type.manager')
->getStorage('embed_button')
->load('node');
$config = $button
->get('type_settings');
$config['display_plugins'] = [
'view_mode:node.teaser',
];
$button
->set('type_settings', $config);
$button
->save();
$dependencies = $button
->getDependencies();
$this
->assertContains('core.entity_view_mode.node.teaser', $dependencies['config']);
$config['display_plugins'] = [
'view_mode:node.full',
];
$button
->set('type_settings', $config);
$button
->save();
$dependencies = $button
->getDependencies();
$this
->assertNotContains('core.entity_view_mode.node.teaser', $dependencies['config']);
}
}