Tar example

/** * {@inheritdoc} */
  protected $archiverPluginId = 'Tar';

  /** * Tests that the Tar archive is created if it does not exist. */
  public function testCreateArchive() {
    $textFile = current($this->getTestFiles('text'));
    $archiveFilename = $this->fileSystem->realpath('public://' . $this->randomMachineName() . '.tar');
    $tar = new Tar($archiveFilename);
    $tar->add($this->fileSystem->realPath($textFile->uri));
    $this->assertFileExists($archiveFilename, 'Archive is automatically created if the file does not exist.');
    $this->assertArchiveContainsFile($archiveFilename$this->fileSystem->realPath($textFile->uri));
  }

}
// 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
Home | Imprint | This part of the site doesn't use cookies.