You are here

public function FieldTemplateTest::testDsFieldTemplate3 in Display Suite 8.2

Tests on field templates.

File

src/Tests/FieldTemplateTest.php, line 130

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\ds\Tests

Code

public function testDsFieldTemplate3() {

  // Get a node.
  $node = $this
    ->entitiesTestSetup('hidden');
  $body_field = $node->body->value;

  // Custom field function with outer wrapper.
  $edit = array(
    '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());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->div->p, $body_field);

  // With outer div wrapper and class.
  $edit = array(
    '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());
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="ow-class"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);

  // With outer span wrapper and class.
  $edit = array(
    '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());
  $xpath = $this
    ->xpath('//div[@class="group-right"]/span[@class="ow-class-2"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
}