diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php index 539879a..75017b9 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php @@ -35,6 +35,20 @@ class ConfigExportImportUITest extends WebTestBase { protected $tarball; /** + * A content type, held between test methods. + * + * @var string + */ + protected $content_type; + + /** + * A field, held between test methods. + * + * @var string + */ + protected $field; + + /** * The name of the role with config UI administer permissions. * * @var string @@ -70,11 +84,43 @@ protected function setUp() { */ function testExport() { // Create a role for second round. - $this->admin_role = $this->drupalCreateRole(array('synchronize configuration', 'import configuration')); + $this->admin_role = $this->drupalCreateRole(array('synchronize configuration', 'import configuration', 'administer content types', 'administer nodes')); $this->slogan = $this->randomString(16); \Drupal::config('system.site') ->set('slogan', $this->slogan) ->save(); + + // Create a content type. + $this->content_type = $this->drupalCreateContentType(); + $type_exists = (bool) entity_load('node_type', $this->content_type->type); + $this->assertTrue($type_exists, 'The new content type has been created in the database.'); + + // Create a field. + $this->field = entity_create('field_entity', array( + 'name' => drupal_strtolower($this->randomName()), + 'entity_type' => 'node', + 'type' => 'text', + )); + $this->field->save(); + entity_create('field_instance', 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(); + + // Display the creation form. + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed'); + + // Export the site configuration. $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export'); $this->tarball = $this->drupalGetContent(); } @@ -85,28 +131,92 @@ function testExport() { function testImport() { $filename = 'temporary://' . $this->randomName(); file_put_contents($filename, $this->tarball); + + // Assert the custom content type does not exist. + $this->drupalGet('node/add'); + $this->assertNoText($this->content_type->type, 'The new content type does not exist.'); + $this->doImport($filename); + // Now that the role is imported, change the slogan and re-import with a non-root user. $web_user = $this->drupalCreateUser(); $web_user->addRole($this->admin_role); $web_user->save(); $this->drupalLogin($web_user); + + // Change the site slogan. \Drupal::config('system.site') ->set('slogan', $this->randomString(16)) ->save(); + $this->assertNotEqual($this->slogan, \Drupal::config('system.site')->get('slogan')); + + $this->doImport($filename); + + $this->drupalLogin($this->root_user); + + // Check that settings are returned to their prior values. + $this->assertEqual($this->slogan, \Drupal::config('system.site')->get('slogan')); + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', 'The custom field widget is displayed'); + + // Delete the custom field. + $field_instances = entity_load_multiple('field_instance'); + foreach($field_instances as &$field_instance) { + if($field_instance->field_name == $this->field->name) { + $field_instance->delete(); + } + } + $fields = entity_load_multiple('field_entity'); + foreach($fields as &$field) { + if($field->name == $this->field->name) { + $field->delete(); + } + } + + // Ensure the custom field is deleted. + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertNoFieldByName("{$this->field->name}[0][value]", '', 'The custom field widget is not displayed'); + + // Recreate the custom field. + $field = entity_create('field_entity', array( + 'name' => $this->field->name, + 'entity_type' => 'node', + 'type' => 'text', + )); + $field->save(); + entity_create('field_instance', array( + 'field_name' => $field->name, + 'entity_type' => 'node', + 'bundle' => $this->content_type->type, + ))->save(); + entity_get_form_display('node', $this->content_type->type, 'default') + ->setComponent($field->name, array( + 'type' => 'text_textfield', + )) + ->save(); + entity_get_display('node', $this->content_type->type, 'full') + ->setComponent($field->name) + ->save(); + + // Ensure the custom field exists. + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', 'The custom field widget is displayed'); + $this->doImport($filename); + + // Ensure the custom field exists. + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', 'The custom field widget is displayed'); } /** - * Import a tarball and assert the data is correct. + * Import a tarball. * * @param string $filename * The name of the tarball containing the configuration to be imported. */ protected function doImport($filename) { - $this->assertNotEqual($this->slogan, \Drupal::config('system.site')->get('slogan')); $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload'); $this->drupalPostForm(NULL, array(), 'Import all'); - $this->assertEqual($this->slogan, \Drupal::config('system.site')->get('slogan')); } }