diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php index 539879a..6632476 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigExportImportUITest.php @@ -33,6 +33,20 @@ class ConfigExportImportUITest extends WebTestBase { * @var string */ 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. @@ -70,11 +84,41 @@ 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 programmaticaly. + $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 creation form. + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', 'Widget is displayed'); + $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export'); $this->tarball = $this->drupalGetContent(); } @@ -91,22 +135,36 @@ function testImport() { $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')); + + // Delete the content type we added earlier. + $this->drupalPostForm('admin/structure/types/manage/' . $this->content_type->type . '/delete', array(), 'Delete'); + $type_exists = (bool) entity_load('node_type', $this->content_type->type); + $this->assertFalse($type_exists, 'The new content type has been deleted.'); + $this->doImport($filename); + + // Check that settings are returned to their prior values. + $this->assertEqual($this->slogan, \Drupal::config('system.site')->get('slogan')); + $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.'); + $this->drupalGet('node/add/' . $this->content_type->type); + $this->assertFieldByName("{$this->field->name}[0][value]", '', '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')); } }