3 namespace Drupal\entity_embed\Tests;
5 use Drupal\Core\Form\FormState;
8 * Tests the view mode entity embed display provided by entity_embed.
12 class ViewModeFieldFormatterTest extends EntityEmbedTestBase {
15 'view_mode:node.full',
17 'view_mode:node.search_index',
18 'view_mode:node.search_result',
19 'view_mode:node.teaser',
23 * Tests view mode entity embed display.
25 public function testViewModeFieldFormatter() {
26 // Ensure that view mode plugins have no configuration form.
27 foreach ($this->plugins as $plugin) {
29 $form_state = new FormState();
30 $display = $this->container->get('plugin.manager.entity_embed.display')
31 ->createInstance($plugin, []);
32 $display->setContextValue('entity', $this->node);
33 $conf_form = $display->buildConfigurationForm($form, $form_state);
34 $this->assertIdentical(array_keys($conf_form), []);
39 * Tests filter using view mode entity embed display plugins.
41 public function testFilterViewModePlugins() {
42 foreach ($this->plugins as $plugin) {
43 $content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid() . '" data-entity-embed-display="' . $plugin . '"></drupal-entity>';
45 $settings['type'] = 'page';
46 $settings['title'] = 'Test ' . $plugin . ' Entity Embed Display plugin';
47 $settings['body'] = [['value' => $content, 'format' => 'custom_format']];
48 $node = $this->drupalCreateNode($settings);
49 $this->drupalGet('node/' . $node->id());
50 $plugin = explode('.', $plugin);
51 $view_mode = str_replace('_', '-', end($plugin));
52 $this->assertRaw('node--view-mode-' . $view_mode, 'Node rendered in the correct view mode: ' . $view_mode . '.');