X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fconfig%2Fsrc%2FTests%2FConfigSingleImportExportTest.php;fp=web%2Fcore%2Fmodules%2Fconfig%2Fsrc%2FTests%2FConfigSingleImportExportTest.php;h=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=607e80c23b016ee61b868bf52b0831958a926f91;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/config/src/Tests/ConfigSingleImportExportTest.php b/web/core/modules/config/src/Tests/ConfigSingleImportExportTest.php deleted file mode 100644 index 607e80c23..000000000 --- a/web/core/modules/config/src/Tests/ConfigSingleImportExportTest.php +++ /dev/null @@ -1,250 +0,0 @@ -drupalPlaceBlock('page_title_block'); - } - - /** - * Tests importing a single configuration file. - */ - public function testImport() { - $storage = \Drupal::entityManager()->getStorage('config_test'); - $uuid = \Drupal::service('uuid'); - - $this->drupalLogin($this->drupalCreateUser(['import configuration'])); - - // Attempt an import with invalid YAML. - $edit = [ - 'config_type' => 'action', - 'import' => '{{{', - ]; - - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - // Assert the static portion of the error since different parsers could give different text in their error. - $this->assertText('The import failed with the following message: '); - - $import = << 'config_test', - 'import' => $import, - ]; - // Attempt an import with a missing ID. - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertText(t('Missing ID key "@id_key" for this @entity_type import.', ['@id_key' => 'id', '@entity_type' => 'Test configuration'])); - - // Perform an import with no specified UUID and a unique ID. - $this->assertNull($storage->load('first')); - $edit['import'] = "id: first\n" . $edit['import']; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to create a new %name @type?', ['%name' => 'first', '@type' => 'test configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $entity = $storage->load('first'); - $this->assertIdentical($entity->label(), 'First'); - $this->assertIdentical($entity->id(), 'first'); - $this->assertTrue($entity->status()); - $this->assertRaw(t('The configuration was imported successfully.')); - - // Attempt an import with an existing ID but missing UUID. - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertText(t('An entity with this machine name already exists but the import did not specify a UUID.')); - - // Attempt an import with a mismatched UUID and existing ID. - $edit['import'] .= "\nuuid: " . $uuid->generate(); - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertText(t('An entity with this machine name already exists but the UUID does not match.')); - - // Attempt an import with a custom ID. - $edit['custom_entity_id'] = 'custom_id'; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to create a new %name @type?', ['%name' => 'custom_id', '@type' => 'test configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $this->assertRaw(t('The configuration was imported successfully.')); - - // Perform an import with a unique ID and UUID. - $import = << 'config_test', - 'import' => $import, - ]; - $second_uuid = $uuid->generate(); - $edit['import'] .= "\nuuid: " . $second_uuid; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to create a new %name @type?', ['%name' => 'second', '@type' => 'test configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $entity = $storage->load('second'); - $this->assertRaw(t('The configuration was imported successfully.')); - $this->assertIdentical($entity->label(), 'Second'); - $this->assertIdentical($entity->id(), 'second'); - $this->assertFalse($entity->status()); - $this->assertIdentical($entity->uuid(), $second_uuid); - - // Perform an update. - $import = << 'config_test', - 'import' => $import, - ]; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to update the %name @type?', ['%name' => 'second', '@type' => 'test configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $entity = $storage->load('second'); - $this->assertRaw(t('The configuration was imported successfully.')); - $this->assertIdentical($entity->label(), 'Second updated'); - - // Try to perform an update which adds missing dependencies. - $import = << 'config_test', - 'import' => $import, - ]; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Configuration %name depends on the %owner module that will not be installed after import.', ['%name' => 'config_test.dynamic.second', '%owner' => 'does_not_exist'])); - - // Try to preform an update which would create a PHP object if Yaml parsing - // not securely set up. - // Perform an update. - $import = << 'config_test', - 'import' => $import, - ]; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to update the %name @type?', ['%name' => 'second', '@type' => 'test configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $entity = $storage->load('second'); - $this->assertRaw(t('The configuration was imported successfully.')); - $this->assertTrue(is_string($entity->label()), 'Entity label is a string'); - $this->assertTrue(strpos($entity->label(), 'ObjectSerialization') > 0, 'Label contains serialized object'); - } - - /** - * Tests importing a simple configuration file. - */ - public function testImportSimpleConfiguration() { - $this->drupalLogin($this->drupalCreateUser(['import configuration'])); - $config = $this->config('system.site')->set('name', 'Test simple import'); - - // Place branding block with site name into header region. - $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']); - - $edit = [ - 'config_type' => 'system.simple', - 'config_name' => $config->getName(), - 'import' => Yaml::encode($config->get()), - ]; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertRaw(t('Are you sure you want to update the %name @type?', ['%name' => $config->getName(), '@type' => 'simple configuration'])); - $this->drupalPostForm(NULL, [], t('Confirm')); - $this->drupalGet(''); - $this->assertText('Test simple import'); - - // Ensure that ConfigImporter validation is running when importing simple - // configuration. - $config_data = $this->config('core.extension')->get(); - // Simulate uninstalling the Config module. - unset($config_data['module']['config']); - $edit = [ - 'config_type' => 'system.simple', - 'config_name' => 'core.extension', - 'import' => Yaml::encode($config_data), - ]; - $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import')); - $this->assertText(t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.')); - - } - - /** - * Tests exporting a single configuration file. - */ - public function testExport() { - $this->drupalLogin($this->drupalCreateUser(['export configuration'])); - - $this->drupalGet('admin/config/development/configuration/single/export/system.simple'); - $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Simple configuration'), 'The simple configuration option is selected when specified in the URL.'); - // Spot check several known simple configuration files. - $element = $this->xpath('//select[@name="config_name"]'); - $options = $this->getAllOptions($element[0]); - $expected_options = ['system.site', 'user.settings']; - foreach ($options as &$option) { - $option = (string) $option; - } - $this->assertIdentical($expected_options, array_intersect($expected_options, $options), 'The expected configuration files are listed.'); - - $this->drupalGet('admin/config/development/configuration/single/export/system.simple/system.image'); - $this->assertFieldByXPath('//textarea[@name="export"]', "toolkit: gd\n_core:\n default_config_hash: durWHaKeBaq4d9Wpi4RqwADj1OufDepcnJuhVLmKN24\n", 'The expected system configuration is displayed.'); - - $this->drupalGet('admin/config/development/configuration/single/export/date_format'); - $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Date format'), 'The date format entity type is selected when specified in the URL.'); - - $this->drupalGet('admin/config/development/configuration/single/export/date_format/fallback'); - $this->assertFieldByXPath('//select[@name="config_name"]//option[@selected="selected"]', t('Fallback date format (fallback)'), 'The fallback date format config entity is selected when specified in the URL.'); - - $fallback_date = \Drupal::entityManager()->getStorage('date_format')->load('fallback'); - $yaml_text = (string) $this->xpath('//textarea[@name="export"]')[0]; - $this->assertEqual(Yaml::decode($yaml_text), $fallback_date->toArray(), 'The fallback date format config entity export code is displayed.'); - } - -}