You are here

public function FeaturesAssignTest::testAssignPackages in Features 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/FeaturesAssignTest.php \Drupal\Tests\features\Kernel\FeaturesAssignTest::testAssignPackages()

@covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentPackages

File

tests/src/Kernel/FeaturesAssignTest.php, line 708

Class

FeaturesAssignTest
The Feature Assign test.

Namespace

Drupal\Tests\features\Kernel

Code

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);
  $this->assigner
    ->applyAssignmentMethod($method_id);
  $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.');
}