public function FieldTemplateTest::testDsFieldTemplate2 in Display Suite 8.4
Tests on field templates.
File
- tests/
src/ Functional/ FieldTemplateTest.php, line 63
Class
- FieldTemplateTest
- Tests for display of nodes and fields.
Namespace
Drupal\Tests\ds\FunctionalCode
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
->drupalGet('admin/structure/ds/settings');
$this
->submitForm($edit, '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
->drupalGet('admin/structure/ds/settings');
$this
->submitForm($edit, '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);
}