You are here

public function FieldTemplateTest::testDsFieldTemplate2 in Display Suite 8.2

Tests on field templates.

File

src/Tests/FieldTemplateTest.php, line 62

Class

FieldTemplateTest
Tests for display of nodes and fields.

Namespace

Drupal\ds\Tests

Code

public function testDsFieldTemplate2() {

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

  // Reset theming function.
  $edit = array(
    '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());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->div->p, $body_field);
  $this
    ->entitiesSetLabelClass('above', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-above"]');
  $this
    ->assertTrimEqual($xpath[0], 'Body');
  $this
    ->entitiesSetLabelClass('inline', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($xpath[0], 'Body');
  $this
    ->entitiesSetLabelClass('above', 'body', 'My body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-above"]');
  $this
    ->assertTrimEqual($xpath[0], 'My body');
  $this
    ->entitiesSetLabelClass('inline', 'body', 'My body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($xpath[0], 'My body');
  $edit = array(
    '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());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
  $xpath = $this
    ->xpath('//div[@class="group-right"]/div[@class="field-label-inline"]');
  $this
    ->assertTrimEqual($xpath[0], 'My body:');
  $this
    ->entitiesSetLabelClass('hidden', 'body');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $xpath = $this
    ->xpath('//div[@class="group-right"]');
  $this
    ->assertTrimEqual($xpath[0]->p, $body_field);
}