public function TwigRenderTest::testFieldNameTargeting in Display Suite 8.4
Same name and namespace in other branches
- 8.3 tests/src/Functional/TwigRenderTest.php \Drupal\Tests\ds\Functional\TwigRenderTest::testFieldNameTargeting()
Tests targeting the field in a twig template.
File
- tests/
src/ Functional/ TwigRenderTest.php, line 15
Class
- TwigRenderTest
- Tests for twig specific functionality.
Namespace
Drupal\Tests\ds\FunctionalCode
public function testFieldNameTargeting() {
// Create a node.
$settings = [
'type' => 'article',
'promote' => 1,
];
/* @var \Drupal\node\NodeInterface $node */
$node = $this
->drupalCreateNode($settings);
// Configure layout.
$layout = [
'ds_layout' => 'dstest_1col_title',
];
$layout_assert = [
'regions' => [
'ds_content' => '<td colspan="8">' . t('Content') . '</td>',
],
];
$this
->dsSelectLayout($layout, $layout_assert);
$fields = [
'fields[node_title][region]' => 'ds_content',
];
$this
->dsConfigureUi($fields);
$this
->drupalGet('node/' . $node
->id());
// Assert that the title is visible.
$elements = $this
->xpath('//div[@class="field field--name-node-title field--type-ds field--label-hidden field__item"]/h2');
$this
->assertEquals(count($elements), 1);
$this
->assertSession()
->pageTextContains($node
->getTitle());
$edit = [
'fs3[use_field_names]' => FALSE,
];
$this
->drupalGet('admin/structure/ds/settings');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('node/' . $node
->id());
// Assert that the title is not visible anymore.
$elements = $this
->xpath('//div[@class="field field--name-node-title field--type-ds field--label-hidden field__item"]/h2');
$this
->assertEquals(count($elements), 0);
}