X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flink%2Ftests%2Fsrc%2FFunctional%2FLinkFieldTest.php;h=c99ad0a931060dd097df970092a13408ec647239;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=67aee9c3b9543e3ee54c3d6d24a6c369ceee69a8;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/link/tests/src/Functional/LinkFieldTest.php b/web/core/modules/link/tests/src/Functional/LinkFieldTest.php index 67aee9c3b..c99ad0a93 100644 --- a/web/core/modules/link/tests/src/Functional/LinkFieldTest.php +++ b/web/core/modules/link/tests/src/Functional/LinkFieldTest.php @@ -606,6 +606,49 @@ class LinkFieldTest extends BrowserTestBase { } } + /** + * Test '#link_type' property exists on 'link_default' widget. + * + * Make sure the 'link_default' widget exposes a '#link_type' property on + * its element. Modules can use it to understand if a text form element is + * a link and also which LinkItemInterface::LINK_* is (EXTERNAL, GENERIC, + * INTERNAL). + */ + public function testLinkTypeOnLinkWidget() { + + $link_type = LinkItemInterface::LINK_EXTERNAL; + $field_name = Unicode::strtolower($this->randomMachineName()); + + // Create a field with settings to validate. + $this->fieldStorage = FieldStorageConfig::create([ + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'type' => 'link', + 'cardinality' => 1, + ]); + $this->fieldStorage->save(); + FieldConfig::create([ + 'field_storage' => $this->fieldStorage, + 'label' => 'Read more about this entity', + 'bundle' => 'entity_test', + 'settings' => [ + 'title' => DRUPAL_OPTIONAL, + 'link_type' => $link_type, + ], + ])->save(); + + $this->container->get('entity.manager') + ->getStorage('entity_form_display') + ->load('entity_test.entity_test.default') + ->setComponent($field_name, [ + 'type' => 'link_default', + ]) + ->save(); + + $form = \Drupal::service('entity.form_builder')->getForm(EntityTest::create()); + $this->assertEqual($form[$field_name]['widget'][0]['uri']['#link_type'], $link_type); + } + /** * Tests editing a link to a non-node entity.