/** * @covers ::getPackage * @covers ::getPackages * @covers ::reset * @covers ::setPackages */ public function testPackages() { $packages = ['foo' => 'bar']; $this->featuresManager->setPackages($packages); $this->assertEquals($packages, $this->featuresManager->getPackages()); $this->assertEquals('bar', $this->featuresManager->getPackage('foo')); $this->featuresManager->reset(); $this->assertArrayEquals([], $this->featuresManager->getPackages()); $this->assertNull($this->featuresManager->getPackage('foo')); }
/** * {@inheritdoc} */ public function prepare(array &$packages = array(), FeaturesBundleInterface $bundle = NULL) { // If no packages were specified, get all packages. if (empty($packages)) { $packages = $this->featuresManager->getPackages(); } // If any packages exist, read in their files. $existing_packages = $this->featuresManager->listPackageDirectories(array_keys($packages), $bundle); foreach ($packages as &$package) { list($full_name, $path) = $this->featuresManager->getExportInfo($package, $bundle); $package['directory'] = $path . '/' . $full_name; $this->preparePackage($package, $existing_packages, $bundle); } // Clean up the $package pass by reference. unset($package); if (isset($bundle) && $bundle->isProfile()) { $profile_name = $bundle->getProfileName(); $profile_package = $this->featuresManager->getPackage($profile_name); if (isset($profile_package)) { $package['directory'] = 'profiles/' . $profile_name; $this->preparePackage($profile_package, $existing_packages, $bundle); } } }
public function testExportWrite() { $package = $this->featuresManager->getPackage(self::PACKAGE_NAME); // Find out where package will be exported list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle()); $path = $path . '/' . $full_name; if (file_exists($path)) { file_unmanaged_delete_recursive($path); } $this->assertFalse(file_exists($path), 'Package directory already exists.'); $this->generator->generatePackages('write', [self::PACKAGE_NAME], $this->assigner->getBundle()); $this->assertTrue(file_exists($path), 'Package directory was not generated.'); $this->assertTrue(file_exists($path . '/' . self::PACKAGE_NAME . '.info.yml'), 'Package info.yml not generated.'); $this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.'); $this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.'); }
/** * @covers \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite */ public function testExportWrite() { // Set a fake drupal root, so the testbot can also write into it. vfsStream::setup('drupal'); \Drupal::getContainer()->set('app.root', 'vfs://drupal'); $package = $this->featuresManager->getPackage(self::PACKAGE_NAME); // Find out where package will be exported list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle()); $path = 'vfs://drupal/' . $path . '/' . $full_name; if (file_exists($path)) { file_unmanaged_delete_recursive($path); } $this->assertFalse(file_exists($path), 'Package directory already exists.'); $this->generator->generatePackages('write', $this->assigner->getBundle(), [self::PACKAGE_NAME]); $this->assertTrue(file_exists($path), 'Package directory was not generated.'); $this->assertTrue(file_exists($path . '/' . self::PACKAGE_NAME . '.info.yml'), 'Package info.yml not generated.'); $this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.'); $this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.'); }
/** * @covers ::assignConfigPackage */ public function testAssignConfigPackageWithExtensionProvidedConfig() { $config_collection = ['test_config' => new ConfigurationItem('test_config', []), 'test_config2' => new ConfigurationItem('test_config2', [], ['extensionProvided' => TRUE])]; $this->featuresManager->setConfigCollection($config_collection); $feature_assigner = $this->prophesize(FeaturesAssignerInterface::class); $feature_assigner->getBundle(NULL)->willReturn(new FeaturesBundle(['machine_name' => 'default'], 'features_bundle')); $this->featuresManager->setAssigner($feature_assigner->reveal()); $package = new Package('test_package'); $original_package = clone $package; $this->featuresManager->setPackage($package); $this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2']); $this->assertEquals(['test_config'], $this->featuresManager->getPackage('test_package')->getConfig(), 'just assign new packages'); $this->featuresManager->setPackage($original_package); $this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2'], TRUE); $this->assertEquals(['test_config', 'test_config2'], $this->featuresManager->getPackage('test_package')->getConfig(), 'just assign new packages'); }
/** * @covers \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite */ public function testExportWrite() { // Set a fake drupal root, so the testbot can also write into it. vfsStream::setup('drupal'); \Drupal::getContainer()->set('app.root', 'vfs://drupal'); $this->featuresManager->setRoot('vfs://drupal'); $package = $this->featuresManager->getPackage(self::PACKAGE_NAME); // Find out where package will be exported list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle()); $path = 'vfs://drupal/' . $path . '/' . $full_name; if (file_exists($path)) { file_unmanaged_delete_recursive($path); } $this->assertFalse(file_exists($path), 'Package directory already exists.'); $this->generator->generatePackages('write', $this->assigner->getBundle(), [self::PACKAGE_NAME]); $info_file_uri = $path . '/' . self::PACKAGE_NAME . '.info.yml'; $this->assertTrue(file_exists($path), 'Package directory was not generated.'); $this->assertTrue(file_exists($info_file_uri), 'Package info.yml not generated.'); $this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.'); $this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.'); $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x"]; $info = Yaml::decode(file_get_contents($info_file_uri)); $this->assertEquals($expected_info, $info, 'Incorrect info file generated'); // Now, add stuff to the feature and re-export to ensure it is preserved // Add a dependency to the package itself to see that it gets exported. $package->setDependencies(['user']); $this->featuresManager->setPackage($package); // Add dependency and custom key to the info file to simulate manual edit. $info['dependencies'] = ['node']; $info['mykey'] = "test value"; $info_contents = Yaml::encode($info); file_put_contents($info_file_uri, $info_contents); // Add an extra file that should be retained. $css_file = $path . '/' . self::PACKAGE_NAME . '.css'; $file_contents = "This is a dummy file"; file_put_contents($css_file, $file_contents); // Add a config file that should be removed since it's not part of the // feature. $config_file = $path . '/config/install/node.type.mytype.yml'; file_put_contents($config_file, $file_contents); $this->generator->generatePackages('write', $this->assigner->getBundle(), [self::PACKAGE_NAME]); $this->assertTrue(file_exists($info_file_uri), 'Package info.yml not generated.'); $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x", "dependencies" => ["node", "user"], "mykey" => "test value"]; $info = Yaml::decode(file_get_contents($info_file_uri)); $this->assertEquals($expected_info, $info, 'Incorrect info file generated'); $this->assertTrue(file_exists($css_file), 'Extra file was not retained.'); $this->assertFalse(file_exists($config_file), 'Config directory was not cleaned.'); $this->assertEquals($file_contents, file_get_contents($css_file), 'Extra file contents not retained'); // Next, test that generating an Archive picks up the extra files. $filename = file_directory_temp() . '/' . self::PACKAGE_NAME . '.tar.gz'; if (file_exists($filename)) { unlink($filename); } $this->assertFalse(file_exists($filename), 'Archive file already exists.'); $this->generator->generatePackages('archive', $this->assigner->getBundle(), [self::PACKAGE_NAME]); $this->assertTrue(file_exists($filename), 'Archive file was not generated.'); $archive = new ArchiveTar($filename); $files = $archive->listContent(); $this->assertEquals(4, count($files)); $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml', $files[0]['filename']); $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.features.yml', $files[1]['filename']); $this->assertEquals(self::PACKAGE_NAME . '/config/install/system.site.yml', $files[2]['filename']); $this->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.css', $files[3]['filename']); $expected_info = ["name" => "My test package", "type" => "module", "core" => "8.x", "dependencies" => ["node", "user"], "mykey" => "test value"]; $info = Yaml::decode($archive->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml')); $this->assertEquals($expected_info, $info, 'Incorrect info file generated'); $this->assertEquals($file_contents, $archive->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.css'), 'Extra file contents not retained'); }