You are here

public function FieldTemplateTest::testDsFieldTemplate3 in Display Suite 8.4

Tests on field templates.

File

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

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function testDsFieldTemplate3() {

  // Get a node.

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->entitiesTestSetup('hidden');
  $body_field = $node->body->value;

  // Custom field function with outer wrapper.
  $edit = [
    'fields[body][settings_edit_form][third_party_settings][ds][ft][id]' => 'expert',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
  ];
  $this
    ->dsEditFormatterSettings($edit);
  drupal_flush_all_caches();

  // As long as we don't change anything in the UI, the default template will
  // be used.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/div/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);

  // With outer div wrapper and class.
  $edit = [
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'div',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class',
  ];
  $this
    ->dsEditFormatterSettings($edit);
  drupal_flush_all_caches();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="ow-class"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);

  // With outer span wrapper and class.
  $edit = [
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow]' => '1',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-el]' => 'span',
    'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][ow-cl]' => 'ow-class-2',
  ];
  $this
    ->dsEditFormatterSettings($edit);
  drupal_flush_all_caches();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/span[@class="ow-class-2"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
}