diff --git a/core/modules/config/src/Tests/ConfigDependencyWebTest.php b/core/modules/config/src/Tests/ConfigDependencyWebTest.php new file mode 100644 index 0000000..019c8cb --- /dev/null +++ b/core/modules/config/src/Tests/ConfigDependencyWebTest.php @@ -0,0 +1,133 @@ +container->get('entity.manager')->getStorage('config_test'); + // Entity1 will be deleted by the test. + $entity1 = $storage->create( + array( + 'id' => 'entity1', + 'label' => 'Entity One', + ) + ); + $entity1->save(); + + // Entity2 has a dependency on Entity1 but it can be fixed because + // \Drupal\config_test\Entity::onDependencyRemoval() will remove the + // dependency before config entities are deleted. + $entity2 = $storage->create( + array( + 'id' => 'entity2', + 'dependencies' => array( + 'enforced' => array( + 'config' => array($entity1->getConfigDependencyName()), + ), + ), + ) + ); + $entity2->save(); + + $this->drupalGet($entity2->url('delete-form')); + $this->assertNoText(t('Configuration updates'), 'No configuration updates found.'); + $this->assertNoText(t('Configuration deletions'), 'No configuration deletes found.'); + $this->drupalGet($entity1->url('delete-form')); + $this->assertNoText(t('Configuration updates'), 'No configuration updates found.'); + $this->assertText(t('Configuration deletions'), 'Configuration deletions found.'); + $this->assertText($entity2->id(), 'Entity2 id found'); + $this->drupalPostForm($entity1->url('delete-form'), array(), 'Delete'); + $storage->resetCache(); + $this->assertFalse($storage->loadMultiple([$entity1->id(), $entity2->id()]), 'Test entities deleted'); + + // Set a more complicated test where dependencies will be fixed. + // Entity1 will be deleted by the test. + $entity1 = $storage->create( + array( + 'id' => 'entity1', + ) + ); + $entity1->save(); + \Drupal::state()->set('config_test.fix_dependencies', array($entity1->getConfigDependencyName())); + + // Entity2 has a dependency on Entity1 but it can be fixed because + // \Drupal\config_test\Entity::onDependencyRemoval() will remove the + // dependency before config entities are deleted. + $entity2 = $storage->create( + array( + 'id' => 'entity2', + 'label' => 'Entity Two', + 'dependencies' => array( + 'enforced' => array( + 'config' => array($entity1->getConfigDependencyName()), + ), + ), + ) + ); + $entity2->save(); + + // Entity3 will be unchanged because it is dependent on Entity2 which can + // be fixed. + $entity3 = $storage->create( + array( + 'id' => 'entity3', + 'dependencies' => array( + 'enforced' => array( + 'config' => array($entity2->getConfigDependencyName()), + ), + ), + ) + ); + $entity3->save(); + + $this->drupalGet($entity1->url('delete-form')); + $this->assertText(t('Configuration updates'), 'Configuration updates found.'); + $this->assertNoText(t('Configuration deletions'), 'No configuration deletions found.'); + $this->assertNoText($entity2->id(), 'Entity2 id not found'); + $this->assertText($entity2->label(), 'Entity2 label not found'); + $this->assertNoText($entity3->id(), 'Entity3 id not found'); + $this->drupalPostForm($entity1->url('delete-form'), array(), 'Delete'); + $storage->resetCache(); + $this->assertFalse($storage->load('entity1'), 'Test entity 1 deleted'); + $entity2 = $storage->load('entity2'); + $this->assertTrue($entity2, 'Entity 2 not deleted'); + $this->assertEqual($entity2->calculateDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.'); + $entity3 = $storage->load('entity3'); + $this->assertTrue($entity3, 'Entity 3 not deleted'); + $this->assertEqual($entity3->calculateDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.'); + + } + +} diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php index 8fc7c13..7cf16e6 100644 --- a/core/modules/config/src/Tests/ConfigEntityTest.php +++ b/core/modules/config/src/Tests/ConfigEntityTest.php @@ -319,100 +319,6 @@ function testCRUDUI() { $this->drupalPostForm('admin/structure/config_test/manage/0/delete', array(), 'Delete'); $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted'); - // Test \Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait. - /** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */ - $storage = $this->container->get('entity.manager')->getStorage('config_test'); - // Entity1 will be deleted by the test. - $entity1 = $storage->create( - array( - 'id' => 'entity1', - 'label' => 'Entity One', - ) - ); - $entity1->save(); - - // Entity2 has a dependency on Entity1 but it can be fixed because - // \Drupal\config_test\Entity::onDependencyRemoval() will remove the - // dependency before config entities are deleted. - $entity2 = $storage->create( - array( - 'id' => 'entity2', - 'dependencies' => array( - 'enforced' => array( - 'config' => array($entity1->getConfigDependencyName()), - ), - ), - ) - ); - $entity2->save(); - - $this->drupalGet($entity2->url('delete-form')); - $this->assertNoText(t('Configuration updates'), 'No configuration updates found.'); - $this->assertNoText(t('Configuration deletions'), 'No configuration deletes found.'); - $this->drupalGet($entity1->url('delete-form')); - $this->assertNoText(t('Configuration updates'), 'No configuration updates found.'); - $this->assertText(t('Configuration deletions'), 'Configuration deletions found.'); - $this->assertText($entity2->id(), 'Entity2 id found'); - $this->drupalPostForm($entity1->url('delete-form'), array(), 'Delete'); - $storage->resetCache(); - $this->assertFalse($storage->loadMultiple([$entity1->id(), $entity2->id()]), 'Test entities deleted'); - - // Set a more complicated test where dependencies will be fixed. - // Entity1 will be deleted by the test. - $entity1 = $storage->create( - array( - 'id' => 'entity1', - ) - ); - $entity1->save(); - \Drupal::state()->set('config_test.fix_dependencies', array($entity1->getConfigDependencyName())); - - // Entity2 has a dependency on Entity1 but it can be fixed because - // \Drupal\config_test\Entity::onDependencyRemoval() will remove the - // dependency before config entities are deleted. - $entity2 = $storage->create( - array( - 'id' => 'entity2', - 'label' => 'Entity Two', - 'dependencies' => array( - 'enforced' => array( - 'config' => array($entity1->getConfigDependencyName()), - ), - ), - ) - ); - $entity2->save(); - - // Entity3 will be unchanged because it is dependent on Entity2 which can - // be fixed. - $entity3 = $storage->create( - array( - 'id' => 'entity3', - 'dependencies' => array( - 'enforced' => array( - 'config' => array($entity2->getConfigDependencyName()), - ), - ), - ) - ); - $entity3->save(); - - $this->drupalGet($entity1->url('delete-form')); - $this->assertText(t('Configuration updates'), 'Configuration updates found.'); - $this->assertNoText(t('Configuration deletions'), 'No configuration deletions found.'); - $this->assertNoText($entity2->id(), 'Entity2 id not found'); - $this->assertText($entity2->label(), 'Entity2 label not found'); - $this->assertNoText($entity3->id(), 'Entity3 id not found'); - $this->drupalPostForm($entity1->url('delete-form'), array(), 'Delete'); - $storage->resetCache(); - $this->assertFalse($storage->load('entity1'), 'Test entity 1 deleted'); - $entity2 = $storage->load('entity2'); - $this->assertTrue($entity2, 'Entity 2 not deleted'); - $this->assertEqual($entity2->calculateDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.'); - $entity3 = $storage->load('entity3'); - $this->assertTrue($entity3, 'Entity 3 not deleted'); - $this->assertEqual($entity3->calculateDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.'); - } } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 9ef8466..9f05892 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -99,7 +99,7 @@ class ConfigEntityStorageTest extends UnitTestCase { /** * The configuration manager. * - * @var \Drupal\Core\Config\ConfigManagerInterface + * @var \Drupal\Core\Config\ConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $configManager; @@ -739,6 +739,11 @@ public function testDeleteRevision() { * @covers ::doDelete */ public function testDelete() { + // Dependencies are tested elsewhere. + // @see \Drupal\config\Tests\ConfigDependencyTest + $this->configManager->expects($this->any()) + ->method('getConfigEntitiesToChangeOnDependencyRemoval') + ->willReturn(['update' => [], 'delete' => [], 'unchanged' => []]); $entities = array(); $configs = array(); $config_map = array();