ViewModeFieldFormatterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testViewModeFieldFormatter() 0 12 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->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), []);
35
    }
36
  }
37
38
  /**
39
   * Tests filter using view mode entity embed display plugins.
40
   */
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>';
44
      $settings = [];
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 . '.');
53
    }
54
  }
55
56
}
57