Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Config / NodeImportCreateTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Config;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * Create content types during config create method invocation.
11  *
12  * @group node
13  */
14 class NodeImportCreateTest extends KernelTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['node', 'field', 'text', 'system', 'user'];
22
23   /**
24    * Set the default field storage backend for fields created during tests.
25    */
26   protected function setUp() {
27     parent::setUp();
28     $this->installEntitySchema('user');
29
30     // Set default storage backend.
31     $this->installConfig(['system', 'field']);
32   }
33
34   /**
35    * Tests creating a content type during default config import.
36    */
37   public function testImportCreateDefault() {
38     $node_type_id = 'default';
39
40     // Check that the content type does not exist yet.
41     $this->assertFalse(NodeType::load($node_type_id));
42
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.');
48   }
49
50   /**
51    * Tests creating a content type during config import.
52    */
53   public function testImportCreate() {
54     $node_type_id = 'import';
55     $node_type_config_name = "node.type.$node_type_id";
56
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"));
65
66     // Import the content of the sync directory.
67     $this->configImporter()->import();
68
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'));
73   }
74
75 }