You are here

public function FeaturesManagerTest::testAssignConfigPackageWithNonProviderExcludedConfig in Features 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/FeaturesManagerTest.php \Drupal\Tests\features\Unit\FeaturesManagerTest::testAssignConfigPackageWithNonProviderExcludedConfig()

@covers ::assignConfigPackage

File

tests/src/Unit/FeaturesManagerTest.php, line 593

Class

FeaturesManagerTest
@coversDefaultClass Drupal\features\FeaturesManager @group features

Namespace

Drupal\Tests\features\Unit

Code

public function testAssignConfigPackageWithNonProviderExcludedConfig() {
  $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());
  $config_collection = [
    'test_config' => new ConfigurationItem('test_config', []),
    'test_config2' => new ConfigurationItem('test_config2', [
      'dependencies' => [
        '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',
    'example3.settings',
  ]);
  $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());
}