You are here

public function NodeImportCreateTest::testImportCreate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/Config/NodeImportCreateTest.php \Drupal\node\Tests\Config\NodeImportCreateTest::testImportCreate()

Tests creating a content type during config import.

File

core/modules/node/src/Tests/Config/NodeImportCreateTest.php, line 58
Contains \Drupal\node\Tests\Config\NodeImportCreateTest.

Class

NodeImportCreateTest
Create content types during config create method invocation.

Namespace

Drupal\node\Tests\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 = drupal_get_path('module', 'node_test_config') . '/sync';
  $target_dir = $this->configDirectories[CONFIG_SYNC_DIRECTORY];
  $this
    ->assertTrue(file_unmanaged_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
    ->assertTrue($node_type, 'Import node type from sync was created.');
  $this
    ->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));
}