1 config.test ConfigurationUITest::testExport()

Tests export of configuration.

File

core/modules/config/tests/config.test, line 513
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();

  // Verify the generated archive was removed from the temporary directory
  // after being sent to the user.
  $leftover_files = file_scan_directory('temporary://', '/^config.*\.tar\.gz$/', array('recurse' => FALSE));
  $this->assertTrue(empty($leftover_files), 'Exported archive was removed from the temporary directory after download.');

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

  // Verify a user with permission may download the archive from the
  // temporary directory, but anonymous users may not.
  $this->backdropGet(file_create_url($uri));
  $this->assertResponse(200, 'User with permission can download config.tar.gz from the temporary directory.');
  $this->backdropLogout();
  $this->backdropGet(file_create_url($uri));
  $this->assertResponse(403, 'Anonymous user cannot download config.tar.gz from the temporary directory.');
  $this->assertNotEqual($this->backdropGetContent(), $archive_data, 'Archive contents not provided to anonymous user.');

  // 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);
}