Issue #2108813 by cilefen, mtift, Désiré, xjm, InternetDevels: Add fancier config import/export test scenario.

8.0.x
webchick 2014-03-26 13:55:15 -07:00
parent 4a57034dd9
commit 23edb3ffa6
1 changed files with 57 additions and 20 deletions

View File

@ -18,20 +18,6 @@ use Drupal\simpletest\WebTestBase;
*/
class ConfigExportImportUITest extends WebTestBase {
/**
* The site UUID.
*
* @var string
*/
protected $siteUuid;
/**
* The slogan value, for a simple export test case.
*
* @var string
*/
protected $slogan;
/**
* The contents of the config export tarball, held between test methods.
*
@ -40,14 +26,15 @@ class ConfigExportImportUITest extends WebTestBase {
protected $tarball;
/**
* The name of the role with config UI administer permissions.
* Modules to enable.
*
* @var string
* @var array
*/
protected $admin_role;
public static $modules = array('config');
public static $modules = array('config', 'node', 'field');
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Export/import UI',
@ -56,6 +43,9 @@ class ConfigExportImportUITest extends WebTestBase {
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// The initial import must be done with uid 1 because if separately named
@ -77,6 +67,34 @@ class ConfigExportImportUITest extends WebTestBase {
->save();
$this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan);
// Create a content type.
$this->content_type = $this->drupalCreateContentType();
// Create a field.
$this->field = entity_create('field_config', array(
'name' => drupal_strtolower($this->randomName()),
'entity_type' => 'node',
'type' => 'text',
));
$this->field->save();
entity_create('field_instance_config', array(
'field_name' => $this->field->name,
'entity_type' => 'node',
'bundle' => $this->content_type->type,
))->save();
entity_get_form_display('node', $this->content_type->type, 'default')
->setComponent($this->field->name, array(
'type' => 'text_textfield',
))
->save();
entity_get_display('node', $this->content_type->type, 'full')
->setComponent($this->field->name)
->save();
$this->drupalGet('node/add/' . $this->content_type->type);
$this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed');
// Export the configuration.
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
$this->tarball = $this->drupalGetContent();
@ -85,12 +103,31 @@ class ConfigExportImportUITest extends WebTestBase {
->save();
$this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->originalSlogan);
// Delete the custom field.
$field_instances = entity_load_multiple('field_instance_config');
foreach ($field_instances as $field_instance) {
if ($field_instance->field_name == $this->field->name) {
$field_instance->delete();
}
}
$fields = entity_load_multiple('field_config');
foreach ($fields as $field) {
if ($field->name == $this->field->name) {
$field->delete();
}
}
$this->drupalGet('node/add/' . $this->content_type->type);
$this->assertNoFieldByName("{$this->field->name}[0][value]", '', 'Widget is not displayed');
// Import the configuration.
$filename = 'temporary://' . $this->randomName();
file_put_contents($filename, $this->tarball);
$this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
$this->drupalPostForm(NULL, array(), 'Import all');
$this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan);
$this->drupalGet('node/add');
$this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed');
}
}