NodeImportCreateTest.php in Drupal 9
File
core/modules/node/tests/src/Kernel/Config/NodeImportCreateTest.php
View source
<?php
namespace Drupal\Tests\node\Kernel\Config;
use Drupal\Core\Site\Settings;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\KernelTests\KernelTestBase;
class NodeImportCreateTest extends KernelTestBase {
protected static $modules = [
'node',
'field',
'text',
'system',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installConfig([
'system',
'field',
]);
}
public function testImportCreateDefault() {
$node_type_id = 'default';
$this
->assertNull(NodeType::load($node_type_id));
$this->container
->get('module_installer')
->install([
'node_test_config',
]);
$node_type = NodeType::load($node_type_id);
$this
->assertNotEmpty($node_type, 'The default content type was created.');
}
public function testImportCreate() {
$node_type_id = 'import';
$node_type_config_name = "node.type.{$node_type_id}";
$active = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$this
->copyConfig($active, $sync);
$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"));
$this
->configImporter()
->import();
$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'));
}
}