diff -u b/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php --- b/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -12,6 +12,9 @@ use Drupal\Core\Url; use Drupal\link\LinkItemInterface; use Drupal\simpletest\WebTestBase; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\field\Entity\FieldConfig; +use Drupal\Core\Entity\Entity\EntityFormDisplay; /** * Tests link field widgets and formatters. @@ -57,13 +60,13 @@ function testURLValidation() { $field_name = Unicode::strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $this->fieldStorage = FieldStorageConfig::create(['field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link', - )); + )]); $this->fieldStorage->save(); - $this->field = entity_create('field_config', array( + $this->field = FieldConfig::create('field_config', array( 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'settings' => array( @@ -72,7 +75,7 @@ ), )); $this->field->save(); - entity_get_form_display('entity_test', 'entity_test', 'default') + EntityFormDisplay::load('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', 'settings' => array( @@ -218,13 +221,13 @@ function testLinkTitle() { $field_name = Unicode::strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $this->fieldStorage = FieldStorageConfig::create(['field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link', - )); + )]); $this->fieldStorage->save(); - $this->field = entity_create('field_config', array( + $this->field = FieldConfig::create('field_config', array( 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'label' => 'Read more about this entity', @@ -234,7 +237,7 @@ ), )); $this->field->save(); - entity_get_form_display('entity_test', 'entity_test', 'default') + EntityFormDisplay::load('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', 'settings' => array( @@ -332,14 +335,14 @@ function testLinkFormatter() { $field_name = Unicode::strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $this->fieldStorage = FieldStorageConfig::create(['field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link', 'cardinality' => 2, - )); + )]); $this->fieldStorage->save(); - entity_create('field_config', array( + FieldConfig::create('field_config', array( 'field_storage' => $this->fieldStorage, 'label' => 'Read more about this entity', 'bundle' => 'entity_test', @@ -348,7 +351,7 @@ 'link_type' => LinkItemInterface::LINK_GENERIC, ), ))->save(); - entity_get_form_display('entity_test', 'entity_test', 'default') + EntityFormDisplay::load('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', )) @@ -472,14 +475,14 @@ function testLinkSeparateFormatter() { $field_name = Unicode::strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $this->fieldStorage = FieldStorageConfig::create(['field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link', 'cardinality' => 2, - )); + )]); $this->fieldStorage->save(); - entity_create('field_config', array( + FieldConfig::create('field_config', array( 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'settings' => array( @@ -491,7 +494,7 @@ 'type' => 'link_separate', 'label' => 'hidden', ); - entity_get_form_display('entity_test', 'entity_test', 'default') + EntityFormDisplay::load('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', )) @@ -593,16 +596,19 @@ $this->verbose($output); } + /** + * Check link text is required. + */ function testRequiredLinkText() { $field_name = Unicode::strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $this->fieldStorage = FieldStorageConfig::create(['field_storage_config', array( 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link', - )); + )]); $this->fieldStorage->save(); - $this->field = entity_create('field_config', array( + $this->field = FieldConfig::create('field_config', array( 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'label' => 'Read more about this entity', @@ -613,7 +619,7 @@ ), )); $this->field->save(); - entity_get_form_display('entity_test', 'entity_test', 'default') + EntityFormDisplay::load('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( 'type' => 'link_default', 'settings' => array( @@ -625,7 +631,7 @@ // Display creation form. $this->drupalGet('entity_test/add'); - $this->drupalPostForm(NULL, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); $result = $this->xpath('//label[contains(@class, :class) and contains(text(), :text)]', array(':class' => 'form-required', ':text' => 'Link text')); $this->assertEqual(count($result), 1, "Link text is marked as required when the link field is set to required.");