You are here

public function FieldTemplateTest::testFieldTemplateMinimal in Display Suite 8.4

Tests minimal template functionality.

File

tests/src/Functional/FieldTemplateTest.php, line 553

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function testFieldTemplateMinimal() {

  // Get a node.

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->entitiesTestSetup('hidden');
  $body_field = $node->body->value;
  $edit = [
    'fields[body][region]' => 'right',
  ];
  $this
    ->dsConfigureUi($edit, 'admin/structure/types/manage/article/display');

  // Set minimal template on.
  $edit = [
    'fields[body][settings_edit_form][third_party_settings][ds][ft][id]' => 'minimal',
  ];
  $this
    ->dsEditFormatterSettings($edit, 'body');
  drupal_flush_all_caches();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field field-name-body"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);

  // Choose field classes.
  $classes = [
    'test_field_class',
    '[node:nid]',
  ];
  $edit = [
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][classes][]' => $classes,
  ];
  $this
    ->dsEditFormatterSettings($edit, 'body');
  drupal_flush_all_caches();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $classes = 'test_field_class ' . $node
    ->id() . ' field field-name-body';
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="' . $classes . '"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);

  // Switch theme.
  $this->container
    ->get('theme_installer')
    ->install([
    'ds_test_layout_theme',
  ]);
  $config = \Drupal::configFactory()
    ->getEditable('system.theme');
  $config
    ->set('default', 'ds_test_layout_theme')
    ->save();
  drupal_flush_all_caches();

  // Go to the node.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->responseContains('minimal overridden in test theme!');
  $classes = 'test_field_class ' . $node
    ->id() . ' field field-name-body';
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="' . $classes . '"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
}