TransformedConfigExportImportUITest.php in Drupal 8
File
core/modules/config/tests/src/Functional/TransformedConfigExportImportUITest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Tests\BrowserTestBase;
class TransformedConfigExportImportUITest extends BrowserTestBase {
public static $modules = [
'config',
'config_transformer_test',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$permissions = [
'export configuration',
'import configuration',
'synchronize configuration',
];
$this->webUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->webUser);
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
}
public function testTransformedExportImport() {
$this
->drupalGet('admin/config/development/configuration');
$this
->assertNoText('Warning message');
$this
->assertNoText('There are no configuration changes to import.');
$this
->drupalGet('admin/config/development/configuration/sync/diff/system.site');
$this
->assertText('name: Drupal');
$this
->assertText(Html::escape("name: 'Drupal Arrr'"));
$originalSlogan = $this
->config('system.site')
->get('slogan');
$this
->assertEmpty($originalSlogan);
$newSlogan = $this
->randomMachineName(16);
$this
->assertNotEqual($newSlogan, $originalSlogan);
$this
->config('system.site')
->set('slogan', $newSlogan)
->save();
$this
->assertEqual($this
->config('system.site')
->get('slogan'), $newSlogan);
$this
->drupalGet('admin/config/development/configuration/sync/diff/system.site');
$this
->assertText(Html::escape("slogan: ''"));
$this
->assertText(Html::escape("slogan: {$newSlogan}"));
$this
->drupalPostForm('admin/config/development/configuration/full/export', [], 'Export');
$tarball = $this
->getSession()
->getPage()
->getContent();
$filename = 'temporary://' . $this
->randomMachineName();
file_put_contents($filename, $tarball);
$this
->drupalPostForm('admin/config/development/configuration/full/import', [
'files[import_tarball]' => $filename,
], 'Upload');
$this
->drupalGet('admin/config/development/configuration/sync/diff/system.site');
$this
->assertText(Html::escape("name: 'Drupal Arrr'"));
$this
->assertText(Html::escape("slogan: '{$originalSlogan} Arrr'"));
$this
->assertEqual($this
->config('system.site')
->get('name'), 'Drupal');
$this
->assertEqual($this
->config('system.site')
->get('slogan'), $newSlogan);
$this
->drupalPostForm('admin/config/development/configuration', [], 'Import all');
$this
->assertEqual($this
->config('system.site')
->get('name'), 'Drupal Arrr');
$this
->assertEqual($this
->config('system.site')
->get('slogan'), $originalSlogan . " Arrr");
$this
->drupalGet('admin/config/development/configuration/sync/diff/system.site');
$this
->assertText(Html::escape("name: 'Drupal Arrr Arrr'"));
}
}