Completed
Push — 8.x-1.x ( c248cd...375743 )
by Janez
02:14
created

ViewModeFieldFormatterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testViewModeFieldFormatter() 0 11 2
A testFilterViewModePlugins() 0 14 2
1
<?php
2
3
namespace Drupal\entity_embed\Tests;
4
5
use Drupal\Core\Form\FormState;
6
7
/**
8
 * Tests the view mode entity embed display provided by entity_embed.
9
 *
10
 * @group entity_embed
11
 */
12
class ViewModeFieldFormatterTest extends EntityEmbedTestBase {
13
14
  private $plugins = [
15
    'view_mode:node.full',
16
    'view_mode:node.rss',
17
    'view_mode:node.search_index',
18
    'view_mode:node.search_result',
19
    'view_mode:node.teaser',
20
  ];
21
22
  /**
23
   * Tests view mode entity embed display.
24
   */
25
  public function testViewModeFieldFormatter() {
26
    // Ensure that view mode plugins have no configuration form.
27
    foreach ($this->plugins as $plugin) {
28
      $form = [];
29
      $form_state = new FormState();
30
      $display = $this->displayPluginManager()->createInstance($plugin, []);
31
      $display->setContextValue('entity', $this->node);
32
      $conf_form = $display->buildConfigurationForm($form, $form_state);
33
      $this->assertIdentical(array_keys($conf_form), []);
34
    }
35
  }
36
37
  /**
38
   * Tests filter using view mode entity embed display plugins.
39
   */
40
  public function testFilterViewModePlugins() {
41
    foreach ($this->plugins as $plugin) {
42
      $content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid() . '" data-entity-embed-display="' . $plugin . '"></drupal-entity>';
43
      $settings = [];
44
      $settings['type'] = 'page';
45
      $settings['title'] = 'Test ' . $plugin . ' Entity Embed Display plugin';
46
      $settings['body'] = [['value' => $content, 'format' => 'custom_format']];
47
      $node = $this->drupalCreateNode($settings);
48
      $this->drupalGet('node/' . $node->id());
49
      $plugin = explode('.', $plugin);
50
      $view_mode = str_replace('_', '-', end($plugin));
51
      $this->assertRaw('node--view-mode-' . $view_mode, 'Node rendered in the correct view mode: ' . $view_mode . '.');
52
    }
53
  }
54
55
}
56