updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: short
label: 'Default short date'
locked: false
pattern: 'm/d/Y - H:i'
@@ -1,4 +1,3 @@
bundle: test
excluded:
- system.theme
required: true
@@ -6,8 +6,8 @@ package: Test
dependencies:
- features
# Information added by Drupal.org packaging script on 2016-09-02
version: '8.x-3.0-beta8'
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
core: '8.x'
project: 'features'
datestamp: 1472847281
datestamp: 1488908587
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: long
label: 'Default long date'
locked: false
pattern: 'l, F j, Y - H:i'
@@ -0,0 +1,3 @@
bundle: test_mybundle
excluded:
- system.theme
@@ -0,0 +1,13 @@
name: Test Core
type: module
# core: 8.x
package: Test
# Ensure features is enabled first
dependencies:
- features
# Information added by Drupal.org packaging script on 2017-03-07
version: '8.x-3.5'
core: '8.x'
project: 'features'
datestamp: 1488908587
@@ -4,6 +4,8 @@ namespace Drupal\Tests\features\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\features\ConfigurationItem;
use Drupal\features\FeaturesManagerInterface;
use Drupal\Core\Config\InstallStorage;
/**
* @group features
@@ -11,11 +13,15 @@ use Drupal\features\ConfigurationItem;
class FeaturesAssignTest extends KernelTestBase {
const PACKAGE_NAME = 'my_test_package';
// Installed test feature package
const TEST_INSTALLED_PACKAGE = 'test_mybundle_core';
// Uninstalled test feature package
const TEST_UNINSTALLED_PACKAGE = 'test_feature';
/**
* {@inheritdoc}
*/
public static $modules = ['features', 'node', 'system', 'user'];
public static $modules = ['features', 'node', 'system', 'user', self::TEST_INSTALLED_PACKAGE];
/**
* @var \Drupal\features\FeaturesManager
@@ -27,6 +33,11 @@ class FeaturesAssignTest extends KernelTestBase {
*/
protected $assigner;
/**
* @var \Drupal\features\FeaturesBundleInterface
*/
protected $bundle;
/**
* @todo Remove the disabled strict config schema checking.
*/
@@ -40,18 +51,129 @@ class FeaturesAssignTest extends KernelTestBase {
$this->installConfig('features');
$this->installConfig('system');
\Drupal::configFactory()->getEditable('features.settings')
->set('assignment.enabled', [])
->set('bundle.settings', [])
->save();
$this->featuresManager = \Drupal::service('features.manager');
$this->assigner = \Drupal::service('features_assigner');
$this->bundle = $this->assigner->getBundle();
// Turn off all assignment plugins.
$this->bundle->setEnabledAssignments([]);
// Start with an empty configuration collection.
$this->featuresManager->setConfigCollection([]);
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentAlter
*/
public function testAssignAlter() {
$method_id = 'alter';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Add some configuration.
$this->addConfigurationItem('example.settings', [
'_core' => ['something'],
'uuid' => 'something',
],
[
'type' => FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG,
]);
$this->addConfigurationItem('node.type.article', [
'_core' => ['something'],
'uuid' => 'something',
'permissions' => [
'first',
'second',
],
],
[
'type' => 'node_type',
]);
$this->addConfigurationItem('user.role.test', [
'_core' => ['something'],
'uuid' => 'something',
'permissions' => [
'first',
'second',
],
],
[
'type' => 'user_role',
]);
// Set all settings to FALSE.
$settings = [
'core' => FALSE,
'uuid' => FALSE,
'user_permissions' => FALSE,
];
$this->bundle->setAssignmentSettings($method_id, $settings);
$this->assigner->applyAssignmentMethod($method_id);
$config = $this->featuresManager->getConfigCollection();
$this->assertNotEmpty($config['example.settings'], 'Expected config not created.');
$this->assertNotEmpty($config['node.type.article'], 'Expected config not created.');
$this->assertNotEmpty($config['user.role.test'], 'Expected config not created.');
$example_settings_data = $config['example.settings']->getData();
$this->assertEquals($example_settings_data['_core'], ['something'], 'Expected _core value missing.');
$this->assertEquals($example_settings_data['uuid'], 'something', 'Expected uuid value missing.');
$node_type_data = $config['node.type.article']->getData();
$this->assertEquals($node_type_data['_core'], ['something'], 'Expected _core value missing.');
$this->assertEquals($node_type_data['uuid'], 'something', 'Expected uuid value missing.');
$this->assertEquals($node_type_data['permissions'], [
'first',
'second',
], 'Expected permissions value missing.');
$user_role_data = $config['user.role.test']->getData();
$this->assertEquals($user_role_data['_core'], ['something'], 'Expected _core value missing.');
$this->assertEquals($user_role_data['uuid'], 'something', 'Expected uuid value missing.');
$this->assertEquals($user_role_data['permissions'], [
'first',
'second',
], 'Expected permissions value missing.');
// Set all settings to TRUE.
$settings = [
'core' => TRUE,
'uuid' => TRUE,
'user_permissions' => TRUE,
];
$this->bundle->setAssignmentSettings($method_id, $settings);
$this->assigner->applyAssignmentMethod($method_id);
$config = $this->featuresManager->getConfigCollection();
$this->assertNotEmpty($config['example.settings'], 'Expected config not created.');
$this->assertNotEmpty($config['node.type.article'], 'Expected config not created.');
$this->assertNotEmpty($config['user.role.test'], 'Expected config not created.');
$example_settings_data = $config['example.settings']->getData();
$this->assertFalse(isset($example_settings_data['_core']), 'Unexpected _core value present.');
// uuid should be retained for simple configuration.
$this->assertEquals($example_settings_data['uuid'], 'something', 'Expected uuid value missing.');
$node_type_data = $config['node.type.article']->getData();
$this->assertFalse(isset($node_type_data['_core']), 'Unexpected _core value present.');
$this->assertFalse(isset($node_type_data['uuid']), 'Unexpected uuid value present.');
// permissions should be stripped only for user_role configuration.
$this->assertEquals($node_type_data['permissions'], [
'first',
'second',
], 'Expected permissions value missing.');
$user_role_data = $config['user.role.test']->getData();
$this->assertFalse(isset($user_role_data['_core']), 'Unexpected _core value present.');
$this->assertFalse(isset($user_role_data['uuid']), 'Unexpected uuid value present.');
$this->assertFalse(isset($user_role_data['permissions']), 'Unexpected permissions value present.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentBaseType
*/
@@ -86,15 +208,14 @@ class FeaturesAssignTest extends KernelTestBase {
$expected_package_names = ['article', 'user'];
$this->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
$this->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
// Dependents like field.field.node.article.body should not be assigned.
$expected_config_items = [
'node.type.article',
'field.field.node.article.body',
];
$this->assertEquals($expected_config_items, $packages['article']->getConfig(), 'Expected configuration items not present in article package.');
}
/**
@@ -130,11 +251,10 @@ class FeaturesAssignTest extends KernelTestBase {
$expected_package_names = ['core'];
$this->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
$this->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
$this->assertTrue(in_array('field.storage.node.body', $packages['core']->getConfig(), 'Expected configuration item not present in core package.'));
$this->assertFalse(in_array('field.field.node.article.body', $packages['core']->getConfig(), 'Unexpected configuration item present in core package.'));
}
/**
@@ -182,7 +302,168 @@ class FeaturesAssignTest extends KernelTestBase {
];
$this->assertEquals($expected_config_items, $packages[self::PACKAGE_NAME]->getConfig(), 'Expected configuration items not present in article package.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentExclude
*/
public function testAssignExclude() {
$method_id = 'exclude';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Also enable Packages and Core plugins.
$this->enableAssignmentMethod('packages', FALSE);
$this->enableAssignmentMethod('core', FALSE);
// Apply the bundle
$this->bundle = $this->assigner->loadBundle('test_mybundle');
$this->assigner->applyAssignmentMethod('packages');
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_INSTALLED_PACKAGE], 'Expected package not created.');
// 1. When Required is set to True, config should stay with the module
// First, test with "Required" set to True.
$packages[self::TEST_INSTALLED_PACKAGE]->setRequired(true);
$this->featuresManager->setPackages($packages);
$this->assigner->applyAssignmentMethod('exclude');
$this->assigner->applyAssignmentMethod('core');
$this->assigner->applyAssignmentMethod('existing');
$packages = $this->featuresManager->getPackages();
$expected_config_items = [
'core.date_format.long',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_INSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing test_core package.');
// 2. When Required is set to False, config still stays with module
// Because the module is installed.
$this->reset();
$this->bundle = $this->assigner->loadBundle('test_mybundle');
$this->assigner->applyAssignmentMethod('packages');
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_INSTALLED_PACKAGE], 'Expected test_mybundle_core package not created.');
// Set "Required" set to False
$packages[self::TEST_INSTALLED_PACKAGE]->setRequired(false);
$this->featuresManager->setPackages($packages);
$this->assigner->applyAssignmentMethod('exclude');
$this->assigner->applyAssignmentMethod('core');
$this->assigner->applyAssignmentMethod('existing');
$packages = $this->featuresManager->getPackages();
$this->assertFalse(array_key_exists('core', $packages), 'Core package should not be created.');
$expected_config_items = [
'core.date_format.long',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_INSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing test_core package.');
// 3. When Required is set to False and module is NOT installed,
// Config stays with module if it doesn't match the current namespace
$this->reset();
// Load a bundle different from TEST_UNINSTALLED_PACKAGE
$this->bundle = $this->assigner->loadBundle('test_mybundle');
$this->assigner->applyAssignmentMethod('packages');
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_UNINSTALLED_PACKAGE], 'Expected test_feature package not created.');
$this->assertNotEmpty($packages[self::TEST_INSTALLED_PACKAGE], 'Expected test_mybundle_core package not created.');
// Mark package as uninstalled, set "Required" set to False
$packages[self::TEST_UNINSTALLED_PACKAGE]->setRequired(false);
$this->featuresManager->setPackages($packages);
$this->assigner->applyAssignmentMethod('exclude');
$this->assigner->applyAssignmentMethod('core');
$this->assigner->applyAssignmentMethod('existing');
$packages = $this->featuresManager->getPackages();
$this->assertFalse(array_key_exists('core', $packages), 'Core package should not be created.');
$expected_config_items = [
'core.date_format.short',
'system.cron',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_UNINSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing test_feature package.');
// 4. When Required is set to False and module is NOT installed,
// Config is reassigned within modules that match the namespace.
$this->reset();
// Load the bundle used in TEST_UNINSTALLED_PACKAGE
$this->bundle = $this->assigner->loadBundle('test');
if (empty($this->bundle) || $this->bundle->isDefault()) {
// Since we uninstalled the test_feature, we probably need to create
// an empty "test" bundle
$this->bundle = $this->assigner->createBundleFromDefault('test');
}
$this->assigner->applyAssignmentMethod('packages');
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_UNINSTALLED_PACKAGE], 'Expected test_feature package not created.');
// Set "Required" set to False
$packages[self::TEST_UNINSTALLED_PACKAGE]->setRequired(false);
$this->featuresManager->setPackages($packages);
$this->assigner->applyAssignmentMethod('exclude');
$this->assigner->applyAssignmentMethod('core');
$this->assigner->applyAssignmentMethod('existing');
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages['core'], 'Expected Core package not created.');
// Ensure "core" package is not confused with "test_core" module
// Since we are in a bundle
$this->assertEmpty($packages['core']->getExtension(), 'Autogenerated core package should not have an extension');
// Core config should be reassigned from TEST_UNINSTALLED_PACKAGE into Core
$expected_config_items = [
'system.cron',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_UNINSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing test_feature package.');
$expected_config_items = [
'core.date_format.short',
];
$this->assertEquals($expected_config_items, $packages['core']->getConfig(), 'Expected configuration items not present in core package.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentExclude
*/
public function testAssignExisting() {
$method_id = 'existing';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Also enable Packages plugin.
$this->enableAssignmentMethod('packages', FALSE);
// First create the existing packages.
$this->assigner->applyAssignmentMethod('packages');
// Now move config into those existing packages.
$this->assigner->applyAssignmentMethod($method_id);
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::TEST_INSTALLED_PACKAGE], 'Expected package not created.');
$this->assertNotEmpty($packages[self::TEST_UNINSTALLED_PACKAGE], 'Expected package not created.');
// Turn off any "required" option in package to let config get reassigned
$package = $packages[self::TEST_INSTALLED_PACKAGE];
$package->setRequired(true);
$expected_config_items = [
'core.date_format.long',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_INSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing package.');
$expected_config_items = [
'core.date_format.short',
'system.cron',
];
$this->assertEquals($expected_config_items, $packages[self::TEST_UNINSTALLED_PACKAGE]->getConfig(), 'Expected configuration items not present in existing package.');
}
/**
@@ -258,6 +539,254 @@ class FeaturesAssignTest extends KernelTestBase {
$this->assertEquals($expected_config_items, $actual_config_items, 'Expected configuration items not present in article package.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentNamespace
*/
public function testAssignNamespace() {
$method_id = 'namespace';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Apply the bundle
$this->bundle = $this->assigner->loadBundle('test_mybundle');
$package_data = [
'article' => [
// Items that should be assigned to 'article'.
'article',
'article-after',
'before.article',
'something_article',
'something-article',
'something.article',
'article_something',
'article-something',
'article.something',
'something_article_something',
'something-article-something',
'something.article.something',
'something.article_something',
],
'article_after' => [
// Items that should be assigned to 'article_after'.
'article_after',
'something_article_after',
'something-article_after',
'something.article_after',
'article_after_something',
'article_after-something',
'article_after.something',
'something_article_after_something',
'something-article_after-something',
'something.article_after.something',
'something.article_after_something',
],
'before_article' => [
// Items that should be assigned to 'before_article'.
'before_article',
'something_before_article',
'something-before_article',
'something.before_article',
'before_article_something',
'before_article-something',
'before_article.something',
'something_before_article_something',
'something-before_article-something',
'something.before_article.something',
'something.before_article_something',
],
// Emulate an existing feature, which has a machine name prefixed by
// the bundle name.
'test_mybundle_page' => [
// Items that should be assigned to 'test_mybundle_page'.
// Items should match the short name, 'page'.
'page',
'page-after',
'before.page',
'something_page',
'something-page',
'something.page',
'page_something',
'page-something',
'page.something',
'something_page_something',
'something-page-something',
'something.page.something',
'something.page_something',
],
];
foreach ($package_data as $machine_name => $config_short_names) {
$this->featuresManager->initPackage($machine_name, 'My test package ' . $machine_name);
foreach ($config_short_names as $short_name) {
$this->addConfigurationItem('node.type.' . $short_name, [], [
'type' => 'node_type',
'shortName' => $short_name,
]);
}
}
// Add some config that should not be matched.
$config_short_names = [
'example',
'example_something',
'article~',
'myarticle',
];
foreach ($config_short_names as $short_name) {
$this->addConfigurationItem('node.type.' . $short_name, [], [
'type' => 'node_type',
'shortName' => $short_name,
]);
}
$this->assigner->applyAssignmentMethod($method_id);
$packages = $this->featuresManager->getPackages();
foreach ($package_data as $machine_name => $config_short_names) {
$this->assertNotEmpty($packages[$machine_name], 'Expected package ' . $machine_name . ' not created.');
array_walk($config_short_names, function(&$value) {
$value = 'node.type.' . $value;
});
sort($config_short_names);
$package_config = $packages[$machine_name]->getConfig();
sort($package_config);
$this->assertEquals($config_short_names, $package_config, 'Expected configuration items not present in ' . $machine_name . ' package.');
}
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentOptionalType
*/
public function testAssignOptionalType() {
$method_id = 'optional';
// Enable the method.
$this->enableAssignmentMethod($method_id);
$settings = [
'types' => [
'config' => ['image_style'],
],
];
$this->bundle->setAssignmentSettings($method_id, $settings);
// Add some configuration.
$this->addConfigurationItem('node.type.article', [], [
'type' => 'node_type',
]);
$this->addConfigurationItem('image.style.test', [], [
'type' => 'image_style',
]);
$this->featuresManager->initPackage(self::PACKAGE_NAME, 'My test package');
$this->assigner->applyAssignmentMethod($method_id);
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages[self::PACKAGE_NAME], 'Expected package not created.');
$config = $this->featuresManager->getConfigCollection();
$this->assertNotEmpty($config['node.type.article'], 'Expected config not created.');
$this->assertNotEmpty($config['image.style.test'], 'Expected config not created.');
$this->assertNull($config['node.type.article']->getSubdirectory(), 'Expected package subdirectory not set to default.');
$this->assertEquals($config['image.style.test']->getSubdirectory(), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, 'Expected package subdirectory not set to optional.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentPackages
*/
public function testAssignPackages() {
$method_id = 'packages';
// 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.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentProfile
*/
public function testAssignProfile() {
$method_id = 'profile';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Add some configuration.
$this->addConfigurationItem('shortcut.myshortcut', [], [
'type' => 'shortcut_set',
]);
$this->addConfigurationItem('node.type.article', [], [
'type' => 'node_type',
]);
$this->addConfigurationItem('image.style.test', [], [
'type' => 'image_style',
]);
$this->addConfigurationItem('system.cron', [], [
'type' => 'simple',
]);
$this->bundle = $this->assigner->createBundleFromDefault('myprofile');
$this->bundle->setProfileName('myprofile');
$this->bundle->setIsProfile(TRUE);
$this->assigner->applyAssignmentMethod($method_id);
$packages = $this->featuresManager->getPackages();
$this->assertNotEmpty($packages['myprofile'], 'Expected package not created.');
$expected_config_items = [
'shortcut.myshortcut',
'system.cron',
'system.theme',
];
$this->assertEquals($expected_config_items, $packages['myprofile']->getConfig(), 'Expected configuration items not present in package.');
}
/**
* @covers Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentSiteType
*/
public function testAssignSiteType() {
$method_id = 'site';
// Enable the method.
$this->enableAssignmentMethod($method_id);
// Test the default options for the site assignment method.
// Add a piece of configuration of a site type.
$this->addConfigurationItem('filter.format.plain_text', [], [
'shortName' => 'plain_text',
'label' => 'Plain text',
'type' => 'filter_format',
]);
// Add a piece of configuration of a non-site type.
$this->addConfigurationItem('field.field.node.article.body', [], [
'shortName' => 'node.article.body',
'label' => 'Body',
'type' => 'field_config',
'dependents' => [],
]);
$this->assigner->applyAssignmentMethod($method_id);
$packages = $this->featuresManager->getPackages();
$expected_package_names = ['site'];
$this->assertEquals($expected_package_names, array_keys($packages), 'Expected packages not created.');
$this->assertTrue(in_array('filter.format.plain_text', $packages['site']->getConfig(), 'Expected configuration item not present in site package.'));
$this->assertFalse(in_array('field.field.node.article.body', $packages['site']->getConfig(), 'Unexpected configuration item present in site package.'));
}
/**
* Enables a specified assignment method.
*
@@ -268,18 +797,14 @@ class FeaturesAssignTest extends KernelTestBase {
* Defaults to TRUE.
*/
protected function enableAssignmentMethod($method_id, $exclusive = TRUE) {
$settings = \Drupal::configFactory()->getEditable('features.settings');
if ($exclusive) {
$settings->set('assignment.enabled', [$method_id]);
$this->bundle->setEnabledAssignments([$method_id]);
}
else {
$enabled = $settings->get('assignment.enabled');
if (!in_array($method_id, $enabled)) {
$enabled[] = $method_id;
}
$settings->set('assignment.enabled', $enabled);
$enabled = array_keys($this->bundle->getEnabledAssignments());
$enabled[] = $method_id;
$this->bundle->setEnabledAssignments($enabled);
}
$settings->save();
}
/**
@@ -298,4 +823,12 @@ class FeaturesAssignTest extends KernelTestBase {
$this->featuresManager->setConfigCollection($config_collection);
}
/**
* Reset the config to reapply assignment plugins
*/
protected function reset() {
$this->assigner->reset();
// Start with an empty configuration collection.
$this->featuresManager->setConfigCollection([]);
}
}
@@ -4,6 +4,8 @@ namespace Drupal\Tests\features\Kernel;
use Drupal\features\Entity\FeaturesBundle;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Archiver\ArchiveTar;
use org\bovigo\vfs\vfsStream;
/**
@@ -12,6 +14,7 @@ use org\bovigo\vfs\vfsStream;
class FeaturesGenerateTest extends KernelTestBase {
const PACKAGE_NAME = 'my_test_package';
const BUNDLE_NAME = 'giraffe';
/**
* {@inheritdoc}
@@ -43,10 +46,6 @@ class FeaturesGenerateTest extends KernelTestBase {
$this->installConfig('features');
$this->installConfig('system');
\Drupal::configFactory()->getEditable('features.settings')
->set('assignment.enabled', [])
->set('bundle.settings', [])
->save();
$this->featuresManager = \Drupal::service('features.manager');
$this->generator = \Drupal::service('features_generator');
@@ -70,18 +69,33 @@ class FeaturesGenerateTest extends KernelTestBase {
$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(3, 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']);
$expected_info = [
"name" => "My test package",
"type" => "module",
"core" => "8.x",
];
$info = Yaml::decode($archive->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml'));
$this->assertEquals($expected_info, $info, 'Incorrect info file generated');
}
public function testGeneratorWithBundle() {
$filename = file_directory_temp() . '/giraffe_' . self::PACKAGE_NAME . '.tar.gz';
$filename = file_directory_temp() . '/' . self::BUNDLE_NAME . '_' . self::PACKAGE_NAME . '.tar.gz';
if (file_exists($filename)) {
unlink($filename);
}
$this->assertFalse(file_exists($filename), 'Archive file already exists.');
$bundle = FeaturesBundle::create([
'machine_name' => 'giraffe'
'machine_name' => self::BUNDLE_NAME
]);
$this->generator->generatePackages('archive', $bundle, [self::PACKAGE_NAME]);
@@ -89,9 +103,9 @@ class FeaturesGenerateTest extends KernelTestBase {
$package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
$this->assertNull($package);
$package = $this->featuresManager->getPackage('giraffe_' . self::PACKAGE_NAME);
$this->assertEquals('giraffe_' . self::PACKAGE_NAME, $package->getMachineName());
$this->assertEquals('giraffe', $package->getBundle());
$package = $this->featuresManager->getPackage( self::BUNDLE_NAME . '_' . self::PACKAGE_NAME);
$this->assertEquals(self::BUNDLE_NAME . '_' . self::PACKAGE_NAME, $package->getMachineName());
$this->assertEquals(self::BUNDLE_NAME, $package->getBundle());
$this->assertTrue(file_exists($filename), 'Archive file was not generated.');
}
@@ -103,6 +117,7 @@ class FeaturesGenerateTest extends KernelTestBase {
// 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
@@ -114,9 +129,82 @@ class FeaturesGenerateTest extends KernelTestBase {
$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($path . '/' . self::PACKAGE_NAME . '.info.yml'), 'Package info.yml 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');
}
}
@@ -0,0 +1,103 @@
<?php
namespace Drupal\Tests\features\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\features\ConfigurationItem;
use Drupal\features\Package;
/**
* @group features
*/
class FeaturesManagerKernelTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'config', 'features'];
protected $strictConfigSchema = FALSE;
/**
* @var \Drupal\features\FeaturesManagerInterface
*/
protected $featuresManager;
/**
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig('features');
$this->installConfig('system');
$this->featuresManager = $this->container->get('features.manager');
$this->configFactory = $this->container->get('config.factory');
}
/**
* @covers \Drupal\features\FeaturesManager::createConfiguration
*/
public function testCreateConfiguration() {
$config_name = 'system_simple.testcreate';
$config = [
'string_value' => 'example',
'array_value' => [
'item1' => 'value1',
'item2' => 'value2',
],
];
$this->featuresManager->createConfiguration([$config_name => $config]);
$config_item = $this->configFactory->get($config_name);
$this->assertEquals($config['string_value'], $config_item->get('string_value'), 'Test config string saved');
$this->assertEquals($config['array_value'], $config_item->get('array_value'), 'Test config array saved');
}
/**
* @covers \Drupal\features\FeaturesManager::import
*/
public function testImport() {
$packages = [
'package' => new Package('package', [
'configOrig' => ['system_simple.example' => 'system_simple.example'],
'dependencies' => [],
'bundle' => '',
]),
'package2' => new Package('package2', [
'configOrig' => ['system_simple.example2' => 'system_simple.example2'],
'dependencies' => [],
'bundle' => '',
]),
'package3' => new Package('package3', [
'configOrig' => ['system_simple.example3' => 'system_simple.example3'],
'dependencies' => [],
'bundle' => '',
]),
];
$this->featuresManager->setPackages($packages);
// Create all three configuration items.
$config_item = new ConfigurationItem('system_simple.example', ['value' => 'example'], ['package' => 'package']);
$config_item2 = new ConfigurationItem('system_simple.example2', ['value' => 'example2'], ['package' => 'package2']);
$config_item3 = new ConfigurationItem('system_simple.example3', ['value' => 'example3'], ['package' => 'package3']);
// Only save example and example3 as currently active config (so example2 will be new).
$this->featuresManager->setConfigCollection(['system_simple.example' => $config_item, 'system_simple.example3' => $config_item3]);
// Only import example and example2, so example3 is unchanged.
$result = $this->featuresManager->import(['package', 'package2']);
$this->assertEquals(['system_simple.example'], array_keys($result['package']['updated']), 'Expected config updated');
$this->assertEquals(['system_simple.example2'], array_keys($result['package2']['new']), 'Expected config created');
// Test if config was actually saved to the Factory.
// Cannot test for example2 because we didn't save the original config data
// and Package2 isn't a real module so config can't be loaded from module.
$example = $this->configFactory->get('system_simple.example')->get('value');
$this->assertEquals('example', $example, 'Example config saved');
}
}
@@ -5,7 +5,7 @@ namespace Drupal\Tests\features\Unit;
use Drupal\features\Entity\FeaturesBundle;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Prophecy\Prophet;
use Drupal\Core\Site\Settings;
/**
* @coversDefaultClass Drupal\features\Entity\FeaturesBundle
@@ -145,6 +145,47 @@ class FeaturesBundleTest extends UnitTestCase {
}
/**
* @covers ::getFullName
* @covers ::getShortName
* @covers ::SetIsProfile
* @covers ::isProfile
* @covers ::getProfileName
* @covers ::isProfilePackage
* @covers ::inBundle
*/
public function testFullname() {
$bundle = new FeaturesBundle([
'machine_name' => 'mybundle',
'profile_name' => 'mybundle'
], 'mybundle');
$this->assertFalse($bundle->isProfile());
// Settings:get('profile_name') isn't defined in test, so this returns NULL.
$this->assertNull($bundle->getProfileName());
$this->assertFalse($bundle->isProfilePackage('mybundle'));
$this->assertEquals('mybundle_test', $bundle->getFullName('test'));
$this->assertEquals('mybundle_test', $bundle->getFullName('mybundle_test'));
$this->assertEquals('mybundle_mybundle', $bundle->getFullName('mybundle'));
$this->assertEquals('test', $bundle->getShortName('test'));
$this->assertEquals('test', $bundle->getShortName('mybundle_test'));
$this->assertEquals('mybundle', $bundle->getShortName('mybundle_mybundle'));
$this->assertEquals('mybundle', $bundle->getShortName('mybundle'));
$this->assertFalse($bundle->inBundle('test'));
$this->assertTrue($bundle->inBundle('mybundle_test'));
$this->assertFalse($bundle->inBundle('mybundle'));
// Now test it as a profile bundle.
$bundle->setIsProfile(TRUE);
$this->assertTrue($bundle->isProfile());
$this->assertTrue($bundle->isProfilePackage('mybundle'));
$this->assertFalse($bundle->isProfilePackage('standard'));
$this->assertEquals('mybundle', $bundle->getProfileName());
$this->assertEquals('mybundle', $bundle->getFullName('mybundle'));
$this->assertFalse($bundle->inBundle('test'));
$this->assertTrue($bundle->inBundle('mybundle_test'));
$this->assertTrue($bundle->inBundle('mybundle'));
}
}
/**
@@ -13,6 +13,7 @@ use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\InfoParser;
use Drupal\Core\Extension\InfoParserInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\config_update\ConfigRevertInterface;
use Drupal\features\Entity\FeaturesBundle;
use Drupal\features\FeaturesAssignerInterface;
use Drupal\features\FeaturesBundleInterface;
@@ -42,9 +43,9 @@ class FeaturesManagerTest extends UnitTestCase {
protected $featuresManager;
/**
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
protected $entityTypeManager;
/**
* @var \Drupal\Core\Config\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -66,31 +67,56 @@ class FeaturesManagerTest extends UnitTestCase {
*/
protected $moduleHandler;
/**
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configReverter;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
$container->set('app.root', $this->root);
// Since in Drupal 8.3 the "\Drupal::installProfile()" was introduced
// then we have to spoof a value for the "install_profile" parameter
// because it will be used by "ExtensionInstallStorage" class, which
// extends the "FeaturesInstallStorage".
// @see \Drupal\features\FeaturesConfigInstaller::__construct()
$container->setParameter('install_profile', '');
\Drupal::setContainer($container);
$entity_type = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
$entity_type->expects($this->any())
->method('getConfigPrefix')
->willReturn('custom');
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager->expects($this->any())
$entity_type->expects($this->any())
->method('getProvider')
->willReturn('my_module');
$this->entityTypeManager = $this->getMock('\Drupal\Core\Entity\EntityTypeManagerInterface');
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->willReturn($entity_type);
$this->configFactory = $this->getMock(ConfigFactoryInterface::class);
$this->configStorage = $this->getMock(StorageInterface::class);
$this->configManager = $this->getMock(ConfigManagerInterface::class);
$this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
$this->featuresManager = new FeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$string_translation = $this->getStringTranslationStub();
$container = new ContainerBuilder();
$container->set('string_translation', $string_translation);
$container->set('app.root', $this->root);
\Drupal::setContainer($container);
// getModuleList should return an array of extension objects.
// but we just need ::getConfigDependency isset($module_list[$provider]).
$this->moduleHandler->expects($this->any())
->method('getModuleList')
->willReturn(['my_module' => true]);
$this->configReverter = $this->getMock(ConfigRevertInterface::class);
$this->configReverter->expects($this->any())
->method('import')
->willReturn(true);
$this->configReverter->expects($this->any())
->method('revert')
->willReturn(true);
$this->featuresManager = new FeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
}
/**
@@ -154,9 +180,12 @@ class FeaturesManagerTest extends UnitTestCase {
/**
* @covers ::setPackage
* @covers ::getPackage
*/
public function testSetPackage() {
// @todo
$package = new Package('foo');
$this->featuresManager->setPackage($package);
$this->assertEquals($package, $this->featuresManager->getPackage('foo'));
}
protected function getAssignInterPackageDependenciesConfigCollection() {
@@ -199,7 +228,7 @@ class FeaturesManagerTest extends UnitTestCase {
$bundle->isDefault()->willReturn(TRUE);
$assigner->getBundle('')->willReturn($bundle->reveal());
// Use the wrapper because we need ::drupalGetProfile().
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setAssigner($assigner->reveal());
$features_manager->setConfigCollection($this->getAssignInterPackageDependenciesConfigCollection());
@@ -247,7 +276,7 @@ class FeaturesManagerTest extends UnitTestCase {
$bundle->getMachineName()->willReturn('giraffe');
$assigner->getBundle('giraffe')->willReturn($bundle->reveal());
// Use the wrapper because we need ::drupalGetProfile().
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setAssigner($assigner->reveal());
$features_manager->setConfigCollection($this->getAssignInterPackageDependenciesConfigCollection());
@@ -375,7 +404,7 @@ class FeaturesManagerTest extends UnitTestCase {
]);
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $config_storage->reveal(), $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $config_storage->reveal(), $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setExtensionStorages($extension_storage->reveal());
$this->assertEquals(['test_overridden'], $features_manager->detectOverrides($package));
@@ -409,7 +438,7 @@ class FeaturesManagerTest extends UnitTestCase {
$this->featuresManager->assignConfigPackage('test_package', ['test_config', 'test_config2']);
$this->assertEquals(['test_config', 'test_config2'], $this->featuresManager->getPackage('test_package')->getConfig());
$this->assertEquals(['example'], $this->featuresManager->getPackage('test_package')->getDependencies());
$this->assertEquals(['example', 'my_module'], $this->featuresManager->getPackage('test_package')->getDependencies());
}
/**
@@ -454,7 +483,7 @@ class FeaturesManagerTest extends UnitTestCase {
\Drupal::getContainer()->set('info_parser', $info_parser->reveal());
$bundle = $this->prophesize(FeaturesBundle::class);
$bundle->getShortName('test_module')->willReturn('test_module');
$bundle->getFullName('test_module')->willReturn('test_module');
$bundle->isDefault()->willReturn(TRUE);
$assigner = $this->prophesize(FeaturesAssignerInterface::class);
@@ -491,7 +520,7 @@ class FeaturesManagerTest extends UnitTestCase {
\Drupal::getContainer()->set('info_parser', $info_parser->reveal());
$bundle = $this->prophesize(FeaturesBundle::class);
$bundle->getShortName('test_module')->willReturn('test_module');
$bundle->getFullName('test_module')->willReturn('test_module');
$bundle->isDefault()->willReturn(TRUE);
$assigner = $this->prophesize(FeaturesAssignerInterface::class);
@@ -521,7 +550,7 @@ class FeaturesManagerTest extends UnitTestCase {
'key' => 'value',
]);
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setExtensionStorages($extension_storage->reveal());
$this->assertEmpty($features_manager->detectNew($package));
@@ -533,7 +562,7 @@ class FeaturesManagerTest extends UnitTestCase {
$extension_storage = $this->prophesize(FeaturesExtensionStoragesInterface::class);
$extension_storage->read('test_config')->willReturn(FALSE);
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setExtensionStorages($extension_storage->reveal());
$this->assertEquals(['test_config'], $features_manager->detectNew($package));
@@ -574,7 +603,7 @@ class FeaturesManagerTest extends UnitTestCase {
public function testInitPackageWithNewPackage() {
$bundle = new FeaturesBundle(['machine_name' => 'test'], 'features_bundle');
$features_manager = new TestFeaturesManager($this->root, $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$features_manager->setAllModules([]);
$package = $features_manager->initPackage('test_feature', 'test name', 'test description', 'module', $bundle);
@@ -597,7 +626,7 @@ class FeaturesManagerTest extends UnitTestCase {
public function testInitPackageWithExistingPackage() {
$bundle = new FeaturesBundle(['machine_name' => 'test'], 'features_bundle');
$features_manager = new TestFeaturesManager('vfs://drupal', $this->entityManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler);
$features_manager = new TestFeaturesManager('vfs://drupal', $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
vfsStream::setup('drupal');
\Drupal::getContainer()->set('app.root', 'vfs://drupal');
@@ -702,7 +731,7 @@ EOT
],
],
]);
$this->featuresManager = new FeaturesManager($this->root, $this->entityManager, $config_factory, $this->configStorage, $this->configManager, $this->moduleHandler);
$this->featuresManager = new FeaturesManager($this->root, $this->entityTypeManager, $config_factory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$package = new Package('test_feature');
$result = $this->featuresManager->getExportInfo($package);
@@ -721,7 +750,7 @@ EOT
],
],
]);
$this->featuresManager = new FeaturesManager($this->root, $this->entityManager, $config_factory, $this->configStorage, $this->configManager, $this->moduleHandler);
$this->featuresManager = new FeaturesManager($this->root, $this->entityTypeManager, $config_factory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter);
$package = new Package('test_feature');
$bundle = new FeaturesBundle(['machine_name' => 'test_bundle'], 'features_bundle');