1 config.test ConfigurationUITest::testExport()

Tests export of configuration.

File

core/modules/config/tests/config.test, line 394
Tests for Configuration module.

Class

ConfigurationUITest
Tests the UI for syncing, importing, and exporting.

Code

function testExport() {
  // Verify the export page with export submit button is available.
  $this->backdropGet('admin/config/development/configuration/full/export');
  $this->assertFieldById('edit-submit', t('Export'));

  // Submit the export form and verify response.
  $this->backdropPost('admin/config/development/configuration/full/export', array(), t('Export'));
  $this->assertResponse(200, 'User can access the download callback.');

  // Get the archived binary file provided to user for download.
  $archive_data = $this->backdropGetContent();

  // Temporarily save the archive file.
  $uri = 'temporary://config.tar.gz';
  file_put_contents($uri, $archive_data);

  // Extract the archive and verify it's not empty.
  $file_path = file_directory_temp() . '/' . file_uri_target($uri);
  $archiver = new Archive_Tar($file_path);
  $archive_contents = $archiver->listContent();
  $archive_files = array();
  foreach ($archive_contents as $file) {
    $archive_files[] = $file['filename'];
  }
  $this->assert(!empty($archive_files), 'Downloaded archive file is not empty.');

  // Prepare the list of config files from active storage.
  $storage_active = config_get_config_storage('active');
  $config_files = array();
  foreach ($storage_active->listAll() as $config_name) {
    $config_files[] = $config_name . '.json';
  }
  // Assert that the downloaded archive file contents are the same as the test
  // site active store.
  $this->assertIdentical($archive_files, $config_files, 'Downloaded archive contains all active configuration files.');

  // Delete the archive.
  unlink($uri);
}