diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php index e002ac2..76f7eb3 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\config\Tests\SchemaCheckTestTrait; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -112,7 +113,8 @@ function testEntityReferenceDefaultValue() { */ function testEntityReferenceDefaultConfigValue() { // Create a node to be referenced. - $referenced_node_type = $this->drupalCreateContentType(array('type' => 'referenced_config')); + $referenced_node_type = $this->drupalCreateContentType(array('type' => 'referenced_config_to_delete')); + $referenced_node_type2 = $this->drupalCreateContentType(array('type' => 'referenced_config_to_preserve')); $field_name = Unicode::strtolower($this->randomMachineName()); $field_storage = entity_create('field_storage_config', array( @@ -120,6 +122,7 @@ function testEntityReferenceDefaultConfigValue() { 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => array('target_type' => 'node_type'), + 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, )); $field_storage->save(); $field = entity_create('field_config', array( @@ -137,18 +140,22 @@ function testEntityReferenceDefaultConfigValue() { // Set created node as default_value. $field_edit = array( 'default_value_input[' . $field_name . '][0][target_id]' => $referenced_node_type->label() . ' (' .$referenced_node_type->id() . ')', + 'default_value_input[' . $field_name . '][1][target_id]' => $referenced_node_type2->label() . ' (' .$referenced_node_type2->id() . ')', ); $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name, $field_edit, t('Save settings')); // Check that the field has a dependency on the default value. $config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get(); - $this->assertTrue(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type is a dependency of the field.'); + $this->assertTrue(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_delete is a dependency of the field.'); + $this->assertTrue(in_array($referenced_node_type2->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_preserve is a dependency of the field.'); // Check that the field does not have a dependency on the default value // after deleting the node type. $referenced_node_type->delete(); \Drupal::configFactory()->reset('field.field.node.reference_content.' . $field_name); - $this->assertTrue(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type is a dependency of the field.'); + $config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get(); + $this->assertFalse(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_delete not a dependency of the field.'); + $this->assertTrue(in_array($referenced_node_type2->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_preserve is a dependency of the field.'); } }