Esempio n. 1
0
 /**
  * Generates a file representation of configuration packages and, optionally,
  * an install profile.
  *
  * @param string $method_id
  *   The ID of the generation method to use.
  * @param string[] $package_names
  *   Names of packages to be generated. If none are specified, all
  *   available packages will be added.
  * @param \Drupal\features\FeaturesBundleInterface $bundle
  *   The optional bundle used for the generation.  Used to generate profiles.
  *
  * @return array
  *   Array of results for profile and/or packages, each result including the
  *   following keys:
  *   - 'success': boolean TRUE or FALSE for successful writing.
  *   - 'display': boolean TRUE if the message should be displayed to the
  *     user, otherwise FALSE.
  *   - 'message': a message about the result of the operation.
  *   - 'variables': an array of substitutions to be used in the message.
  */
 protected function generate($method_id, array $package_names = array(), FeaturesBundleInterface $bundle = NULL)
 {
     $packages = $this->featuresManager->getPackages();
     // Filter out the packages that weren't requested.
     if (!empty($package_names)) {
         $packages = array_intersect_key($packages, array_fill_keys($package_names, NULL));
     }
     $this->featuresManager->assignInterPackageDependencies($packages);
     // Prepare the files.
     $this->featuresManager->prepareFiles($packages);
     $return = $this->applyGenerationMethod($method_id, $packages, $bundle);
     foreach ($return as $message) {
         if ($message['display']) {
             $type = $message['success'] ? 'status' : 'error';
             drupal_set_message($this->t($message['message'], $message['variables']), $type);
         }
         $type = $message['success'] ? 'notice' : 'error';
         \Drupal::logger('features')->{$type}($message['message'], $message['variables']);
     }
     return $return;
 }
 /**
  * @covers ::assignInterPackageDependencies
  */
 public function testAssignInterPackageDependenciesWithBundle()
 {
     $assigner = $this->prophesize(FeaturesAssignerInterface::class);
     $bundle = $this->prophesize(FeaturesBundleInterface::class);
     // Provide a bundle without any prefix.
     $bundle->getFullName('package')->willReturn('package');
     $bundle->getFullName('package2')->willReturn('package2');
     $assigner->getBundle('giraffe')->willReturn($bundle->reveal());
     $this->featuresManager->setAssigner($assigner->reveal());
     $this->featuresManager->setConfigCollection($this->getAssignInterPackageDependenciesConfigCollection());
     $packages = ['package' => new Package('package', ['config' => ['example.config', 'example.config3'], 'dependencies' => [], 'bundle' => 'giraffe']), 'package2' => new Package('package2', ['config' => ['example.config2'], 'dependencies' => [], 'bundle' => 'giraffe'])];
     $expected = $packages;
     // example.config3 has a providing_feature but no assigned package.
     $expected['package']->setDependencies(['my_other_feature']);
     // 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.
     $expected['package']->setDependencies(['my_other_feature', 'package2']);
     $this->featuresManager->setPackages($packages);
     $this->featuresManager->assignInterPackageDependencies($packages);
     $this->assertEquals($expected, $packages);
 }
Esempio n. 3
0
 /**
  * @covers ::assignInterPackageDependencies
  * @expectedException \Exception
  * @expectedExceptionMessage The packages have not yet been prefixed with a bundle name
  */
 public function testAssignInterPackageDependenciesPrematureCall()
 {
     $bundle = $this->prophesize(FeaturesBundleInterface::class);
     $packages = ['package' => new Package('package', ['config' => ['example.config', 'example.config3'], 'dependencies' => [], 'bundle' => 'giraffe'])];
     $this->featuresManager->assignInterPackageDependencies($bundle->reveal(), $packages);
 }