3 namespace Drupal\Tests\node\Kernel\Config;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\KernelTests\KernelTestBase;
10 * Create content types during config create method invocation.
14 class NodeImportCreateTest extends KernelTestBase {
21 public static $modules = ['node', 'field', 'text', 'system', 'user'];
24 * Set the default field storage backend for fields created during tests.
26 protected function setUp() {
28 $this->installEntitySchema('user');
30 // Set default storage backend.
31 $this->installConfig(['field']);
35 * Tests creating a content type during default config import.
37 public function testImportCreateDefault() {
38 $node_type_id = 'default';
40 // Check that the content type does not exist yet.
41 $this->assertFalse(NodeType::load($node_type_id));
43 // Enable node_test_config module and check that the content type
44 // shipped in the module's default config is created.
45 $this->container->get('module_installer')->install(['node_test_config']);
46 $node_type = NodeType::load($node_type_id);
47 $this->assertTrue($node_type, 'The default content type was created.');
51 * Tests creating a content type during config import.
53 public function testImportCreate() {
54 $node_type_id = 'import';
55 $node_type_config_name = "node.type.$node_type_id";
57 // Simulate config data to import.
58 $active = $this->container->get('config.storage');
59 $sync = $this->container->get('config.storage.sync');
60 $this->copyConfig($active, $sync);
61 // Manually add new node type.
62 $src_dir = __DIR__ . '/../../../modules/node_test_config/sync';
63 $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
64 $this->assertTrue(file_unmanaged_copy("$src_dir/$node_type_config_name.yml", "$target_dir/$node_type_config_name.yml"));
66 // Import the content of the sync directory.
67 $this->configImporter()->import();
69 // Check that the content type was created.
70 $node_type = NodeType::load($node_type_id);
71 $this->assertTrue($node_type, 'Import node type from sync was created.');
72 $this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));