diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index ce00011..ed56dce 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -8,8 +8,10 @@ namespace Drupal\field\Tests; use Drupal\Component\Utility\Html; +use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormState; +use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -655,4 +657,40 @@ function testHiddenField() { $this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget'); } + /** + * Tests the form display of the label for multi-value fields. + */ + public function testLabelOnMultiValueFields() { + $user = $this->drupalCreateUser(['administer entity_test content']); + $this->drupalLogin($user); + + FieldStorageConfig::create([ + 'entity_type' => 'entity_test_base_field_display', + 'field_name' => 'foo', + 'type' => 'text', + 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test_base_field_display', + 'bundle' => 'bar', + 'field_name' => 'foo', + // Set a dangerous label to test XSS filtering. + 'label' => "", + ])->save(); + EntityFormDisplay::create([ + 'targetEntityType' => 'entity_test_base_field_display', + 'bundle' => 'bar', + 'mode' => 'default', + ])->setComponent('foo', ['type' => 'text_textfield'])->enable()->save(); + + $entity = EntityTestBaseFieldDisplay::create(['type' => 'bar']); + $entity->save(); + + $this->drupalGet('entity_test_base_field_display/manage/' . $entity->id()); + $this->assertResponse(200); + $this->assertText('A field with multiple values'); + // Test if labels were XSS filtered. + $this->assertEscaped(""); + } + } diff --git a/core/modules/system/src/Tests/Entity/EntityBaseFieldTest.php b/core/modules/system/src/Tests/Entity/EntityBaseFieldTest.php deleted file mode 100644 index 756715a..0000000 --- a/core/modules/system/src/Tests/Entity/EntityBaseFieldTest.php +++ /dev/null @@ -1,70 +0,0 @@ -drupalCreateUser(['administer entity_test content']); - $this->drupalLogin($user); - - FieldStorageConfig::create([ - 'entity_type' => 'entity_test_base_field_display', - 'field_name' => 'foo', - 'type' => 'text', - 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, - ])->save(); - FieldConfig::create([ - 'entity_type' => 'entity_test_base_field_display', - 'bundle' => 'bar', - 'field_name' => 'foo', - // Set a dangerous label to test XSS filtering. - 'label' => "", - ]) - ->save(); - EntityFormDisplay::create([ - 'targetEntityType' => 'entity_test_base_field_display', - 'bundle' => 'bar', - 'mode' => 'default', - ]) - ->setComponent('foo', ['type' => 'text_textfield']) - ->enable() - ->save(); - - $entity = EntityTestBaseFieldDisplay::create(['type' => 'bar']); - $entity->save(); - - $this->drupalGet('entity_test_base_field_display/manage/' . $entity->id()); - $this->assertResponse(200); - $this->assertText('A field with multiple values'); - // Test if labels were XSS filtered. - $this->assertEscaped(""); - } - -}