/** * @covers ::prepareFiles */ public function testPrepareFiles() { $packages = []; $packages['test_feature'] = new Package('test_feature', ['config' => ['test_config'], 'name' => 'Test feature']); $config_collection = []; $config_collection['test_config'] = new ConfigurationItem('test_config', ['foo' => 'bar']); $this->featuresManager->setConfigCollection($config_collection); $this->featuresManager->prepareFiles($packages); $files = $packages['test_feature']->getFiles(); $this->assertCount(2, $files); $this->assertEquals('test_feature.info.yml', $files['info']['filename']); $this->assertEquals(Yaml::encode(['name' => 'Test feature', 'type' => 'module', 'core' => '8.x', 'config' => ['test_config'], 'features' => TRUE]), $files['info']['string']); $this->assertEquals('test_config.yml', $files['test_config']['filename']); $this->assertEquals(Yaml::encode(['foo' => 'bar']), $files['test_config']['string']); }
/** * 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) { // Prepare the files. $this->featuresManager->prepareFiles(); $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)); } $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; }