public function FeaturesManagerTest::testAssignInterPackageDependenciesWithBundle in Features 8.3
Same name and namespace in other branches
- 8.4 tests/src/Unit/FeaturesManagerTest.php \Drupal\Tests\features\Unit\FeaturesManagerTest::testAssignInterPackageDependenciesWithBundle()
@covers ::assignInterPackageDependencies
File
- tests/
src/ Unit/ FeaturesManagerTest.php, line 427
Class
- FeaturesManagerTest
- @coversDefaultClass Drupal\features\FeaturesManager @group features
Namespace
Drupal\Tests\features\UnitCode
public function testAssignInterPackageDependenciesWithBundle() {
$assigner = $this
->prophesize(FeaturesAssignerInterface::class);
$bundle = $this
->prophesize(FeaturesBundleInterface::class);
// 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);
$bundle
->getMachineName()
->willReturn('giraffe');
$assigner
->getBundle('giraffe')
->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, $this->moduleExtensionList);
$features_manager
->setAssigner($assigner
->reveal());
$features_manager
->setConfigCollection($this
->getAssignInterPackageDependenciesConfigCollection());
$packages = [
'package' => new Package('package', [
'config' => [
'example.config',
],
'dependencies' => [],
'bundle' => 'giraffe',
]),
'package2' => new Package('package2', [
'config' => [
'example.config2',
],
'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);
// Dependencies require the full package names.
$package_names = array_keys($packages);
$features_manager
->setPackageBundleNames($bundle
->reveal(), $package_names);
$packages = $features_manager
->getPackages();
$features_manager
->assignInterPackageDependencies($bundle
->reveal(), $packages);
// example.config3 has a providing_feature but no assigned package.
// my_package2 provides configuration required by configuration in
// 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());
}