public function OptionsFieldUITest::testNodeDisplay in Drupal 9
Same name and namespace in other branches
- 8 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 337
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
->drupalGet($this->adminPath);
$this
->submitForm($edit, 'Save field settings');
$this
->assertSession()
->pageTextContains('Updated field ' . $this->fieldName . ' field settings.');
// Select a default value.
$edit = [
$this->fieldName => '1',
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, '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
->drupalGet('admin/structure/types/manage/' . $this->typeName . '/display');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('node/' . $node
->id());
if ($formatter == 'list_default') {
$output = $on;
}
else {
$output = '1';
}
// Verify that correct options are found.
$this
->assertSession()
->elementsCount('xpath', '//div[text()="' . $output . '"]', 1);
}
}