From f749eac343ed59483d103ef7442599c35747fa0f Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 9 Sep 2014 14:21:09 +0100 Subject: [PATCH] Revert "Issue #2238149 by Berdir: Apply formatters and widgets in EntityTestFormCotroller." This reverts commit 3ac426f9cbb63fe28b0d0a67f64f8b683e0a384b. --- .../Tests/ContentTestTranslationUITest.php | 11 +++++++ .../datetime/src/Tests/DateTimeFieldTest.php | 9 ++++- .../Tests/EntityReferenceIntegrationTest.php | 20 +++++++++-- .../Views/EntityReferenceRelationshipTest.php | 1 - .../src/Tests/Boolean/BooleanFieldTest.php | 2 ++ .../field/src/Tests/Email/EmailFieldTest.php | 2 ++ core/modules/field/src/Tests/FormTest.php | 27 +++++++++++++-- .../src/Tests/Number/NumberFieldTest.php | 14 ++++++++ .../field/src/Tests/TranslationWebTest.php | 2 ++ core/modules/hal/src/Tests/NormalizeTest.php | 1 + core/modules/link/src/Tests/LinkFieldTest.php | 12 +++++++ .../quickedit/src/Tests/QuickEditTestBase.php | 1 - .../src/Tests/Entity/EntityFormTest.php | 5 +-- .../src/Tests/Entity/EntityRevisionsTest.php | 2 +- .../KeyValueContentEntityStorageTest.php | 12 ++----- .../modules/entity_test/entity_test.info.yml | 1 - .../entity_test/src/Entity/EntityTest.php | 22 ++----------- .../entity_test/src/EntityTestForm.php | 33 +++++++++++-------- .../Tests/TermFieldMultipleVocabularyTest.php | 4 +++ .../taxonomy/src/Tests/TermFieldTest.php | 2 ++ core/modules/text/src/Tests/TextFieldTest.php | 6 ++++ .../views/src/Tests/QueryGroupByTest.php | 1 - .../Drupal/Tests/Core/Form/FormCacheTest.php | 20 ++++++++++- 23 files changed, 153 insertions(+), 57 deletions(-) diff --git a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php index aa499159c71..337667cc575 100644 --- a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php @@ -37,4 +37,15 @@ class ContentTestTranslationUITest extends ContentTranslationUITest { 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 27ab2c65978..2a45c4a4591 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -101,6 +101,8 @@ class DateTimeFieldTest extends WebTestBase { $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')); @@ -168,6 +170,8 @@ class DateTimeFieldTest extends WebTestBase { $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), ); @@ -254,7 +258,10 @@ class DateTimeFieldTest extends WebTestBase { // Submit a valid date and ensure it is accepted. $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15); - $edit = array(); + $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), + ); // 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 d1c59accc9e..f13cc5d25c5 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php @@ -59,6 +59,7 @@ class EntityReferenceIntegrationTest extends WebTestBase { * 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(); @@ -68,9 +69,15 @@ class EntityReferenceIntegrationTest extends WebTestBase { // 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[0][value]' => $entity_name, + 'name' => $entity_name, + 'user_id' => $user_id, $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(), @@ -93,8 +100,14 @@ class EntityReferenceIntegrationTest extends WebTestBase { $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[0][value]' => $entity_name, + 'name' => $entity_name, + 'user_id' => $user_id, $this->fieldName . '[target_id]' => $target_id, ); $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); @@ -109,7 +122,8 @@ class EntityReferenceIntegrationTest extends WebTestBase { // 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. - $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags'); + // Also exclude the special author reference widgets. + $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags', 'route_based_autocomplete', 'author_autocomplete'); $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 27135211a60..ca44975298d 100644 --- a/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php +++ b/core/modules/entity_reference/src/Tests/Views/EntityReferenceRelationshipTest.php @@ -49,7 +49,6 @@ 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 22e28527883..85c07466122 100644 --- a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php +++ b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php @@ -103,6 +103,8 @@ class BooleanFieldTest extends WebTestBase { // 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 d51b698a2b1..738c2d7eabd 100644 --- a/core/modules/field/src/Tests/Email/EmailFieldTest.php +++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php @@ -90,6 +90,8 @@ class EmailFieldTest extends WebTestBase { // 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/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 8000c688324..bea7e14e9da 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -114,6 +114,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -123,6 +125,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -140,6 +144,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -151,6 +157,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -182,6 +190,8 @@ class FormTest extends FieldTestBase { // Try to submit an empty value. $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => '', ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -211,6 +221,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -223,6 +235,8 @@ class FormTest extends FieldTestBase { // 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')); @@ -266,7 +280,10 @@ class FormTest extends FieldTestBase { $count = 3; $delta_range = $count - 1; $values = $weights = $pattern = $expected_values = array(); - $edit = array(); + $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), + ); for ($delta = 0; $delta <= $delta_range; $delta++) { // Assign unique random values and weights. do { @@ -446,6 +463,8 @@ class FormTest extends FieldTestBase { // Create entity with three values. $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), $field_name => '1, 2, 3', ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -524,6 +543,8 @@ class FormTest extends FieldTestBase { // Create entity. $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => 1, ); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -537,6 +558,8 @@ class FormTest extends FieldTestBase { // Create a new revision. $edit = array( + 'user_id' => 1, + 'name' => $this->randomMachineName(), "{$field_name}[0][value]" => 2, 'revision' => TRUE, ); @@ -578,7 +601,7 @@ class FormTest extends FieldTestBase { // 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(), t('Save')); + $this->drupalPostForm(NULL, array('user_id' => 1, 'name' => $this->randomMachineName()), 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 a2433737c0f..82b69d29924 100644 --- a/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -79,6 +79,8 @@ class NumberFieldTest extends WebTestBase { // 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')); @@ -170,6 +172,8 @@ class NumberFieldTest extends WebTestBase { // 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')); @@ -180,6 +184,8 @@ class NumberFieldTest extends WebTestBase { // 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')); @@ -188,6 +194,8 @@ class NumberFieldTest extends WebTestBase { // 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')); @@ -196,6 +204,8 @@ class NumberFieldTest extends WebTestBase { // 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')); @@ -211,6 +221,8 @@ class NumberFieldTest extends WebTestBase { 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')); @@ -262,6 +274,8 @@ class NumberFieldTest extends WebTestBase { // 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 2778ff7698f..66460729254 100644 --- a/core/modules/field/src/Tests/TranslationWebTest.php +++ b/core/modules/field/src/Tests/TranslationWebTest.php @@ -109,6 +109,8 @@ class TranslationWebTest extends FieldTestBase { // 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 00d66873a98..2d15299ff77 100644 --- a/core/modules/hal/src/Tests/NormalizeTest.php +++ b/core/modules/hal/src/Tests/NormalizeTest.php @@ -36,6 +36,7 @@ class NormalizeTest extends NormalizerTestBase { $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 fb87d73036f..c7eb596f19e 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -149,6 +149,8 @@ class LinkFieldTest extends WebTestBase { 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')); @@ -170,6 +172,8 @@ class LinkFieldTest extends WebTestBase { 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')); @@ -266,6 +270,8 @@ class LinkFieldTest extends WebTestBase { // 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]" => '', ); @@ -281,6 +287,8 @@ class LinkFieldTest extends WebTestBase { // 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')); @@ -338,6 +346,8 @@ class LinkFieldTest extends WebTestBase { // 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]" => '', @@ -476,6 +486,8 @@ class LinkFieldTest extends WebTestBase { // 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 e4a54163483..4f4ece7b50e 100644 --- a/core/modules/quickedit/src/Tests/QuickEditTestBase.php +++ b/core/modules/quickedit/src/Tests/QuickEditTestBase.php @@ -42,7 +42,6 @@ abstract class QuickEditTestBase extends DrupalUnitTestBase { $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 e7b21c6548d..a60c53ecda1 100644 --- a/core/modules/system/src/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php @@ -61,7 +61,8 @@ class EntityFormTest extends WebTestBase { $name2 = $this->randomMachineName(10); $edit = array( - 'name[0][value]' => $name1, + 'name' => $name1, + 'user_id' => mt_rand(0, 128), 'field_test_text[0][value]' => $this->randomMachineName(16), ); @@ -69,7 +70,7 @@ class EntityFormTest extends WebTestBase { $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[0][value]'] = $name2; + $edit['name'] = $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 d484c8bba88..5eb2858e1e7 100644 --- a/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php +++ b/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php @@ -98,7 +98,7 @@ class EntityRevisionsTest extends WebTestBase { // 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-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type))); + $this->assertFieldById('edit-name', $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 721b8d31704..2986920b3da 100644 --- a/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php +++ b/core/modules/system/src/Tests/KeyValueStore/KeyValueContentEntityStorageTest.php @@ -9,14 +9,14 @@ namespace Drupal\system\Tests\KeyValueStore; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageException; -use Drupal\simpletest\KernelTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** * Tests KeyValueEntityStorage for content entities. * * @group KeyValueStore */ -class KeyValueContentEntityStorageTest extends KernelTestBase { +class KeyValueContentEntityStorageTest extends DrupalUnitTestBase { /** * Modules to enable. @@ -25,14 +25,6 @@ class KeyValueContentEntityStorageTest extends KernelTestBase { */ public static $modules = array('entity', 'user', 'entity_test', 'keyvalue_test'); - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->installEntitySchema('user'); - } - /** * Tests CRUD operations. */ 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 8d3200cd586..bd4382e4d8b 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,4 +7,3 @@ 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 34dc9979f30..3993dcf63c2 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,10 +88,6 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface { 'label' => 'hidden', 'type' => 'string', 'weight' => -5, - )) - ->setDisplayOptions('form', array( - 'type' => 'string', - 'weight' => -5, )); // @todo: Add allowed values validation. @@ -103,22 +99,8 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface { $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The ID of the associated user.')) - ->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' => '', - ), - )); + ->setSettings(array('target_type' => 'user')) + ->setTranslatable(TRUE); 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 5bc2d2b910c..205188432bd 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -6,7 +6,6 @@ namespace Drupal\entity_test; -use Drupal\Component\Utility\Random; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -16,18 +15,6 @@ use Drupal\Core\Language\LanguageInterface; */ 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} */ @@ -35,6 +22,26 @@ class EntityTestForm extends ContentEntityForm { $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 224d2b662eb..45885877a75 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldMultipleVocabularyTest.php @@ -86,6 +86,8 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase { // 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')); @@ -126,6 +128,8 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase { // 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 41ad7a51827..fa0f00718f5 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php @@ -109,6 +109,8 @@ class TermFieldTest extends TaxonomyTestBase { // 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 bbf341f8ae3..330d9f85415 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -121,6 +121,8 @@ class TextFieldTest extends WebTestBase { // 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')); @@ -191,6 +193,8 @@ class TextFieldTest extends WebTestBase { // 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')); @@ -231,6 +235,8 @@ class TextFieldTest extends WebTestBase { // 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 5958e8d821b..b6132fcdfe8 100644 --- a/core/modules/views/src/Tests/QueryGroupByTest.php +++ b/core/modules/views/src/Tests/QueryGroupByTest.php @@ -43,7 +43,6 @@ 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'); diff --git a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php index c950f81c406..6d668b2fb15 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php @@ -16,7 +16,6 @@ use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\Core\Form\FormCache * @group Form - * @backupStaticAttributes enabled */ class FormCacheTest extends UnitTestCase { @@ -75,6 +74,8 @@ class FormCacheTest extends UnitTestCase { protected function setUp() { parent::setUp(); + $this->resetSafeMarkup(); + $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->formCacheStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface'); @@ -94,6 +95,14 @@ class FormCacheTest extends UnitTestCase { $this->formCache = new FormCache($this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken); } + /** + * {@inheritdoc} + */ + protected function tearDown() { + parent::tearDown(); + $this->resetSafeMarkup(); + } + /** * @covers ::getCache */ @@ -397,4 +406,13 @@ class FormCacheTest extends UnitTestCase { $this->formCache->setCache($form_build_id, $form, $form_state); } + /** + * Ensures SafeMarkup does not bleed from one test to another. + */ + protected function resetSafeMarkup() { + $property = (new \ReflectionClass('Drupal\Component\Utility\SafeMarkup'))->getProperty('safeStrings'); + $property->setAccessible(TRUE); + $property->setValue(array()); + } + }