NodeImportCreateTest.php in Zircon Profile 8
File
core/modules/node/src/Tests/Config/NodeImportCreateTest.php
View source
<?php
namespace Drupal\node\Tests\Config;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase;
class NodeImportCreateTest extends KernelTestBase {
public static $modules = array(
'node',
'field',
'text',
'system',
'user',
);
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installConfig(array(
'field',
));
}
public function testImportCreateDefault() {
$node_type_id = 'default';
$this
->assertFalse(NodeType::load($node_type_id));
$this->container
->get('module_installer')
->install(array(
'node_test_config',
));
$node_type = NodeType::load($node_type_id);
$this
->assertTrue($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 = 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"));
$this
->configImporter()
->import();
$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'));
}
}