diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -299,6 +299,7 @@ $this->addDependency('module', $definition['provider']); } } + return $this->dependencies; } /** @@ -355,13 +356,6 @@ /** * {@inheritdoc} */ - public function getDependencies() { - return $this->dependencies; - } - - /** - * {@inheritdoc} - */ public function getConfigDependencyName() { return $this->getEntityType()->getConfigPrefix() . '.' . $this->id(); } diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -140,11 +140,6 @@ public function calculateDependencies(); /** - * Gets the entity's dependencies. - */ - public function getDependencies(); - - /** * Gets the configuration dependency name. * * @return string diff -u b/core/modules/block/lib/Drupal/block/Entity/Block.php b/core/modules/block/lib/Drupal/block/Entity/Block.php --- b/core/modules/block/lib/Drupal/block/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Entity/Block.php @@ -173,6 +173,7 @@ public function calculateDependencies() { parent::calculateDependencies(); $this->addDependency('theme', $this->theme); + return $this->dependencies; } } diff -u b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php --- b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php @@ -283,6 +283,7 @@ elseif ($this->sourceType == static::SOURCE_TYPE_THEME) { $this->addDependency('theme', $this->source); } + return $this->dependencies; } } diff -u b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php --- b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php @@ -232,8 +232,9 @@ } $breakpoints = $this->getBreakpoints(); foreach ($breakpoints as $breakpoint) { - $this->addDependency('module', $breakpoint->getConfigDependencyName()); + $this->addDependency('entity', $breakpoint->getConfigDependencyName()); } + return $this->dependencies; } } diff -u b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php --- b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php @@ -98,6 +98,7 @@ // entity and dependency on provider is managed automatically. $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition(); $this->addDependency('module', $definition['provider']); + return $this->dependencies; } /** diff -u b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php --- b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -177,6 +177,7 @@ $mode_entity = $this->entityManager()->getStorageController($this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode); $this->addDependency('entity', $mode_entity->getConfigDependencyName()); } + return $this->dependencies; } /** diff -u b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php --- b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php @@ -85,6 +85,7 @@ parent::calculateDependencies(); $target_entity_type = $this->entityManager()->getDefinition($this->targetEntityType); $this->addDependency('module', $target_entity_type->getProvider()); + return $this->dependencies; } } diff -u b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php --- b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -337,6 +337,7 @@ parent::calculateDependencies(); // Ensure the field is dependent on the providing module. $this->addDependency('module', $this->module); + return $this->dependencies; } /** diff -u b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php --- b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Field\TypedData\FieldItemDataDefinition; +use Drupal\field\Field; use Drupal\field\FieldException; use Drupal\field\FieldInstanceConfigInterface; @@ -235,7 +236,7 @@ // 'uuid' entry is present too, so that leftover 'field_uuid' entries // present in config files imported as "default module config" are ignored. if (isset($values['field_uuid']) && isset($values['uuid'])) { - $field = field_info_field_by_id($values['field_uuid']); + $field = Field::fieldInfo()->getFieldById($values['field_uuid']); if (!$field) { throw new FieldException(format_string('Attempt to create an instance of unknown field @uuid', array('@uuid' => $values['field_uuid']))); } @@ -245,7 +246,7 @@ // easier DX on creation of new instances (either through programmatic // creation / or through import of default config files). elseif (isset($values['field_name']) && isset($values['entity_type'])) { - $field = field_info_field($values['entity_type'], $values['field_name']); + $field = Field::fieldInfo()->getField($values['entity_type'], $values['field_name']); if (!$field) { throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); } @@ -365,6 +366,7 @@ parent::calculateDependencies(); // Manage dependencies. $this->addDependency('entity', $this->field->getConfigDependencyName()); + return $this->dependencies; } /** diff -u b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php --- b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php +++ b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php @@ -90,6 +90,7 @@ $breakpoint_group = $this->entityManager()->getStorageController('breakpoint_group')->load($this->breakpointGroup); $this->addDependency('entity', $breakpoint_group->getConfigDependencyName()); } + return $this->dependencies; } /** diff -u b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php --- b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php +++ b/core/modules/rdf/lib/Drupal/rdf/Entity/RdfMapping.php @@ -169,6 +169,7 @@ $bundle_entity = $this->entityManager()->getStorageController($bundle_entity_type_id)->load($this->bundle); $this->addDependency('entity', $bundle_entity->getConfigDependencyName()); } + return $this->dependencies; } /** diff -u b/core/modules/tour/lib/Drupal/tour/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Entity/Tour.php --- b/core/modules/tour/lib/Drupal/tour/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Entity/Tour.php @@ -181,6 +181,7 @@ } $this->addDependency('module', $this->module); + return $this->dependencies; } } diff -u b/core/modules/user/config/views.view.user_admin_people.yml b/core/modules/user/config/views.view.user_admin_people.yml --- b/core/modules/user/config/views.view.user_admin_people.yml +++ b/core/modules/user/config/views.view.user_admin_people.yml @@ -561,7 +561,6 @@ empty_zero: false hide_alter_empty: true text: Translate - optional: true plugin_id: content_translation_link provider: content_translation dropbutton: diff -u b/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php --- b/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -297,6 +297,7 @@ } } } + return $this->dependencies; } /** diff -u b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php --- b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -1209,12 +1209,6 @@ /** * {@inheritdoc} */ - public function getDependencies() { - } - - /** - * {@inheritdoc} - */ public function getConfigDependencyName() { } diff -u b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewUIObjectTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewUIObjectTest.php --- b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewUIObjectTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewUIObjectTest.php @@ -48,11 +48,10 @@ // calls id(), which breaks the ->expect($this->once()) call. Call it later. // EntityInterface::isSyncing() is only called during syncing process. // EntityInterface::isUninstalling() is only called during uninstallation - // process. ConfigEntityInterface::getConfigDependencyName(), - // ConfigEntityInterface::calculateDependencies() and - // ConfigEntityInterface::getDependencies() are only used for dependency - // management. - if (!in_array($reflection_method->getName(), ['isNew', 'isSyncing', 'isUninstalling', 'getConfigDependencyName', 'calculateDependencies', 'getDependencies'])) { + // process. ConfigEntityInterface::getConfigDependencyName() and + // ConfigEntityInterface::calculateDependencies() are only used for + // dependency management. + if (!in_array($reflection_method->getName(), ['isNew', 'isSyncing', 'isUninstalling', 'getConfigDependencyName', 'calculateDependencies'])) { if (count($reflection_method->getParameters()) == 0) { $method_args[$reflection_method->getName()] = array(); } diff -u b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigDependencyManagerTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigDependencyManagerTest.php --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigDependencyManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigDependencyManagerTest.php @@ -8,8 +8,8 @@ /** * Tests the ConfigDependencyManager class. * + * @group Drupal * @group Config - * @group \Drupal */ class ConfigDependencyManagerTest extends UnitTestCase { diff -u b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityDependencyTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityDependencyTest.php --- b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityDependencyTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityDependencyTest.php @@ -8,8 +8,8 @@ /** * Tests the ConfigEntityDependency class. * + * @group Drupal * @group Config - * @group \Drupal */ class ConfigEntityDependencyTest extends UnitTestCase { only in patch2: unchanged: --- /dev/null +++ b/core/modules/block/tests/Drupal/block/Tests/BlockConfigEntityUnitTest.php @@ -0,0 +1,121 @@ + '', + 'name' => '\Drupal\block\Entity\Block unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('block')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $values = array('theme' => 'stark'); + // Mock the entity under test so that we can mock the getPluginBag method. + $entity = $this->getMockBuilder('\Drupal\block\Entity\Block') + ->setConstructorArgs(array($values, $this->entityTypeId)) + ->setMethods(array('getPluginBag')) + ->getMock(); + // Create a configurable plugin that would add a dependency. + $instance_id = $this->randomName(); + $instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test')); + + // Create a plugin bag to contain the instance. + $plugin_bag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag') + ->disableOriginalConstructor() + ->setMethods(array('get')) + ->getMock(); + $plugin_bag->expects($this->atLeastOnce()) + ->method('get') + ->with($instance_id) + ->will($this->returnValue($instance)); + $plugin_bag->addInstanceId($instance_id); + + // Return the mocked plugin bag. + $entity->expects($this->once()) + ->method('getPluginBag') + ->will($this->returnValue($plugin_bag)); + + $dependencies = $entity->calculateDependencies(); + $this->assertContains('test', $dependencies['module']); + $this->assertContains('stark', $dependencies['theme']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointConfigEntityUnitTest.php @@ -0,0 +1,123 @@ + '', + 'name' => '\Drupal\breakpoint\Entity\Breakpoint unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('breakpoint')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesModule() { + $values = array( + 'source' => 'test_module', + 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE, + ); + $entity = new Breakpoint($values, $this->entityTypeId); + + $dependencies = $entity->calculateDependencies(); + $this->assertArrayNotHasKey('theme', $dependencies); + $this->assertContains('test_module', $dependencies['module']); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesTheme() { + $values = array( + 'source' => 'test_theme', + 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, + ); + $entity = new Breakpoint($values, $this->entityTypeId); + + $dependencies = $entity->calculateDependencies(); + $this->assertArrayNotHasKey('module', $dependencies); + $this->assertContains('test_theme', $dependencies['theme']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointGroupConfigEntityUnitTest.php @@ -0,0 +1,158 @@ + '', + 'name' => '\Drupal\breakpoint\Entity\BreakpointGroup unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('breakpoint')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + } + + /** + * Sets up the entity to test. + */ + public function setUpEntity($values) { + // Mocking the entity under test because the class contains calls to + // procedural code. + $this->entity = $this->getMockBuilder('\Drupal\breakpoint\Entity\BreakpointGroup') + ->setConstructorArgs(array($values, $this->entityTypeId)) + ->setMethods(array('getBreakpoints')) + ->getMock(); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesModule() { + $this->setUpEntity( + array( + 'source' => 'test_module', + 'sourceType' => Breakpoint::SOURCE_TYPE_MODULE, + ) + ); + $breakpoint = $this->getMockBuilder('\Drupal\breakpoint\Entity\Breakpoint') + ->disableOriginalConstructor()->getMock(); + $breakpoint->expects($this->once()) + ->method('getConfigDependencyName') + ->will($this->returnValue('breakpoint.breakpoint.test')); + + $this->entity->expects($this->once()) + ->method('getBreakpoints') + ->will($this->returnValue(array($breakpoint))); + + $dependencies = $this->entity->calculateDependencies(); + $this->assertArrayNotHasKey('theme', $dependencies); + $this->assertContains('test_module', $dependencies['module']); + $this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesTheme() { + $this->setUpEntity( + array( + 'source' => 'test_theme', + 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, + ) + ); + + $breakpoint = $this->getMockBuilder('\Drupal\breakpoint\Entity\Breakpoint') + ->disableOriginalConstructor()->getMock(); + $breakpoint->expects($this->once()) + ->method('getConfigDependencyName') + ->will($this->returnValue('breakpoint.breakpoint.test')); + + $this->entity->expects($this->once()) + ->method('getBreakpoints') + ->will($this->returnValue(array($breakpoint))); + + $dependencies = $this->entity->calculateDependencies(); + $this->assertArrayNotHasKey('module', $dependencies); + $this->assertContains('test_theme', $dependencies['theme']); + $this->assertContains('breakpoint.breakpoint.test', $dependencies['entity']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/editor/tests/Drupal/editor/Tests/EditorConfigEntityUnitTest.php @@ -0,0 +1,171 @@ + '', + 'name' => '\Drupal\editor\Entity\Editor unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->editorId = $this->randomName(); + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('editor')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $this->editorPluginManager = $this->getMockBuilder('Drupal\editor\Plugin\EditorManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); + $this->moduleHandler->expects($this->once()) + ->method('invokeAll') + ->with('editor_default_settings', array($this->editorId)) + ->will($this->returnValue(array())); + + $this->moduleHandler->expects($this->once()) + ->method('alter') + ->with('editor_default_settings', array(), $this->editorId) + ->will($this->returnValue(array())); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + $container->set('plugin.manager.editor', $this->editorPluginManager); + $container->set('module_handler', $this->moduleHandler); + \Drupal::setContainer($container); + + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $format_id = 'filter.format.test'; + $values = array('editor' => $this->editorId, 'format' => $format_id); + + $plugin = $this->getMockBuilder('Drupal\editor\Plugin\EditorPluginInterface') + ->disableOriginalConstructor() + ->getMock(); + $plugin->expects($this->once()) + ->method('getPluginDefinition') + ->will($this->returnValue(array('provider' => 'test_module'))); + $plugin->expects($this->once()) + ->method('getDefaultSettings') + ->will($this->returnValue(array())); + + $this->editorPluginManager->expects($this->any()) + ->method('createInstance') + ->with($this->editorId) + ->will($this->returnValue($plugin)); + + $entity = new Editor($values, $this->entityTypeId); + + $filter_format = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface'); + $filter_format->expects($this->once()) + ->method('getConfigDependencyName') + ->will($this->returnValue('filter.format.test')); + + $storage = $this->getMock('Drupal\Core\Entity\EntityStorageControllerInterface'); + $storage->expects($this->once()) + ->method('load') + ->with($format_id) + ->will($this->returnValue($filter_format)); + + $this->entityManager->expects($this->once()) + ->method('getStorageController') + ->with('filter_format') + ->will($this->returnValue($storage)); + + $dependencies = $entity->calculateDependencies(); + $this->assertContains('test_module', $dependencies['module']); + $this->assertContains('filter.format.test', $dependencies['entity']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/field/tests/Drupal/field/Tests/FieldConfigEntityUnitTest.php @@ -0,0 +1,97 @@ + '', + 'name' => '\Drupal\field\Entity\FieldConfig unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('entity')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => 'test_entity_type', 'module' => 'test_module'); + $entity = new FieldConfig($values, $this->entityTypeId); + $dependencies = $entity->calculateDependencies(); + $this->assertContains('test_module', $dependencies['module']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/field/tests/Drupal/field/Tests/FieldInstanceConfigEntityUnitTest.php @@ -0,0 +1,120 @@ + '', + 'name' => '\Drupal\field\Entity\FieldInstanceConfig unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('entity')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $this->fieldInfo = $this->getMockBuilder('\Drupal\field\FieldInfo') + ->disableOriginalConstructor() + ->getMock(); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + $container->set('field.info', $this->fieldInfo); + \Drupal::setContainer($container); + + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $field = $this->getMock('\Drupal\field\FieldConfigInterface'); + // The field name property is public and accessed this way in the field + // instance config entity constructor. + $field->name = 'test_field'; + $field->expects($this->once()) + ->method('getConfigDependencyName') + ->will($this->returnValue('field.field.test_entity_type.test_field')); + $this->fieldInfo->expects($this->any()) + ->method('getField') + ->with('test_entity_type', 'test_field') + ->will($this->returnValue($field)); + $values = array('field_name' => 'test_field', 'entity_type' => 'test_entity_type', $this->entityTypeId, 'bundle' => 'test_bundle'); + $entity = new FieldInstanceConfig($values, $this->entityTypeId); + $dependencies = $entity->calculateDependencies(); + $this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']); + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/rdf/tests/Drupal/rdf/Tests/RdfMappingConfigEntityUnitTest.php @@ -0,0 +1,162 @@ + '', + 'name' => '\Drupal\field\Entity\RdfMapping unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityTypeId = $this->randomName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('entity')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $target_entity_type_id = $this->randomName(16); + + $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $target_entity_type->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('test_module')); + $values = array('targetEntityType' => $target_entity_type_id); + $target_entity_type->expects($this->any()) + ->method('getBundleEntityType') + ->will($this->returnValue('bundle')); + + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with($target_entity_type_id) + ->will($this->returnValue($target_entity_type)); + $this->entityManager->expects($this->at(1)) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $entity = new RdfMapping($values, $this->entityTypeId); + $dependencies = $entity->calculateDependencies(); + $this->assertArrayNotHasKey('entity', $dependencies); + $this->assertContains('test_module', $dependencies['module']); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesWithEntityBundle() { + $target_entity_type_id = $this->randomName(16); + $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $target_entity_type->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('test_module')); + $bundle_id = $this->randomName(10); + $values = array('targetEntityType' => $target_entity_type_id , 'bundle' => $bundle_id); + + $bundle_entity_type_id = $this->randomName(17); + $bundle_entity = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityInterface'); + $bundle_entity + ->expects($this->once()) + ->method('getConfigDependencyName') + ->will($this->returnValue('test_module.type.' . $bundle_id)); + + $target_entity_type->expects($this->any()) + ->method('getBundleEntityType') + ->will($this->returnValue($bundle_entity_type_id)); + + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with($target_entity_type_id) + ->will($this->returnValue($target_entity_type)); + $this->entityManager->expects($this->at(1)) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $storage = $this->getMock('Drupal\Core\Entity\EntityStorageControllerInterface'); + $storage->expects($this->once()) + ->method('load') + ->with($bundle_id) + ->will($this->returnValue($bundle_entity)); + + $this->entityManager->expects($this->once()) + ->method('getStorageController') + ->with($bundle_entity_type_id) + ->will($this->returnValue($storage)); + + $entity = new RdfMapping($values, $this->entityTypeId); + $dependencies = $entity->calculateDependencies(); + $this->assertContains('test_module.type.' . $bundle_id, $dependencies['entity']); + $this->assertContains('test_module', $dependencies['module']); + } + +} only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -7,13 +7,16 @@ namespace Drupal\Tests\Core\Config\Entity; +use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Component\Plugin\PluginBase; use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase * * @group Drupal + * @group Config */ class ConfigEntityBaseUnitTest extends UnitTestCase { @@ -53,6 +56,13 @@ class ConfigEntityBaseUnitTest extends UnitTestCase { protected $uuid; /** + * The provider of the entity type. + * + * @var string + */ + protected $provider; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -69,8 +79,11 @@ public static function getInfo() { public function setUp() { $values = array(); $this->entityType = $this->randomName(); - + $this->provider = $this->randomName(); $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityInfo->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue($this->provider)); $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); $this->entityManager->expects($this->any()) @@ -230,4 +243,107 @@ public function testGetExportProperties() { $this->assertSame($this->entity->get($name), $properties[$name]); } } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + // Calculating dependencies will reset the dependencies array. + $this->entity->set('dependencies', array('module' => array('node'))); + $this->assertEmpty($this->entity->calculateDependencies()); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesWithPluginBag() { + $values = array(); + $this->entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBag') + ->setConstructorArgs(array($values, $this->entityType)) + ->setMethods(array('getPluginBag')) + ->getMock(); + + // Create a configurable plugin that would add a dependency. + $instance_id = $this->randomName(); + $instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test')); + + // Create a plugin bag to contain the instance. + $pluginBag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag') + ->disableOriginalConstructor() + ->setMethods(array('get')) + ->getMock(); + $pluginBag->expects($this->atLeastOnce()) + ->method('get') + ->with($instance_id) + ->will($this->returnValue($instance)); + $pluginBag->addInstanceId($instance_id); + + // Return the mocked plugin bag. + $this->entity->expects($this->once()) + ->method('getPluginBag') + ->will($this->returnValue($pluginBag)); + + $dependencies = $this->entity->calculateDependencies(); + $this->assertContains('test', $dependencies['module']); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependenciesWithPluginBagSameProviderAsEntityType() { + $values = array(); + $this->entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginBag') + ->setConstructorArgs(array($values, $this->entityType)) + ->setMethods(array('getPluginBag')) + ->getMock(); + + // Create a configurable plugin that will not add a dependency since it is + // provider matches the provider of the entity type. + $instance_id = $this->randomName(); + $instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => $this->provider)); + + // Create a plugin bag to contain the instance. + $pluginBag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag') + ->disableOriginalConstructor() + ->setMethods(array('get')) + ->getMock(); + $pluginBag->expects($this->atLeastOnce()) + ->method('get') + ->with($instance_id) + ->will($this->returnValue($instance)); + $pluginBag->addInstanceId($instance_id); + + // Return the mocked plugin bag. + $this->entity->expects($this->once()) + ->method('getPluginBag') + ->will($this->returnValue($pluginBag)); + + $this->assertEmpty($this->entity->calculateDependencies()); + } + +} + +class TestConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface { + + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return $this->configuration; + } + + /** + * {@inheritdoc} + */ + public function setConfiguration(array $configuration) { + $this->configuration = $configuration; + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array(); + } + } only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php @@ -0,0 +1,120 @@ + '', + 'name' => '\Drupal\entity\EntityDisplayModeBase unit test', + 'group' => 'Entity', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->entityType = $this->randomName(); + + $this->entityInfo = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityInfo->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('entity')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + \Drupal::setContainer($container); + + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $target_entity_type_id = $this->randomName(16); + + $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $target_entity_type->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('test_module')); + $values = array('targetEntityType' => $target_entity_type_id); + + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with($target_entity_type_id) + ->will($this->returnValue($target_entity_type)); + $this->entityManager->expects($this->at(1)) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue($this->entityInfo)); + + $this->entity = $this->getMockBuilder('\Drupal\entity\EntityDisplayModeBase') + ->setConstructorArgs(array($values, $this->entityType)) + ->setMethods(array('getFilterFormat')) + ->getMock(); + + $dependencies = $this->entity->calculateDependencies(); + $this->assertContains('test_module', $dependencies['module']); + + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithPluginBag.php @@ -0,0 +1,20 @@ +