diff --git a/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportChangeTest.php b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportChangeTest.php new file mode 100644 index 0000000..0dc848a --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportChangeTest.php @@ -0,0 +1,74 @@ +installSchema('system', array('config_snapshot')); + + // Set default storage backend. + $this->installConfig(array('field', 'node_test_config')); + } + + public static function getInfo() { + return array( + 'name' => 'Node config change tests', + 'description' => 'Change content types during config create method invocation.', + 'group' => 'Node', + ); + } + + /** + * Tests importing an updated content type. + */ + function testImportChange() { + $node_type_id = 'default'; + $node_type_config_name = "node.type.$node_type_id"; + + // Simulate config data to import: + // - the current manifest for node types, + // - a modified version (modified label) of the node type config. + $manifest_name = 'manifest.node.type'; + $active = $this->container->get('config.storage'); + $manifest = $active->read($manifest_name); + $node_type = $active->read($node_type_config_name); + $new_label = 'Test update import field'; + $node_type['name'] = $new_label; + + // Save as files in the the staging directory. + $staging = $this->container->get('config.storage.staging'); + $staging->write($manifest_name, $manifest); + $staging->write($node_type_config_name, $node_type); + + // Import the content of the staging directory. + config_import(); + + // Check that the updated config was correctly imported. + $node_type = entity_load('node_type', $node_type_id); + $this->assertEqual($node_type->label(), $new_label, 'Node type name has been updated.'); + } + +} diff --git a/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php new file mode 100644 index 0000000..202a2ab --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/Config/NodeImportCreateTest.php @@ -0,0 +1,89 @@ +installSchema('system', array('config_snapshot')); + + // Set default storage backend. + $this->installConfig(array('field')); + } + + public static function getInfo() { + return array( + 'name' => 'Node config create tests', + 'description' => 'Create content types during config create method invocation.', + 'group' => 'Node', + ); + } + + /** + * Tests creating a content type during default config import. + */ + function testImportCreateDefault() { + $node_type_id = 'default'; + + // Check that the content type does not exist yet. + $this->assertFalse(entity_load('node_type', $node_type_id)); + + // Enable node_test_config module and check that the content type + // shipped in the module's default config is created. + module_enable(array('node_test_config')); + $node_type = entity_load('node_type', $node_type_id); + $this->assertTrue($node_type, 'The default content type was created.'); + } + + /** + * Tests creating a content type during config import. + */ + function testImportCreate() { + $node_type_id = 'import'; + $node_type_config_name = "node.type.$node_type_id"; + $node_type_manifest_name = 'manifest.node.type'; + + // Simulate config data to import: + $src_dir = drupal_get_path('module', 'node_test_config') . '/staging'; + $this->assertTrue(file_unmanaged_copy("$src_dir/$node_type_config_name.yml", "public://config_staging/$node_type_config_name.yml")); + + // Add the coresponding entries to the current manifest data. + $active = $this->container->get('config.storage'); + $node_type_manifest = $active->read($node_type_manifest_name); + $node_type_manifest[$node_type_id] = array('name' => $node_type_config_name); + + // Save the manifests as files in the the staging directory. + $staging = $this->container->get('config.storage.staging'); + $staging->write($node_type_manifest_name, $node_type_manifest); + + // Import the content of the staging directory. + config_import(); + + // Check that the content type was created. + $node_type = entity_load('node_type', $node_type_id); + $this->assertTrue($node_type, 'Import node type from staging was created.'); + } + +} diff --git a/core/modules/node/tests/modules/node_test_config/config/node.type.default.yml b/core/modules/node/tests/modules/node_test_config/config/node.type.default.yml new file mode 100644 index 0000000..4a427fa --- /dev/null +++ b/core/modules/node/tests/modules/node_test_config/config/node.type.default.yml @@ -0,0 +1,23 @@ +type: default +name: Default +base: node_content +module: node +disabled: '0' +locked: '0' +custom: '1' +description: 'Default description.' +help: '' +modified: '1' +has_title: '1' +title_label: Title +settings: + node: + preview: '1' + options: + status: status + promote: promote + sticky: '0' + revision: '0' + submitted: '1' +status: '1' +langcode: und diff --git a/core/modules/node/tests/modules/node_test_config/node_test_config.info.yml b/core/modules/node/tests/modules/node_test_config/node_test_config.info.yml new file mode 100644 index 0000000..6a08e18 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_config/node_test_config.info.yml @@ -0,0 +1,6 @@ +name: 'Node configuration tests' +description: 'Support module for node configuration tests.' +core: 8.x +package: Testing +version: VERSION +hidden: TRUE diff --git a/core/modules/node/tests/modules/node_test_config/node_test_config.module b/core/modules/node/tests/modules/node_test_config/node_test_config.module new file mode 100644 index 0000000..00522b5 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_config/node_test_config.module @@ -0,0 +1,6 @@ +