// Test if header contains file name with hostname and timestamp.
$request = \Drupal::
request();
$hostname =
str_replace('.', '-',
$request->
getHttpHost());
$this->
assertSession()->
responseHeaderMatches('content-disposition', '/attachment; filename="config-' .
preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/'
);
// Extract the archive and verify it's not empty.
$file_system = \Drupal::
service('file_system'
);
assert($file_system instanceof FileSystemInterface
);
$temp_directory =
$file_system->
getTempDirectory();
$file_path =
$temp_directory . '/config.tar.gz';
$archiver =
new Tar($file_path);
$archive_contents =
$archiver->
listContents();
$this->
assertNotEmpty($archive_contents, 'Downloaded archive file is not empty.'
);
// Prepare the list of config files from active storage, see
// \Drupal\config\Controller\ConfigController::downloadExport().
$storage_active =
$this->container->
get('config.storage'
);
$config_files =
[];
foreach ($storage_active->
listAll() as $config_name) { $config_files[] =
$config_name . '.yml';
} // Assert that the downloaded archive file contents are the same as the test