public function OptionsFieldUITest::testNodeDisplay in Drupal 8
Same name and namespace in other branches
- 9 core/modules/options/tests/src/Functional/OptionsFieldUITest.php \Drupal\Tests\options\Functional\OptionsFieldUITest::testNodeDisplay()
Tests normal and key formatter display on node display.
File
- core/
modules/ options/ tests/ src/ Functional/ OptionsFieldUITest.php, line 336
Class
- OptionsFieldUITest
- Tests the Options field UI functionality.
Namespace
Drupal\Tests\options\FunctionalCode
public function testNodeDisplay() {
$this->fieldName = strtolower($this
->randomMachineName());
$this
->createOptionsField('list_integer');
$node = $this
->drupalCreateNode([
'type' => $this->type,
]);
$on = $this
->randomMachineName();
$off = $this
->randomMachineName();
$edit = [
'settings[allowed_values]' => "1|{$on}\n 0|{$off}",
];
$this
->drupalPostForm($this->adminPath, $edit, t('Save field settings'));
$this
->assertText(new FormattableMarkup('Updated field @field_name field settings.', [
'@field_name' => $this->fieldName,
]), "The 'On' and 'Off' form fields work for boolean fields.");
// Select a default value.
$edit = [
$this->fieldName => '1',
];
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save'));
// Check the node page and see if the values are correct.
$file_formatters = [
'list_default',
'list_key',
];
foreach ($file_formatters as $formatter) {
$edit = [
"fields[{$this->fieldName}][type]" => $formatter,
"fields[{$this->fieldName}][region]" => 'content',
];
$this
->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/display', $edit, t('Save'));
$this
->drupalGet('node/' . $node
->id());
if ($formatter == 'list_default') {
$output = $on;
}
else {
$output = '1';
}
$elements = $this
->xpath('//div[text()="' . $output . '"]');
$this
->assertCount(1, $elements, 'Correct options found.');
}
}