diff --git a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php index 337667c..aa49915 100644 --- a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php @@ -37,15 +37,4 @@ protected function getTranslatorPermissions() { return array_merge(parent::getTranslatorPermissions(), array('administer entity_test content')); } - /** - * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getNewEntityValues(). - */ - protected function getNewEntityValues($langcode) { - $user = $this->drupalCreateUser(); - return array( - 'name' => $this->randomMachineName(), - 'user_id' => $user->id(), - ) + parent::getNewEntityValues($langcode); - } - } diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index 2a45c4a..27ab2c6 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -101,8 +101,6 @@ function testDateField() { $time_format = entity_load('date_format', 'html_time')->getPattern(); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value][date]" => $date->format($date_format), ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -170,8 +168,6 @@ function testDatetimeField() { $time_format = entity_load('date_format', 'html_time')->getPattern(); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value][date]" => $date->format($date_format), "{$field_name}[0][value][time]" => $date->format($time_format), ); @@ -258,10 +254,7 @@ function testDatelistWidget() { // Submit a valid date and ensure it is accepted. $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15); - $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), - ); + $edit = array(); // Add the ampm indicator since we are testing 12 hour time. $date_value['ampm'] = 'am'; foreach ($date_value as $part => $value) { diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php index f13cc5d..d1c59ac 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php @@ -59,7 +59,6 @@ protected function setUp() { * Tests the entity reference field with all its supported field widgets. */ public function testSupportedEntityTypesAndWidgets() { - $user_id = mt_rand(128, 256); foreach ($this->getTestEntities() as $referenced_entities) { $this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId(); @@ -69,15 +68,9 @@ public function testSupportedEntityTypesAndWidgets() { // Test the default 'entity_reference_autocomplete' widget. entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save(); - $user_id++; - entity_create('user', array( - 'uid' => $user_id, - 'name' => $this->randomString(), - ))->save(); $entity_name = $this->randomMachineName(); $edit = array( - 'name' => $entity_name, - 'user_id' => $user_id, + 'name[0][value]' => $entity_name, $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', // Test an input of the entity label without a ' (entity_id)' suffix. $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(), @@ -100,14 +93,8 @@ public function testSupportedEntityTypesAndWidgets() { $target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'; // Test an input of the entity label without a ' (entity_id)' suffix. $target_id .= ', ' . $referenced_entities[1]->label(); - $user_id++; - entity_create('user', array( - 'uid' => $user_id, - 'name' => $this->randomString(), - ))->save(); $edit = array( - 'name' => $entity_name, - 'user_id' => $user_id, + 'name[0][value]' => $entity_name, $this->fieldName . '[target_id]' => $target_id, ); $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); @@ -122,8 +109,7 @@ public function testSupportedEntityTypesAndWidgets() { // Test all the other widgets supported by the entity reference field. // Since we don't know the form structure for these widgets, just test // that editing and saving an already created entity works. - // Also exclude the special author reference widgets. - $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags', 'route_based_autocomplete', 'author_autocomplete'); + $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags'); $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name))); $supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference'); $supported_widget_types = array_diff(array_keys($supported_widgets), $exclude); diff --git a/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php b/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php index ca44975..2713521 100644 --- a/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php +++ b/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php @@ -49,6 +49,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views')); diff --git a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php index 85c0746..22e2852 100644 --- a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php +++ b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php @@ -103,8 +103,6 @@ function testBooleanField() { // Submit and ensure it is accepted. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[value]" => 1, ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/field/src/Tests/Email/EmailFieldTest.php b/core/modules/field/src/Tests/Email/EmailFieldTest.php index 738c2d7..d51b698 100644 --- a/core/modules/field/src/Tests/Email/EmailFieldTest.php +++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php @@ -90,8 +90,6 @@ function testEmailField() { // Submit a valid email address and ensure it is accepted. $value = 'test@example.com'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php index 67ca02e..c69ee2d 100644 --- a/core/modules/field/src/Tests/FieldUnitTestBase.php +++ b/core/modules/field/src/Tests/FieldUnitTestBase.php @@ -53,6 +53,17 @@ protected function setUp() { // Set default storage backend and configure the theme system. $this->installConfig(array('field', 'system')); + + // Create user 1. + $storage = \Drupal::entityManager()->getStorage('user'); + $storage + ->create(array( + 'uid' => 1, + 'name' => 'entity-test', + 'mail' => 'entity@localhost', + 'status' => TRUE, + )) + ->save(); } /** diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index bea7e14..8000c68 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -114,8 +114,6 @@ function testFieldFormSingle() { // Submit with invalid value (field-level validation). $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => -1 ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -125,8 +123,6 @@ function testFieldFormSingle() { // Create an entity $value = mt_rand(1, 127); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -144,8 +140,6 @@ function testFieldFormSingle() { // Update the entity. $value = mt_rand(1, 127); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -157,8 +151,6 @@ function testFieldFormSingle() { // Empty the field. $value = ''; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value ); $this->drupalPostForm('entity_test/manage/' . $id, $edit, t('Save')); @@ -190,8 +182,6 @@ function testFieldFormDefaultValue() { // Try to submit an empty value. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => '', ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -221,8 +211,6 @@ function testFieldFormSingleRequired() { // Create an entity $value = mt_rand(1, 127); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -235,8 +223,6 @@ function testFieldFormSingleRequired() { // Edit with missing required value. $value = ''; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm('entity_test/manage/' . $id, $edit, t('Save')); @@ -280,10 +266,7 @@ function testFieldFormUnlimited() { $count = 3; $delta_range = $count - 1; $values = $weights = $pattern = $expected_values = array(); - $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), - ); + $edit = array(); for ($delta = 0; $delta <= $delta_range; $delta++) { // Assign unique random values and weights. do { @@ -463,8 +446,6 @@ function testFieldFormMultipleWidget() { // Create entity with three values. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), $field_name => '1, 2, 3', ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -543,8 +524,6 @@ function testFieldFormAccess() { // Create entity. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => 1, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -558,8 +537,6 @@ function testFieldFormAccess() { // Create a new revision. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => 2, 'revision' => TRUE, ); @@ -601,7 +578,7 @@ function testHiddenField() { // Create an entity and test that the default value is assigned correctly to // the field that uses the hidden widget. $this->assertNoField("{$field_name}[0][value]", 'The field does not appear in the form'); - $this->drupalPostForm(NULL, array('user_id' => 1, 'name' => $this->randomMachineName()), t('Save')); + $this->drupalPostForm(NULL, array(), t('Save')); preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match); $id = $match[1]; $this->assertText(t('entity_test_rev @id has been created.', array('@id' => $id)), 'Entity was created'); diff --git a/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php index 82b69d2..a243373 100644 --- a/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -79,8 +79,6 @@ function testNumberDecimalField() { // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -172,8 +170,6 @@ function testNumberIntegerField() { // Submit a valid integer $value = rand($minimum, $maximum); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -184,8 +180,6 @@ function testNumberIntegerField() { // Try to set a value below the minimum value $this->drupalGet('entity_test/add'); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $minimum - 1, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -194,8 +188,6 @@ function testNumberIntegerField() { // Try to set a decimal value $this->drupalGet('entity_test/add'); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => 1.5, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -204,8 +196,6 @@ function testNumberIntegerField() { // Try to set a value above the maximum value $this->drupalGet('entity_test/add'); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $maximum + 1, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -221,8 +211,6 @@ function testNumberIntegerField() { foreach ($valid_entries as $valid_entry) { $this->drupalGet('entity_test/add'); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $valid_entry, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -274,8 +262,6 @@ function testNumberFloatField() { // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/field/src/Tests/TranslationWebTest.php b/core/modules/field/src/Tests/TranslationWebTest.php index 6646072..2778ff7 100644 --- a/core/modules/field/src/Tests/TranslationWebTest.php +++ b/core/modules/field/src/Tests/TranslationWebTest.php @@ -109,8 +109,6 @@ function testFieldFormTranslationRevisions() { // Create a new revision. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $entity->{$field_name}->value, 'revision' => TRUE, ); diff --git a/core/modules/hal/src/Tests/NormalizeTest.php b/core/modules/hal/src/Tests/NormalizeTest.php index 2d15299..00d6687 100644 --- a/core/modules/hal/src/Tests/NormalizeTest.php +++ b/core/modules/hal/src/Tests/NormalizeTest.php @@ -36,7 +36,6 @@ public function testNormalize() { $values = array( 'langcode' => 'de', 'name' => $this->randomMachineName(), - 'user_id' => 1, 'field_test_text' => array( 'value' => $this->randomMachineName(), 'format' => 'full_html', diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index c7eb596..fb87d73 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -149,8 +149,6 @@ function testURLValidation() { protected function assertValidEntries($field_name, array $valid_entries) { foreach ($valid_entries as $value) { $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][url]" => $value, ); $this->drupalPostForm('entity_test/add', $edit, t('Save')); @@ -172,8 +170,6 @@ protected function assertValidEntries($field_name, array $valid_entries) { protected function assertInvalidEntries($field_name, array $invalid_entries) { foreach ($invalid_entries as $invalid_value) { $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][url]" => $invalid_value, ); $this->drupalPostForm('entity_test/add', $edit, t('Save')); @@ -270,8 +266,6 @@ function testLinkTitle() { // Verify that a link without link text is rendered using the URL as text. $value = 'http://www.example.com/'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][url]" => $value, "{$field_name}[0][title]" => '', ); @@ -287,8 +281,6 @@ function testLinkTitle() { // Verify that a link with text is rendered using the link text. $title = $this->randomMachineName(); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][title]" => $title, ); $this->drupalPostForm("entity_test/manage/$id", $edit, t('Save')); @@ -346,8 +338,6 @@ function testLinkFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][url]" => $url1, // Note that $title1 is not submitted. "{$field_name}[0][title]" => '', @@ -486,8 +476,6 @@ function testLinkSeparateFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][url]" => $url1, "{$field_name}[1][url]" => $url2, "{$field_name}[1][title]" => $title2, diff --git a/core/modules/quickedit/src/Tests/QuickEditTestBase.php b/core/modules/quickedit/src/Tests/QuickEditTestBase.php index 4f4ece7..e4a5416 100644 --- a/core/modules/quickedit/src/Tests/QuickEditTestBase.php +++ b/core/modules/quickedit/src/Tests/QuickEditTestBase.php @@ -42,6 +42,7 @@ protected function setUp() { $this->fields = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS); + $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); $this->installConfig(array('field', 'filter')); } diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/src/Tests/Entity/EntityFormTest.php index a60c53e..e7b21c6 100644 --- a/core/modules/system/src/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php @@ -61,8 +61,7 @@ protected function assertFormCRUD($entity_type) { $name2 = $this->randomMachineName(10); $edit = array( - 'name' => $name1, - 'user_id' => mt_rand(0, 128), + 'name[0][value]' => $name1, 'field_test_text[0][value]' => $this->randomMachineName(16), ); @@ -70,7 +69,7 @@ protected function assertFormCRUD($entity_type) { $entity = $this->loadEntityByName($entity_type, $name1); $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type))); - $edit['name'] = $name2; + $edit['name[0][value]'] = $name2; $this->drupalPostForm($entity_type . '/manage/' . $entity->id(), $edit, t('Save')); $entity = $this->loadEntityByName($entity_type, $name1); $this->assertFalse($entity, format_string('%entity_type: The entity has been modified.', array('%entity_type' => $entity_type))); diff --git a/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php b/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php index 5eb2858..d484c8b 100644 --- a/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php +++ b/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php @@ -98,7 +98,7 @@ protected function assertRevisions($entity_type) { // Confirm the correct revision text appears in the edit form. $entity = entity_load($entity_type, $entity->id->value); $this->drupalGet($entity_type . '/manage/' . $entity->id->value); - $this->assertFieldById('edit-name', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type))); + $this->assertFieldById('edit-name-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type))); $this->assertFieldById('edit-field-test-text-0-value', $entity->field_test_text->value, format_string('%entity_type: Text matches in UI.', array('%entity_type' => $entity_type))); } } diff --git a/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php b/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php index 2986920..721b8d3 100644 --- a/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php +++ b/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php @@ -9,14 +9,14 @@ use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageException; -use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\simpletest\KernelTestBase; /** * Tests KeyValueEntityStorage for content entities. * * @group KeyValueStore */ -class KeyValueContentEntityStorageTest extends DrupalUnitTestBase { +class KeyValueContentEntityStorageTest extends KernelTestBase { /** * Modules to enable. @@ -26,6 +26,14 @@ class KeyValueContentEntityStorageTest extends DrupalUnitTestBase { public static $modules = array('entity', 'user', 'entity_test', 'keyvalue_test'); /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('user'); + } + + /** * Tests CRUD operations. */ function testCRUD() { diff --git a/core/modules/system/tests/modules/entity_test/entity_test.info.yml b/core/modules/system/tests/modules/entity_test/entity_test.info.yml index bd4382e..8d3200c 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.info.yml +++ b/core/modules/system/tests/modules/entity_test/entity_test.info.yml @@ -7,3 +7,4 @@ core: 8.x dependencies: - field - text + - entity_reference diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php index 3993dcf..34dc997 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php @@ -88,6 +88,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { 'label' => 'hidden', 'type' => 'string', 'weight' => -5, + )) + ->setDisplayOptions('form', array( + 'type' => 'string', + 'weight' => -5, )); // @todo: Add allowed values validation. @@ -99,8 +103,22 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The ID of the associated user.')) - ->setSettings(array('target_type' => 'user')) - ->setTranslatable(TRUE); + ->setSetting('target_type', 'user') + ->setSetting('handler', 'default') + // Default EntityTest entities to have the root user as the owner, to + // simplify testing. + ->setDefaultValue(array(0 => 1)) + ->setTranslatable(TRUE) + ->setDisplayOptions('form', array( + 'type' => 'entity_reference_autocomplete', + 'weight' => -1, + 'settings' => array( + 'match_operator' => 'CONTAINS', + 'size' => '60', + 'autocomplete_type' => 'tags', + 'placeholder' => '', + ), + )); return $fields; } diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index 6845520..1db41d4 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -6,6 +6,7 @@ namespace Drupal\entity_test; +use Drupal\Component\Utility\Random; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -18,30 +19,22 @@ class EntityTestForm extends ContentEntityForm { /** * {@inheritdoc} */ + protected function prepareEntity() { + if (empty($this->entity->name->value)) { + // Assign a random name to new EntityTest entities, to avoid repetition in + // tests. + $random = new Random(); + $this->entity->name->value = $random->name(); + } + } + + /** + * {@inheritdoc} + */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entity = $this->entity; - $form['name'] = array( - '#type' => 'textfield', - '#title' => t('Name'), - '#default_value' => $entity->name->value, - '#size' => 60, - '#maxlength' => 128, - '#required' => TRUE, - '#weight' => -10, - ); - - $form['user_id'] = array( - '#type' => 'textfield', - '#title' => 'UID', - '#default_value' => $entity->user_id->target_id, - '#size' => 60, - '#maxlength' => 128, - '#required' => TRUE, - '#weight' => -10, - ); - $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', diff --git a/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php index 4588587..224d2b6 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php @@ -86,8 +86,6 @@ function testTaxonomyTermFieldMultipleVocabularies() { // used to ignore the value check. $this->assertFieldByName("{$this->field_name}[]", NULL, 'Widget is displayed.'); $edit = array( - 'user_id' => mt_rand(0, 10), - 'name' => $this->randomMachineName(), "{$this->field_name}[]" => array($term1->id(), $term2->id()), ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -128,8 +126,6 @@ function testTaxonomyTermFieldMultipleVocabularies() { // Term 1 should still pass validation. $edit = array( - 'user_id' => mt_rand(0, 10), - 'name' => $this->randomMachineName(), "{$this->field_name}[]" => array($term1->id()), ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/taxonomy/src/Tests/TermFieldTest.php b/core/modules/taxonomy/src/Tests/TermFieldTest.php index fa0f007..41ad7a5 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php @@ -109,8 +109,6 @@ function testTaxonomyTermFieldWidgets() { // Submit with some value. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), $this->field_name => array($term->id()), ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 330d9f8..bbf341f 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -121,8 +121,6 @@ function _testTextfieldWidgets($field_type, $widget_type) { // Submit with some value. $value = $this->randomMachineName(); $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -193,8 +191,6 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Submit with data that should be filtered. $value = '' . $this->randomMachineName() . ''; $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -235,8 +231,6 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Edit and change the text format to the new one that was created. $edit = array( - 'user_id' => 1, - 'name' => $this->randomMachineName(), "{$field_name}[0][format]" => $format_id, ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/views/src/Tests/QueryGroupByTest.php b/core/modules/views/src/Tests/QueryGroupByTest.php index b6132fc..5958e8d 100644 --- a/core/modules/views/src/Tests/QueryGroupByTest.php +++ b/core/modules/views/src/Tests/QueryGroupByTest.php @@ -43,6 +43,7 @@ class QueryGroupByTest extends ViewUnitTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('user'); $this->installEntitySchema('entity_test'); $this->storage = $this->container->get('entity.manager')->getStorage('entity_test');