View source
<?php
namespace Drupal\Tests\eck\Functional;
use Drupal\Core\Url;
class ConfigImportTest extends FunctionalTestBase {
protected $profile = 'standard';
public function setUp() {
parent::setUp();
$permissions = [
'export configuration',
'synchronize configuration',
'administer eck entity types',
'administer eck entities',
'administer eck entity bundles',
'bypass eck entity access',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$configFactory = \Drupal::configFactory();
$sync = $this->container
->get('config.storage.sync');
$config = $configFactory
->loadMultiple($configFactory
->listAll());
foreach ($config as $name => $conf) {
$sync
->write($name, $conf
->getRawData());
}
}
public function testImport() {
$defaultLanguage = \Drupal::languageManager()
->getDefaultLanguage();
$entityTypeConfigName = 'eck.eck_entity_type.test_entity';
$entityBundleConfigName = 'eck.eck_type.test_entity.bundle';
$storage = $this->container
->get('config.storage');
$sync = $this->container
->get('config.storage.sync');
$this
->assertFalse($storage
->exists($entityTypeConfigName), 'Entity config absent as expected.');
$this
->assertFalse($storage
->exists($entityBundleConfigName), 'Bundle config absent as expected');
$entityTypeConfiguration = [
'id' => 'test_entity',
'label' => 'Test entity',
'langcode' => $defaultLanguage
->getId(),
'dependencies' => [],
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'status' => TRUE,
'uid' => TRUE,
'created' => TRUE,
'changed' => TRUE,
'title' => TRUE,
];
$sync
->write($entityTypeConfigName, $entityTypeConfiguration);
$entityBundleConfiguration = [
'uuid' => '44bb277a-8358-4bc4-b439-577b0cb96820',
'langcode' => $defaultLanguage
->getId(),
'status' => TRUE,
'dependencies' => [],
'name' => 'Bundle',
'type' => 'bundle',
'description' => '',
];
$sync
->write($entityBundleConfigName, $entityBundleConfiguration);
$this
->drupalGet(Url::fromRoute('config.sync'));
$this
->submitForm([], 'Import all');
$config = $this
->config($entityTypeConfigName);
$this
->assertEquals($config
->getRawData(), $entityTypeConfiguration, 'Entity type configuration imported successfully.');
$config = $this
->config($entityBundleConfigName);
$this
->assertEquals($config
->getRawData(), $entityBundleConfiguration, 'Entity bundle configuration imported successfully.');
$this
->drupalGet(Url::fromRoute('eck.entity_type.list'));
$this
->assertSession()
->responseContains('Test entity');
$edit = [
'title[0][value]' => $this
->randomMachineName(),
];
$route = 'eck.entity.add';
$routeArguments = [
'eck_entity_type' => 'test_entity',
'eck_entity_bundle' => 'bundle',
];
$this
->drupalGet(Url::fromRoute($route, $routeArguments));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->responseContains($edit['title[0][value]']);
}
}