public function WebformOptionsCustomEntityTest::testOptionsCustomEntity in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_options_custom/tests/src/Functional/WebformOptionsCustomEntityTest.php \Drupal\Tests\webform_options_custom\Functional\WebformOptionsCustomEntityTest::testOptionsCustomEntity()
Test options custom entity.
File
- modules/
webform_options_custom/ tests/ src/ Functional/ WebformOptionsCustomEntityTest.php, line 29
Class
- WebformOptionsCustomEntityTest
- Webform options custom entity test.
Namespace
Drupal\Tests\webform_options_custom\FunctionalCode
public function testOptionsCustomEntity() {
$webform = Webform::load('test_element_options_custom_ent');
$node = Node::load(1);
$this
->drupalGet('/webform/test_element_options_custom_ent');
// Check that data-option-value is populated with the node ids.
$this
->assertRaw('<div data-name="Room 1" data-option-value="1">Room 1</div>');
$this
->assertRaw('<div data-name="Room 2" data-option-value="2">Room 2</div>');
$this
->assertRaw('<div data-name="Room 3" data-option-value="3">Room 3</div>');
// Check that data-descriptions are populated with the node titles.
$this
->assertRaw('data-descriptions="{"1":"This is room number #1. [1 remaining]","2":"This is room number #2. [1 remaining]","3":"This is room number #3. [1 remaining]"}"');
// Check that node link is used in the preview.
// Please note that the description is used in the node's title.
$this
->postSubmission($webform, [
'webform_options_custom_entity[select][]' => '1',
], 'Preview');
$this
->assertRaw('<a href="' . $node
->toUrl()
->setAbsolute()
->toString() . '" hreflang="en">Room 1 -- This is room number #1.</a>');
}