function NodeImportCreateTest::testImportCreate

Same name in other branches
  1. 8.9.x core/modules/node/tests/src/Kernel/Config/NodeImportCreateTest.php \Drupal\Tests\node\Kernel\Config\NodeImportCreateTest::testImportCreate()
  2. 10 core/modules/node/tests/src/Kernel/Config/NodeImportCreateTest.php \Drupal\Tests\node\Kernel\Config\NodeImportCreateTest::testImportCreate()
  3. 11.x core/modules/node/tests/src/Kernel/Config/NodeImportCreateTest.php \Drupal\Tests\node\Kernel\Config\NodeImportCreateTest::testImportCreate()

Tests creating a content type during config import.

File

core/modules/node/tests/src/Kernel/Config/NodeImportCreateTest.php, line 54

Class

NodeImportCreateTest
Create content types during config create method invocation.

Namespace

Drupal\Tests\node\Kernel\Config

Code

public function testImportCreate() {
    $node_type_id = 'import';
    $node_type_config_name = "node.type.{$node_type_id}";
    // Simulate config data to import.
    $active = $this->container
        ->get('config.storage');
    $sync = $this->container
        ->get('config.storage.sync');
    $this->copyConfig($active, $sync);
    // Manually add new node type.
    $src_dir = __DIR__ . '/../../../modules/node_test_config/sync';
    $target_dir = Settings::get('config_sync_directory');
    $this->assertNotFalse(\Drupal::service('file_system')->copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml"));
    // Import the content of the sync directory.
    $this->configImporter()
        ->import();
    // Check that the content type was created.
    $node_type = NodeType::load($node_type_id);
    $this->assertNotEmpty($node_type, 'Import node type from sync was created.');
    $this->assertNull(FieldConfig::loadByName('node', $node_type_id, 'body'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.