You are here

public function FeaturesAssignTest::testAssignDependency in Features 8.4

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

@covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentDependency

File

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

Class

FeaturesAssignTest
The Feature Assign test.

Namespace

Drupal\Tests\features\Kernel

Code

public function testAssignDependency() {
  $method_id = 'dependency';

  // Enable the method.
  $this
    ->enableAssignmentMethod($method_id);

  // Test the default options for the base assignment method.
  // Test node type assignments.
  // Declare the node_type entity 'article'.
  $this
    ->addConfigurationItem('node.type.article', [], [
    'shortName' => 'article',
    'label' => 'Article',
    'type' => 'node_type',
    'dependents' => [
      'field.field.node.article.body',
    ],
  ]);

  // Add a piece of dependent configuration.
  $this
    ->addConfigurationItem('field.field.node.article.body', [], [
    'shortName' => 'node.article.body',
    'label' => 'Body',
    'type' => 'field_config',
    'dependents' => [],
  ]);
  $this->featuresManager
    ->initPackage(self::PACKAGE_NAME, 'My test package');
  $this->featuresManager
    ->assignConfigPackage(self::PACKAGE_NAME, [
    'node.type.article',
  ]);
  $this->assigner
    ->applyAssignmentMethod($method_id);
  $packages = $this->featuresManager
    ->getPackages();
  $expected_package_names = [
    self::PACKAGE_NAME,
  ];
  $this
    ->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
  $expected_config_items = [
    'node.type.article',
    'field.field.node.article.body',
  ];
  $this
    ->assertEquals($expected_config_items, $packages[self::PACKAGE_NAME]
    ->getConfig(), 'Expected configuration items not present in article package.');
}