function LinkFieldWidgetTest::testDefaultValues
Verify that default values are applied to the uri subfield.
File
-
core/
modules/ link/ tests/ src/ Kernel/ LinkFieldWidgetTest.php, line 133
Class
- LinkFieldWidgetTest
- Tests link field widgets.
Namespace
Drupal\Tests\link\KernelCode
public function testDefaultValues() : void {
$formBuilder = $this->container
->get('entity.form_builder');
$linkTypes = [
LinkItemInterface::LINK_INTERNAL => 'internal:/node/add',
LinkItemInterface::LINK_EXTERNAL => 'https://example.com',
LinkItemInterface::LINK_GENERIC => '',
];
foreach ($linkTypes as $linkType => $defaultValue) {
$field = $this->entitySetUp($linkType, LinkTitleVisibility::Disabled, 1, $defaultValue);
$form = $formBuilder->getForm(EntityTest::create());
// Normalize internal URIs.
if ($linkType === LinkItemInterface::LINK_INTERNAL) {
$defaultValue = substr($defaultValue, 9);
}
$this->assertEquals($defaultValue, $form[$field]['widget'][0]['uri']['#value']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.