updated contrib modules

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 14:16:18 +01:00
parent e668535a4e
commit 272fa07ccf
202 changed files with 5165 additions and 1725 deletions
@@ -1,8 +1,10 @@
{
"name": "drupal/features",
"description": "Enables administrators to package configuration into modules.",
"type": "drupal-module",
"description": "Enables administrators to package configuration into modules",
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": { }
"name": "drupal/features",
"require": {
"drupal/config_update": "^1.4"
},
"type": "drupal-module"
}
@@ -38,7 +38,7 @@ features.bundle.*:
type: boolean
label: "Is install profile"
features.assignment.*:
features.assignment.settings:
type: mapping
label: "Assignment settings"
mapping:
@@ -49,16 +49,13 @@ features.assignment.*:
type: integer
label: "Weight"
features.assignment.*:
type: features.assignment.settings
features.assignment.base:
type: mapping
type: features.assignment.settings
label: "Base type"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
types:
type: mapping
label: "Types"
@@ -75,15 +72,9 @@ features.assignment.base:
type: string
features.assignment.core:
type: mapping
type: features.assignment.settings
label: "Core type"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
types:
type: mapping
label: "Types"
@@ -95,15 +86,9 @@ features.assignment.core:
type: string
features.assignment.exclude:
type: mapping
type: features.assignment.settings
label: "Exclude"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
types:
type: mapping
label: "Types"
@@ -134,15 +119,9 @@ features.assignment.exclude:
label: "Don't exclude ANY configuration by namespace"
features.assignment.optional:
type: mapping
type: features.assignment.settings
label: "Optional"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
types:
type: mapping
label: "Types"
@@ -154,15 +133,9 @@ features.assignment.optional:
type: string
features.assignment.profile:
type: mapping
type: features.assignment.settings
label: "Profile"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
curated:
type: boolean
label: "Add commonly-needed configuration"
@@ -187,15 +160,9 @@ features.assignment.profile:
type: string
features.assignment.site:
type: mapping
type: features.assignment.settings
label: "Site"
mapping:
enabled:
type: boolean
label: "Enabled"
weight:
type: integer
label: "Weight"
types:
type: mapping
label: "Types"
@@ -205,3 +172,17 @@ features.assignment.site:
label: "Configuration Types"
sequence:
type: string
features.assignment.alter:
type: features.assignment.settings
label: "Alter"
mapping:
core:
type: boolean
label: "Core"
uuid:
type: boolean
label: "UUID"
user_permissions:
type: boolean
label: "User permissions"
@@ -0,0 +1,11 @@
services:
features.commands:
class: \Drupal\features\Commands\FeaturesCommands
arguments:
- '@features_assigner'
- '@features.manager'
- '@features_generator'
- '@config_update.config_diff'
- '@config.storage'
tags:
- { name: drush.command }
@@ -7,8 +7,8 @@ dependencies:
- config
- config_update
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
# Information added by Drupal.org packaging script on 2018-02-27
version: '8.x-3.7'
core: '8.x'
project: 'features'
datestamp: 1488908587
datestamp: 1519763291
@@ -7,8 +7,8 @@ configure: features.assignment
dependencies:
- features
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
# Information added by Drupal.org packaging script on 2018-02-27
version: '8.x-3.7'
core: '8.x'
project: 'features'
datestamp: 1488908587
datestamp: 1519763291
@@ -641,16 +641,15 @@ class FeaturesEditForm extends FormBase {
foreach (array('excluded', 'required') as $constraint) {
$this->{$constraint} = array();
$info = !empty($this->package->{'get' . $constraint}()) ? $this->package->{'get' . $constraint}() : array();
if (($constraint == 'required') && (empty($info) || !is_array($info))) {
// If required is True or empty array, add all config as required
$info = $this->package->getConfigOrig();
}
foreach ($info as $item_name) {
if (!isset($config[$item_name])) {
continue;
// $info may be boolean.
if (is_array($info)) {
foreach ($info as $item_name) {
if (!isset($config[$item_name])) {
continue;
}
$item = $config[$item_name];
$this->{$constraint}[$item->getType()][$item->getShortName()] = $item->getLabel();
}
$item = $config[$item_name];
$this->{$constraint}[$item->getType()][$item->getShortName()] = $item->getLabel();
}
}
@@ -133,10 +133,7 @@ class FeaturesExportForm extends FormBase {
// Add in un-packaged configuration items.
$this->addUnpackaged($packages, $config_collection);
// Filter packages on bundle if selected.
if (!$current_bundle->isDefault()) {
$packages = $this->featuresManager->filterPackages($packages, $current_bundle->getMachineName(), TRUE);
}
$packages = $this->featuresManager->filterPackages($packages, $current_bundle->getMachineName());
// Pass the packages and bundle data for use in the form pre_render
// callback.
@@ -51,7 +51,7 @@ class FeaturesBundleUITest extends WebTestBase {
* The features bundle.
*/
protected function defaultBundle() {
return $this->bundleStorage->load('default');
return $this->bundleStorage->load(FeaturesBundleInterface::DEFAULT_BUNDLE);
}
/**
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
<?php
namespace Drupal\features\Exception;
class DomainException extends \DomainException {
}
@@ -0,0 +1,7 @@
<?php
namespace Drupal\features\Exception;
class InvalidArgumentException extends \InvalidArgumentException {
}
@@ -364,8 +364,7 @@ class FeaturesAssigner implements FeaturesAssignerInterface {
}
}
foreach ($new_bundles as $new_bundle) {
$new_bundle = $this->createBundleFromDefault($new_bundle['machine_name'], $new_bundle['name'], $new_bundle['description'], $new_bundle['is_profile']);
drupal_set_message($this->t('Features bundle @name automatically created.', ['@name' => $new_bundle->getName()]));
$this->createBundleFromDefault($new_bundle['machine_name'], $new_bundle['name'], $new_bundle['description'], $new_bundle['is_profile']);
}
}
@@ -57,7 +57,7 @@ class FeaturesConfigInstaller extends ConfigInstaller {
list($major, $minor, ) = explode('.', \Drupal::VERSION);
if ($major == 8 && $minor > 2) {
// D8.3 added the %install_profile% argument.
$install_profile = drupal_get_profile();
$install_profile = \Drupal::installProfile();
parent::__construct($config_factory, $active_storage, $typed_config, $config_manager, $event_dispatcher, $install_profile);
}
else {
@@ -35,7 +35,15 @@ class FeaturesInstallStorage extends ExtensionInstallStorage {
* default collection.
*/
public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION) {
parent::__construct($config_storage, $directory, $collection, FALSE);
list($major, $minor, ) = explode('.', \Drupal::VERSION);
if ($major == 8 && $minor > 2) {
// D8.3 added the %profile% argument.
$profile = \Drupal::installProfile();
parent::__construct($config_storage, $directory, $collection, FALSE, $profile);
}
else {
parent::__construct($config_storage, $directory, $collection, FALSE);
}
}
/**
@@ -326,10 +326,13 @@ class FeaturesManager implements FeaturesManagerInterface {
// A package matches the namespace if:
// - it's prefixed with the namespace, or
// - it's assigned to a bundle named for the namespace, or
// - we're looking only for exported packages and it's not exported.
if (empty($namespace) || (strpos($package->getMachineName(), $namespace . '_') === 0) ||
// - the namespace is the default bundle and it has an empty bundle, and
// - we're not removing only exported packages, or
// - we are removing only exported packages and it's not exported.
if ((strpos($package->getMachineName(), $namespace . '_') === 0 ||
($package->getBundle() && $package->getBundle() === $namespace) ||
($only_exported && $package->getStatus() === FeaturesManagerInterface::STATUS_NO_EXPORT)) {
($namespace === FeaturesBundleInterface::DEFAULT_BUNDLE && empty($package->getBundle()))) &&
(!$only_exported || ($package->getStatus() === FeaturesManagerInterface::STATUS_NO_EXPORT))) {
$result[$key] = $package;
}
}
@@ -546,25 +549,30 @@ class FeaturesManager implements FeaturesManagerInterface {
protected function getConfigDependency(ConfigurationItem $config, $module_list = array()) {
$dependencies = [];
$type = $config->getType();
if ($type != FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG) {
$provider = $this->entityTypeManager->getDefinition($type)->getProvider();
// Ensure the provider is an installed module and not, for example, 'core'
if (isset($module_list[$provider])) {
$dependencies[] = $provider;
// For configuration in the InstallStorage::CONFIG_INSTALL_DIRECTORY
// directory, set any dependencies of the configuration item as package
// dependencies.
// As its name implies, the core-provided
// InstallStorage::CONFIG_OPTIONAL_DIRECTORY should not create
// dependencies.
if ($config->getSubdirectory() === InstallStorage::CONFIG_INSTALL_DIRECTORY) {
if ($type === FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG) {
$dependencies[] = strtok($config->getName(), '.');
}
else {
$dependencies[] = $this->entityTypeManager->getDefinition($type)->getProvider();
}
// For configuration in the InstallStorage::CONFIG_INSTALL_DIRECTORY
// directory, set any module dependencies of the configuration item
// as package dependencies.
// As its name implies, the core-provided
// InstallStorage::CONFIG_OPTIONAL_DIRECTORY should not create
// dependencies.
if ($config->getSubdirectory() === InstallStorage::CONFIG_INSTALL_DIRECTORY &&
isset($config->getData()['dependencies']['module'])
) {
if (isset($config->getData()['dependencies']['module'])) {
$dependencies = array_merge($dependencies, $config->getData()['dependencies']['module']);
}
// Only return dependencies for installed modules and not, for example,
// 'core'.
$dependencies = array_intersect($dependencies, array_keys($module_list));
}
return $dependencies;
}
@@ -755,20 +763,28 @@ class FeaturesManager implements FeaturesManagerInterface {
}
$config_collection = $this->getConfigCollection();
$module_list = $this->moduleHandler->getModuleList();
/** @var \Drupal\features\Package[] $packages */
foreach ($packages as $package) {
foreach ($package->getConfig() as $item_name) {
if (!empty($config_collection[$item_name]->getData()['dependencies']['config'])) {
foreach ($config_collection[$item_name]->getData()['dependencies']['config'] as $dependency_name) {
if (isset($config_collection[$dependency_name])) {
if (isset($config_collection[$dependency_name]) &&
// For configuration in the
// InstallStorage::CONFIG_INSTALL_DIRECTORY directory, set any
// package dependencies of the configuration item.
// As its name implies, the core-provided
// InstallStorage::CONFIG_OPTIONAL_DIRECTORY should not create
// dependencies.
($config_collection[$dependency_name]->getSubdirectory() === InstallStorage::CONFIG_INSTALL_DIRECTORY)) {
// If the required item is assigned to one of the packages, add
// a dependency on that package.
$dependency_set = FALSE;
if ($dependency_package = $config_collection[$dependency_name]->getPackage()) {
$package_name = $bundle->getFullName($dependency_package);
// Package shouldn't be dependent on itself.
if ($package_name && array_key_exists($package_name, $packages) && $package_name != $package->getMachineName()) {
if ($package_name && array_key_exists($package_name, $packages) && $package_name != $package->getMachineName() && isset($module_list[$package_name])) {
$package->setDependencies($this->mergeUniqueItems($package->getDependencies(), [$package_name]));
$dependency_set = TRUE;
}
@@ -778,7 +794,7 @@ class FeaturesManager implements FeaturesManagerInterface {
if (!$dependency_set && $extension_name = $config_collection[$dependency_name]->getProvider()) {
// No extension should depend on the install profile.
$package_name = $bundle->getFullName($package->getMachineName());
if ($extension_name != $package_name && $extension_name != $this->drupalGetProfile()) {
if ($extension_name != $package_name && $extension_name != $this->drupalGetProfile() && isset($module_list[$extension_name])) {
$package->setDependencies($this->mergeUniqueItems($package->getDependencies(), [$extension_name]));
}
}
@@ -235,7 +235,7 @@ class Package {
}
/**
* @return string[]
* @return string[]|bool
*/
public function getRequired() {
return $this->required;
@@ -245,12 +245,20 @@ class Package {
* @return bool
*/
public function getRequiredAll() {
// Mark all as required if the package is not yet exported.
if ($this->getStatus() === FeaturesManagerInterface::STATUS_NO_EXPORT) {
return TRUE;
}
// Mark all as required if required is TRUE.
if (is_bool($this->required)) {
return $this->required;
}
// Mark all as required if required contains all the exported config.
$config_orig = $this->getConfigOrig();
$info = is_array($this->required) ? $this->required : array();
$diff = array_diff($config_orig, $info);
// Mark all as required if required:true, or required is empty, or
// if required contains all the exported config
return empty($diff) || empty($info);
$diff = array_diff($config_orig, $this->required);
return empty($diff);
}
/**
@@ -26,7 +26,7 @@ class FeaturesAssignmentPackages extends FeaturesAssignmentMethodBase {
$short_name = $package->getMachineName();
// Copy over package excluded settings, if any.
if (!$package->getExcluded()) {
if ($package->getExcluded()) {
$config_collection = $this->featuresManager->getConfigCollection();
foreach ($package->getExcluded() as $config_name) {
if (isset($config_collection[$config_name])) {
@@ -6,8 +6,8 @@ package: Test
dependencies:
- features
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
# Information added by Drupal.org packaging script on 2018-02-27
version: '8.x-3.7'
core: '8.x'
project: 'features'
datestamp: 1488908587
datestamp: 1519763291
@@ -1,3 +1,5 @@
bundle: test_mybundle
excluded:
- system.theme
required:
- core.date_format.long
@@ -6,8 +6,8 @@ package: Test
dependencies:
- features
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
# Information added by Drupal.org packaging script on 2018-02-27
version: '8.x-3.7'
core: '8.x'
project: 'features'
datestamp: 1488908587
datestamp: 1519763291
@@ -700,6 +700,19 @@ class FeaturesAssignTest extends KernelTestBase {
public function testAssignPackages() {
$method_id = 'packages';
// A configuration item that will be excluded.
$this->addConfigurationItem('system.theme', [], [
'type' => FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG,
]);
// A configuration item that will be required.
$this->addConfigurationItem('core.date_format.long', [], [
'type' => 'date_format',
]);
// A configuration item that will be neither excluded nor required.
$this->addConfigurationItem('system.theme', [], [
'type' => FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG,
]);
// Enable the method.
$this->enableAssignmentMethod($method_id);
@@ -708,6 +721,14 @@ class FeaturesAssignTest extends KernelTestBase {
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_INSTALLED_PACKAGE], 'Expected package not created.');
$config = $this->featuresManager->getConfigCollection();
$this->assertTrue(in_array(self::TEST_INSTALLED_PACKAGE, $config['system.theme']->getPackageExcluded()), 'Configuration item not excluded from package.');
$this->assertFalse(in_array(self::TEST_INSTALLED_PACKAGE, $config['system.site']->getPackageExcluded()), 'Configuration item excluded from package.');
$this->assertEquals(self::TEST_INSTALLED_PACKAGE, $config['core.date_format.long']->getPackage(), 'Required item not assigned to package.');
$this->assertNotEquals(self::TEST_INSTALLED_PACKAGE, $config['system.site']->getPackage(), 'Unrequired item assigned to package.');
}
/**
@@ -730,7 +751,7 @@ class FeaturesAssignTest extends KernelTestBase {
'type' => 'image_style',
]);
$this->addConfigurationItem('system.cron', [], [
'type' => 'simple',
'type' => FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG,
]);
$this->bundle = $this->assigner->createBundleFromDefault('myprofile');
$this->bundle->setProfileName('myprofile');
@@ -105,10 +105,23 @@ class FeaturesManagerTest extends UnitTestCase {
$this->configManager = $this->getMock(ConfigManagerInterface::class);
$this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
// getModuleList should return an array of extension objects.
// but we just need ::getConfigDependency isset($module_list[$provider]).
// but we just need isset($module_list[$provider]) for
// ::getConfigDependency() and ::assignInterPackageDependencies().
$this->moduleHandler->expects($this->any())
->method('getModuleList')
->willReturn(['my_module' => true]);
->willReturn([
'my_module' => true,
'example' => true,
'example3' => true,
'my_feature' => true,
'my_other_feature' => true,
'package' => true,
'package2' => true,
'package3' => true,
'giraffe_package' => true,
'giraffe_package2' => true,
'giraffe_package3' => true,
]);
$this->configReverter = $this->getMock(ConfigRevertInterface::class);
$this->configReverter->expects($this->any())
->method('import')
@@ -188,6 +201,55 @@ class FeaturesManagerTest extends UnitTestCase {
$this->assertEquals($package, $this->featuresManager->getPackage('foo'));
}
/**
* @covers ::filterPackages
*/
public function testGetPackages() {
$packages = [
'package' => new Package('package', [
'bundle' => '',
'status' => FeaturesManagerInterface::STATUS_NO_EXPORT,
]),
'package2' => new Package('package2', [
'bundle' => '',
'status' => FeaturesManagerInterface::STATUS_UNINSTALLED,
]),
'package3' => new Package('package3', [
'bundle' => 'my_bundle',
'status' => FeaturesManagerInterface::STATUS_NO_EXPORT,
]),
'package4' => new Package('package4', [
'bundle' => 'my_bundle',
'status' => FeaturesManagerInterface::STATUS_UNINSTALLED,
]),
];
// Filter for the default bundle.
$filtered_packages = $this->featuresManager->filterPackages($packages, FeaturesBundleInterface::DEFAULT_BUNDLE);
$this->assertEquals(['package', 'package2'], array_keys($filtered_packages));
// Filter for a custom bundle.
$filtered_packages = $this->featuresManager->filterPackages($packages, 'my_bundle');
$this->assertEquals(['package3', 'package4'], array_keys($filtered_packages));
// Filter for a non-matching bundle.
$filtered_packages = $this->featuresManager->filterPackages($packages, 'some_bundle');
$this->assertEquals([], array_keys($filtered_packages));
// Filter for the default bundle removing only exported.
$filtered_packages = $this->featuresManager->filterPackages($packages, FeaturesBundleInterface::DEFAULT_BUNDLE, TRUE);
$this->assertEquals(['package'], array_keys($filtered_packages));
// Filter for a custom bundle removing only exported.
$filtered_packages = $this->featuresManager->filterPackages($packages, 'my_bundle', TRUE);
$this->assertEquals(['package3'], array_keys($filtered_packages));
// Filter for a non-matching bundle removing only exported.
$filtered_packages = $this->featuresManager->filterPackages($packages, 'some_bundle', TRUE);
$this->assertEquals([], array_keys($filtered_packages));
}
protected function getAssignInterPackageDependenciesConfigCollection() {
$config_collection = [];
$config_collection['example.config'] = (new ConfigurationItem('example.config', [
@@ -196,23 +258,46 @@ class FeaturesManagerTest extends UnitTestCase {
'example.config2',
'example.config3',
'example.config4',
'example.config5',
'example.config6',
'example.config7',
],
],
]))->setPackage('package');
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setPackage('package');
$config_collection['example.config2'] = (new ConfigurationItem('example.config2', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setPackage('package2')
->setProvider('my_feature');
$config_collection['example.config3'] = (new ConfigurationItem('example.config3', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setProvider('my_other_feature');
$config_collection['example.config4'] = (new ConfigurationItem('example.config3', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setProvider(static::PROFILE_NAME);
$config_collection['example.config5'] = (new ConfigurationItem('example.config5', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_OPTIONAL_DIRECTORY)
->setPackage('package3');
$config_collection['example.config6'] = (new ConfigurationItem('example.config6', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setProvider('my_uninstalled_feature');
$config_collection['example.config7'] = (new ConfigurationItem('example.config7', [
'dependencies' => [],
]))
->setSubdirectory(InstallStorage::CONFIG_INSTALL_DIRECTORY)
->setProvider('package4');
return $config_collection;
}
@@ -225,8 +310,10 @@ class FeaturesManagerTest extends UnitTestCase {
// Provide a bundle without any prefix.
$bundle->getFullName('package')->willReturn('package');
$bundle->getFullName('package2')->willReturn('package2');
$bundle->getFullName('package3')->willReturn('package3');
$bundle->getFullName('package4')->willReturn('package4');
$bundle->isDefault()->willReturn(TRUE);
$assigner->getBundle('')->willReturn($bundle->reveal());
$assigner->getBundle()->willReturn($bundle->reveal());
// Use the wrapper because we need ::drupalGetProfile().
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setAssigner($assigner->reveal());
@@ -244,6 +331,16 @@ class FeaturesManagerTest extends UnitTestCase {
'dependencies' => [],
'bundle' => '',
]),
'package3' => new Package('package3', [
'config' => ['example.config5'],
'dependencies' => [],
'bundle' => '',
]),
'package4' => new Package('package4', [
'config' => ['example.config7'],
'dependencies' => [],
'bundle' => '',
]),
];
$features_manager->setPackages($packages);
@@ -257,6 +354,13 @@ class FeaturesManagerTest extends UnitTestCase {
// my_package.
// Because package assignments take precedence over providing_feature ones,
// package2 should have been assigned rather than my_feature.
// Because it is assigned to the InstallStorage::CONFIG_OPTIONAL_DIRECTORY
// subdirectory, example.config5 does not create a dependency on its
// providing feature, package3.
// Because it's provided by an uninstalled module, example.config6 doesn't
// create a dependency on my_uninstalled_feature.
// Because it's provided by an uninstalled module, example.config7 doesn't
// create a dependency on package4.
$this->assertEquals(['my_other_feature', 'package2'], $packages['package']->getDependencies());
$this->assertEquals([], $packages['package2']->getDependencies());
}
@@ -270,6 +374,8 @@ class FeaturesManagerTest extends UnitTestCase {
// Provide a bundle without any prefix.
$bundle->getFullName('package')->willReturn('giraffe_package');
$bundle->getFullName('package2')->willReturn('giraffe_package2');
$bundle->getFullName('package3')->willReturn('giraffe_package3');
$bundle->getFullName('package4')->willReturn('giraffe_package4');
$bundle->getFullName('giraffe_package')->willReturn('giraffe_package');
$bundle->getFullName('giraffe_package2')->willReturn('giraffe_package2');
$bundle->isDefault()->willReturn(FALSE);
@@ -291,6 +397,16 @@ class FeaturesManagerTest extends UnitTestCase {
'dependencies' => [],
'bundle' => 'giraffe',
]),
'package3' => new Package('package3', [
'config' => ['example.config5'],
'dependencies' => [],
'bundle' => 'giraffe',
]),
'package4' => new Package('package4', [
'config' => ['example.config7'],
'dependencies' => [],
'bundle' => 'giraffe',
]),
];
$features_manager->setPackages($packages);
@@ -304,6 +420,13 @@ class FeaturesManagerTest extends UnitTestCase {
// my_package.
// Because package assignments take precedence over providing_feature ones,
// package2 should have been assigned rather than my_feature.
// Because it is assigned to the InstallStorage::CONFIG_OPTIONAL_DIRECTORY
// subdirectory, example.config5 does not create a dependency on its
// providing feature, package3.
// Because it's provided by an uninstalled module, example.config6 doesn't
// create a dependency on my_uninstalled_feature.
// Because it's provided by an uninstalled module, example.config7 doesn't
// create a dependency on giraffe_package4.
$expected = ['giraffe_package2', 'my_other_feature'];
$this->assertEquals($expected, $packages['giraffe_package']->getDependencies());
}
@@ -417,6 +540,7 @@ class FeaturesManagerTest extends UnitTestCase {
$assigner = $this->prophesize(FeaturesAssignerInterface::class);
$bundle = $this->prophesize(FeaturesBundleInterface::class);
$bundle->isProfilePackage('test_package')->willReturn(FALSE);
$bundle->isProfilePackage('test_package2')->willReturn(FALSE);
$assigner->getBundle(NULL)->willReturn($bundle->reveal());
$this->featuresManager->setAssigner($assigner->reveal());
@@ -424,21 +548,43 @@ class FeaturesManagerTest extends UnitTestCase {
'test_config' => new ConfigurationItem('test_config', []),
'test_config2' => new ConfigurationItem('test_config2', [
'dependencies' => [
'module' => ['example'],
'module' => ['example', 'example2'],
]
], [
'subdirectory' => InstallStorage::CONFIG_INSTALL_DIRECTORY,
]),
'example3.settings' => new ConfigurationItem('example3.settings', [], [
'type' => FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG,
'subdirectory' => InstallStorage::CONFIG_INSTALL_DIRECTORY,
]),
'test_config3' => new ConfigurationItem('test_config3', [
'dependencies' => [
'module' => ['example2'],
]
], [
'subdirectory' => InstallStorage::CONFIG_OPTIONAL_DIRECTORY,
]),
];
$this->featuresManager->setConfigCollection($config_collection);
$package = new Package('test_package');
$this->featuresManager->setPackage($package);
$this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2']);
$this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2', 'example3.settings']);
$this->assertEquals(['test_config', 'test_config2'], $this->featuresManager->getPackage('test_package')->getConfig());
$this->assertEquals(['example', 'my_module'], $this->featuresManager->getPackage('test_package')->getDependencies());
$this->assertEquals(['test_config', 'test_config2', 'example3.settings'], $this->featuresManager->getPackage('test_package')->getConfig());
// 'example2' is not returned by ::getModuleList() and so isn't a
// dependency.
$this->assertEquals(['example', 'example3', 'my_module'], $this->featuresManager->getPackage('test_package')->getDependencies());
// Test optional config, which doesn't create module dependencies.
$package = new Package('test_package2');
$this->featuresManager->setPackage($package);
$this->featuresManager->assignConfigPackage('test_package2', ['test_config3']);
$this->assertEquals(['test_config3'], $this->featuresManager->getPackage('test_package2')->getConfig());
$this->assertEquals([], $this->featuresManager->getPackage('test_package2')->getDependencies());
}
/**
@@ -451,6 +597,32 @@ class FeaturesManagerTest extends UnitTestCase {
];
$this->featuresManager->setConfigCollection($config_collection);
$feature_assigner = $this->prophesize(FeaturesAssignerInterface::class);
$feature_assigner->getBundle(NULL)->willReturn(new FeaturesBundle(['machine_name' => FeaturesBundleInterface::DEFAULT_BUNDLE], 'features_bundle'));
$this->featuresManager->setAssigner($feature_assigner->reveal());
$package = new Package('test_package');
$original_package = clone $package;
$this->featuresManager->setPackage($package);
$this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2']);
$this->assertEquals(['test_config'], $this->featuresManager->getPackage('test_package')->getConfig(), 'just assign new packages');
$this->featuresManager->setPackage($original_package);
$this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2'], TRUE);
$this->assertEquals(['test_config', 'test_config2'], $this->featuresManager->getPackage('test_package')->getConfig(), 'just assign new packages');
}
/**
* @covers ::assignConfigPackage
*/
public function testAssignConfigPackageWithPackageExcludedConfig() {
$config_collection = [
'test_config' => new ConfigurationItem('test_config', []),
'test_config2' => new ConfigurationItem('test_config2', [], ['packageExcluded' => ['test_package']]),
];
$this->featuresManager->setConfigCollection($config_collection);
$feature_assigner = $this->prophesize(FeaturesAssignerInterface::class);
$feature_assigner->getBundle(NULL)->willReturn(new FeaturesBundle(['machine_name' => 'default'], 'features_bundle'));
$this->featuresManager->setAssigner($feature_assigner->reveal());
@@ -687,6 +859,7 @@ EOT
/**
* @covers ::prepareFiles
* @covers ::addInfoFile
*/
public function testPrepareFiles() {
$packages = [];
@@ -695,12 +868,22 @@ EOT
'name' => 'Test feature',
]);
$packages['test_feature2'] = new Package('test_feature2', [
'config' => ['test_config2'],
'name' => 'Test feature 2',
'type' => 'profile',
'excluded' => ['my_config'],
'required' => ['test_config2'],
]);
$config_collection = [];
$config_collection['test_config'] = new ConfigurationItem('test_config', ['foo' => 'bar']);
$config_collection['test_config2'] = new ConfigurationItem('test_config2', ['foo' => 'bar']);
$this->featuresManager->setConfigCollection($config_collection);
$this->featuresManager->prepareFiles($packages);
// Test test_feature package.
$files = $packages['test_feature']->getFiles();
$this->assertCount(3, $files);
$this->assertEquals('test_feature.info.yml', $files['info']['filename']);
@@ -718,6 +901,14 @@ EOT
$this->assertEquals('test_feature.features.yml', $files['features']['filename']);
$this->assertEquals(Yaml::encode(TRUE), $files['features']['string']);
// Test test_feature2 package.
$files = $packages['test_feature2']->getFiles();
$this->assertEquals(Yaml::encode([
'excluded' => ['my_config'],
'required' => ['test_config2'],
]), $files['features']['string']);
}
/**