You are here

public function FieldTemplateTest::_testDsFieldTemplate2 in Display Suite 8.3

Tests on field templates.

File

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

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function _testDsFieldTemplate2() {

  // Get a node.

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

  // Reset theming function.
  $edit = [
    'fs1[ft-default]' => 'reset',
  ];
  $this
    ->drupalPostForm('admin/structure/ds/settings', $edit, t('Save configuration'));

  // 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);
  $this
    ->entitiesSetLabelClass('above', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-above"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'Body');
  $this
    ->entitiesSetLabelClass('inline', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'Body');
  $this
    ->entitiesSetLabelClass('above', 'body', 'My body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-above"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'My body');
  $this
    ->entitiesSetLabelClass('inline', 'body', 'My body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'My body');
  $edit = [
    'fs1[ft-show-colon]' => 'reset',
  ];
  $this
    ->drupalPostForm('admin/structure/ds/settings', $edit, t('Save configuration'));

  // Clear node cache to get the colon.
  $tags = $node
    ->getCacheTags();
  Cache::invalidateTags($tags);
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $elements = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'My body:');
  $this
    ->entitiesSetLabelClass('hidden', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="group-right"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
}