You are here

public function FieldTemplateTest::testDsFieldTemplate in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FieldTemplateTest.php \Drupal\Tests\ds\Functional\FieldTemplateTest::testDsFieldTemplate()

Tests on field templates.

File

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

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function testDsFieldTemplate() {

  // Get a node.

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

  // Default theming function.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $this
    ->entitiesSetLabelClass('above', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above"]/div[@class="field__label"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'Body');
  $elements = $this
    ->xpath('//div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above"]/div[@class="field__item"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $this
    ->entitiesSetLabelClass('above', 'body', 'My body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above"]/div[@class="field__label"]');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), 'My body');
  $elements = $this
    ->xpath('//div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above"]/div[@class="field__item"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
  $this
    ->entitiesSetLabelClass('hidden', 'body', '', 'test_field_class');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $elements = $this
    ->xpath('//div[@class="test_field_class clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"]/p');
  $this
    ->assertTrimEqual($elements[0]
    ->getText(), $body_field);
}