diff --git a/drush/features.drush.inc b/drush/features.drush.inc index 7a5c7bb..fd33551 100644 --- a/drush/features.drush.inc +++ b/drush/features.drush.inc @@ -864,7 +864,7 @@ function _drush_features_get_component_map() { } if (!empty($item->getPackage())) { $package = $packages[$item->getPackage()]; - $result[$type][$short_name][] = $name; + $result[$type][$short_name][] = $package['machine_name']; } } diff --git a/src/ConfigurationItem.php b/src/ConfigurationItem.php index 302e2d9..cc2a9be 100644 --- a/src/ConfigurationItem.php +++ b/src/ConfigurationItem.php @@ -13,7 +13,7 @@ namespace Drupal\features; * @todo Should the object be immutable? * @todo Should this object have an interface? */ -class ConfigurationItem implements \ArrayAccess { +class ConfigurationItem { /** * Prefixed configuration item name. @@ -96,10 +96,10 @@ class ConfigurationItem implements \ArrayAccess { * Creates a new ConfigurationItem instance. * * @param string $name + * @param array $data * @param string $shortName * @param string $label * @param string $type - * @param array $data * @param \string[] $dependents * @param string $subdirectory * @param string $package @@ -107,7 +107,7 @@ class ConfigurationItem implements \ArrayAccess { * @param string $providingFeature * @param \string[] $packageExcluded */ - public function __construct($name, $shortName, $label, $type, array $data, array $dependents, $subdirectory, $package, $extensionProvided, $providingFeature, array $packageExcluded) { + public function __construct($name, array $data, $shortName, $label, $type, array $dependents, $subdirectory, $package, $extensionProvided, $providingFeature, array $packageExcluded = []) { $this->name = $name; $this->shortName = $shortName; $this->label = $label; @@ -305,88 +305,4 @@ class ConfigurationItem implements \ArrayAccess { return $this; } - /** - * {@inheritdoc} - */ - public function offsetGet($offset) { - switch ($offset) { - case 'name': - return $this->getName(); - case 'name_short': - return $this->getShortName(); - case 'label': - return $this->getLabel(); - case 'type': - return $this->getType(); - case 'data': - return $this->getData(); - case 'dependents': - return $this->getDependents(); - case 'subdirectory': - return $this->getSubdirectory(); - case 'package': - return $this->getPackage(); - case 'extension_provided': - return $this->isExtensionProvided(); - case 'package_excluded': - return $this->getPackageExcluded(); - default: - throw new \InvalidArgumentException('Wrong configuration item key: ' . $offset); - } - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) { - switch ($offset) { - case 'name': - return $this->setName($value); - case 'name_short': - return $this->setShortName($value); - case 'label': - return $this->setLabel($value); - case 'type': - return $this->setType($value); - case 'data': - return $this->setData($value); - case 'dependents': - return $this->setDependents($value); - case 'subdirectory': - return $this->setSubdirectory($value); - case 'package': - return $this->setPackage($value); - case 'extension_provided': - return $this->setExtensionProvided($value); - case 'package_excluded': - return $this->setPackageExcluded($value); - default: - throw new \InvalidArgumentException('Wrong configuration item key: ' . $offset); - } - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset) { - return in_array($offset, [ - 'name', - 'name_short', - 'label', - 'type', - 'data', - 'dependents', - 'subdirectory', - 'package', - 'extension_provided', - 'package_excluded' - ]); - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) { - } - } diff --git a/src/FeaturesManager.php b/src/FeaturesManager.php index 42be05f..31c449f 100644 --- a/src/FeaturesManager.php +++ b/src/FeaturesManager.php @@ -10,6 +10,7 @@ use Drupal; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\features\FeaturesAssignerInterface; use Drupal\features\FeaturesBundleInterface; use Drupal\features\FeaturesGeneratorInterface; @@ -602,8 +603,8 @@ class FeaturesManager implements FeaturesManagerInterface { } // Otherwise, if the dependency is provided by an existing // feature, add a dependency on that feature. - elseif (!empty($config_collection[$dependency_name]['providing_feature'])) { - $this->mergeUniqueItems($package['dependencies'], [$config_collection[$dependency_name]['providing_feature']]); + elseif ($config_collection[$dependency_name]->getProvidingFeature()) { + $this->mergeUniqueItems($package['dependencies'], [$config_collection[$dependency_name]->getProvidingFeature()]); } } } @@ -954,12 +955,11 @@ class FeaturesManager implements FeaturesManagerInterface { $config_collection[$name] = new ConfigurationItem( $name, + $data, $item_name, $label, $config_type, - $data, array_keys($dependents), - // Default to the install directory. InstallStorage::CONFIG_INSTALL_DIRECTORY, '', NULL, diff --git a/tests/src/Unit/FeaturesManagerTest.php b/tests/src/Unit/FeaturesManagerTest.php index f409475..6891cfe 100644 --- a/tests/src/Unit/FeaturesManagerTest.php +++ b/tests/src/Unit/FeaturesManagerTest.php @@ -7,11 +7,15 @@ namespace Drupal\Tests\features\Unit; +use Drupal\Core\Config\Entity\ConfigEntityType; +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Entity\EntityType; use Drupal\features\FeaturesAssignerInterface; use Drupal\features\FeaturesBundleInterface; use Drupal\features\ConfigurationItem; use Drupal\features\FeaturesManager; use Drupal\features\FeaturesManagerInterface; +use Drupal\migrate\Plugin\migrate\destination\Config; use Drupal\Tests\UnitTestCase; /** @@ -26,22 +30,35 @@ class FeaturesManagerTest extends UnitTestCase { protected $featuresManager; /** + * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $entityManager; + + /** * {@inheritdoc} */ public function setUp() { + parent::setUp(); + $entity_type = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface'); $entity_type->expects($this->any()) ->method('getConfigPrefix') ->willReturn('custom'); - $entity_manager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); - $entity_manager->expects($this->any()) + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) ->method('getDefinition') ->willReturn($entity_type); $config_factory = $this->getMock('\Drupal\Core\Config\ConfigFactoryInterface'); $storage = $this->getMock('Drupal\Core\Config\StorageInterface'); $config_manager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); - $this->featuresManager = new FeaturesManager($entity_manager, $config_factory, $storage, $config_manager, $module_handler); + $this->featuresManager = new FeaturesManager($this->entityManager, $config_factory, $storage, $config_manager, $module_handler); + + $string_translation = $this->getStringTranslationStub(); + $container = new ContainerBuilder(); + $container->set('string_translation', $string_translation); + $container->set('app.root', $this->root); + \Drupal::setContainer($container); } /** @@ -98,7 +115,7 @@ class FeaturesManagerTest extends UnitTestCase { * @covers ::getConfigCollection */ public function testConfigCollection() { - $config = ['config' => new ConfigurationItem('', '', '', '', [], [], '', '', TRUE, '', [])]; + $config = ['config' => new ConfigurationItem('', [], '', '', '', [], '', '', TRUE, '', [])]; $this->featuresManager->setConfigCollection($config); $this->assertArrayEquals($config, $this->featuresManager->getConfigCollection()); } @@ -112,34 +129,20 @@ class FeaturesManagerTest extends UnitTestCase { protected function getAssignInterPackageDependenciesConfigCollection() { $config_collection = []; - $config_collection['example.config'] = [ - 'name' => 'example.config', - 'data' => [ - 'dependencies' => [ - 'config' => [ - 'example.config2', - 'example.config3', - ], + $config_collection['example.config'] = new ConfigurationItem('example.config', [ + 'dependencies' => [ + 'config' => [ + 'example.config2', + 'example.config3', ], ], - 'package' => 'package', - ]; - $config_collection['example.config2'] = [ - 'name' => 'example.config2', - 'data' => [ - 'dependencies' => [], - ], - 'package' => 'package2', - 'providing_feature' => 'my_feature', - ]; - $config_collection['example.config3'] = [ - 'name' => 'example.config3', - 'data' => [ - 'dependencies' => [], - ], - 'package' => '', - 'providing_feature' => 'my_other_feature', - ]; + ], '', '', '', [], '', 'package', FALSE, ''); + $config_collection['example.config2'] = new ConfigurationItem('example.config2', [ + 'dependencies' => [], + ], '', '', '', [], '', 'package2', TRUE, 'my_feature'); + $config_collection['example.config3'] = new ConfigurationItem('example.config3', [ + 'dependencies' => [], + ], '', '', '', [], '', '', TRUE, 'my_other_feature'); return $config_collection; }