diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index b472b8f..b1a775c 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -234,8 +234,14 @@ public function create(array $values) { $class = $this->entityInfo['class']; $entity = new $class($values, $this->entityType); - // Mark this entity as new, so isNew() returns TRUE. This does not check - // whether a configuration entity with the same ID (if any) already exists. + if (!$entity->isNew()) { + // Check to see if an entity already exists. + $config = config($this->getConfigPrefix() . $entity->id()); + if (!$config->isNew()) { + throw new EntityMalformedException(format_string('The @type entity ID (@id) is not unique.', array('@type' => $this->entityType, '@id' => $entity->id()))); + } + } + // Mark this entity as new, so isNew() returns TRUE. $entity->enforceIsNew(); // Assign a new UUID if there is none yet. diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php index 0091300..228cb69 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php @@ -40,19 +40,7 @@ public function setUp() { */ public function testThemeBreakpoints() { // Verify the breakpoint group for breakpoint_test_theme was created. - $breakpoint_group_obj = entity_create('breakpoint_group', array( - 'label' => 'Breakpoint test theme', - 'name' => 'breakpoint_test_theme', - 'source' => 'breakpoint_test_theme', - 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, - 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.breakpoint_test_theme', - )); - $breakpoint_group_obj->breakpoints = array( - 'theme.breakpoint_test_theme.mobile' => array(), - 'theme.breakpoint_test_theme.narrow' => array(), - 'theme.breakpoint_test_theme.wide' => array(), - 'theme.breakpoint_test_theme.tv' => array(), - ); + $breakpoint_group_obj = entity_load('breakpoint_group', Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.breakpoint_test_theme'); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); @@ -67,18 +55,7 @@ public function testThemeBreakpoints() { */ public function testThemeBreakpointGroup() { // Verify the breakpoint group 'test' was created by breakpoint_test_theme. - $breakpoint_group_obj = entity_create('breakpoint_group', array( - 'label' => 'Test Theme', - 'name' => 'test', - 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, - 'source' => 'breakpoint_test_theme', - 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test', - )); - $breakpoint_group_obj->breakpoints = array( - 'theme.breakpoint_test_theme.mobile' => array('1.5x', '2.x'), - 'theme.breakpoint_test_theme.narrow' => array(), - 'theme.breakpoint_test_theme.wide' => array(), - ); + $breakpoint_group_obj = entity_load('breakpoint_group', Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test'); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); @@ -92,24 +69,9 @@ public function testThemeBreakpointGroup() { * Test the breakpoints defined by the custom group in the module. */ public function testThemeBreakpointGroupModule() { - // Call the import manually, since the testbot needs to enable the module - // first, otherwise the theme isn't detected. - _breakpoint_import_breakpoint_groups('breakpoint_theme_test', Breakpoint::SOURCE_TYPE_MODULE); - - // Verify the breakpoint group 'module_test' was created by + // Verify the breakpoint group 'module_test' was created by the // breakpoint_theme_test module. - $breakpoint_group_obj = entity_create('breakpoint_group', array( - 'label' => 'Test Module', - 'name' => 'module_test', - 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE, - 'source' => 'breakpoint_theme_test', - 'id' => Breakpoint::SOURCE_TYPE_MODULE . '.breakpoint_theme_test.module_test', - )); - $breakpoint_group_obj->breakpoints = array( - 'theme.breakpoint_test_theme.mobile' => array(), - 'theme.breakpoint_test_theme.narrow' => array(), - 'theme.breakpoint_test_theme.wide' => array(), - ); + $breakpoint_group_obj = entity_load('breakpoint_group', Breakpoint::SOURCE_TYPE_MODULE . '.breakpoint_theme_test.module_test'); // Verify we can load this breakpoint defined by the theme. $this->verifyBreakpointGroup($breakpoint_group_obj); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index efcbf0e..ddfa7cc 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -137,24 +137,6 @@ function testCRUD() { $this->assertIdentical($config_test->isNew(), FALSE); $this->assertIdentical($config_test->getOriginalID(), $expected['id']); - // Re-create the entity with the same ID and verify updated status. - $same_id = entity_create('config_test', array( - 'id' => $config_test->id(), - )); - $this->assertIdentical($same_id->isNew(), TRUE); - $status = $same_id->save(); - $this->assertIdentical($status, SAVED_UPDATED); - - // Verify that the entity was overwritten. - $same_id = entity_load('config_test', $config_test->id()); - $this->assertIdentical($same_id->id(), $config_test->id()); - // Note: Reloading loads from FileStorage, and FileStorage enforces strings. - $this->assertIdentical($same_id->label(), ''); - $this->assertNotEqual($same_id->uuid(), $config_test->uuid()); - - // Revert to previous state. - $config_test->save(); - // Verify that renaming the ID returns correct status and properties. $ids = array($expected['id'], 'second_' . $this->randomName(4), 'third_' . $this->randomName(4)); for ($i = 1; $i < 3; $i++) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php index d64c73a..905ac98 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\config\Tests; use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\Core\Entity\EntityMalformedException; /** * Unit tests for configuration controllers and objects. @@ -40,4 +41,27 @@ public function testStorageControllerMethods() { $this->assertIdentical($controller->getConfigPrefix(), $expected); } + /** + * Tests the behavior of creating conflicting entities. + */ + public function testCreatingConflictingEntities() { + // Create an entity with a label. + $entity = entity_create('config_test', array('id' => 'foo', 'label' => 'Foo', 'style' => 'foo')); + $entity->save(); + + // Create an entity with the same ID, but a different label. + $exception = FALSE; + try { + $entity = entity_create('config_test', array('id' => 'foo', 'label' => 'Bananas')); + $entity->save(); + } + catch (EntityMalformedException $e) { + $exception = TRUE; + } + // Creating an entity with the same machine name should not succeed. + $this->assertEqual($entity->label(), 'Foo', 'The entity label was not overwritten.'); + $this->assertEqual($entity->style, 'foo', 'The entity style was not overwritten.'); + $this->assertTrue($exception, 'An exception was thrown when creating an entity with a duplicate ID.'); + } + } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php index 95089f7..4242bcc 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -8,6 +8,7 @@ namespace Drupal\config\Tests; use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\Core\Entity\EntityMalformedException; /** * Tests importing configuration from files into active configuration. @@ -194,4 +195,17 @@ function testUpdated() { $this->assertFalse(config_sync_get_changes($staging, $storage)); } + /** + * Tests enabling a module with a duplicate configuration entity. + */ + function testDuplicate() { + $this->assertEqual(config('config_test.dynamic.default')->get('label'), 'Default', "Configuration object label is 'Default'."); + try { + module_enable(array('config_test_duplicate')); + } + catch (EntityMalformedException $e) { + } + $this->assertEqual(config('config_test.dynamic.default')->get('label'), 'Default', 'Configuration object is not silently overwritten on import.'); + } + } diff --git a/core/modules/config/tests/config_test_duplicate/config/config_test.dynamic.default.yml b/core/modules/config/tests/config_test_duplicate/config/config_test.dynamic.default.yml new file mode 100644 index 0000000..12efb31 --- /dev/null +++ b/core/modules/config/tests/config_test_duplicate/config/config_test.dynamic.default.yml @@ -0,0 +1,2 @@ +id: default +label: Not default diff --git a/core/modules/config/tests/config_test_duplicate/config_test_duplicate.info b/core/modules/config/tests/config_test_duplicate/config_test_duplicate.info new file mode 100644 index 0000000..491708d --- /dev/null +++ b/core/modules/config/tests/config_test_duplicate/config_test_duplicate.info @@ -0,0 +1,5 @@ +name = Duplicate default configuration +package = Core +version = VERSION +core = 8.x +hidden = TRUE diff --git a/core/modules/config/tests/config_test_duplicate/config_test_duplicate.module b/core/modules/config/tests/config_test_duplicate/config_test_duplicate.module new file mode 100644 index 0000000..f6c2685 --- /dev/null +++ b/core/modules/config/tests/config_test_duplicate/config_test_duplicate.module @@ -0,0 +1,6 @@ +get(); + // Change the machine name to prevent a conflict. + $values['name'] = strtolower($this->randomName(8)); $created = $this->controller->create($values); $this->assertTrue($created instanceof View, 'Created object is a View.'); diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_field_type.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_field_type.yml deleted file mode 100644 index c9172bc..0000000 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_field_type.yml +++ /dev/null @@ -1,20 +0,0 @@ -api_version: '3.0' -base_table: node -core: '8' -description: '' -disabled: '0' -display: - default: - display_options: - fields: - type: - field: type - id: type - table: node - display_plugin: default - display_title: Master - id: default - position: '0' -human_name: '' -name: test_field_type -tag: ''