You are here

protected function WebformResultsExportDownloadTest::getArchiveContents in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/WebformResultsExportDownloadTest.php \Drupal\Tests\webform\Functional\WebformResultsExportDownloadTest::getArchiveContents()

Get archive contents.

Parameters

string $filepath: Archive file path.

Return value

array Array of archive contents.

1 call to WebformResultsExportDownloadTest::getArchiveContents()
WebformResultsExportDownloadTest::testDownloadFiles in tests/src/Functional/WebformResultsExportDownloadTest.php
Tests download files.

File

tests/src/Functional/WebformResultsExportDownloadTest.php, line 149

Class

WebformResultsExportDownloadTest
Tests for webform results export download.

Namespace

Drupal\Tests\webform\Functional

Code

protected function getArchiveContents($filepath) {
  if (strpos($filepath, '.zip') !== FALSE) {
    $archive = new \ZipArchive();
    $archive
      ->open($filepath);
    $files = [];
    for ($i = 0; $i < $archive->numFiles; $i++) {
      $files[] = $archive
        ->getNameIndex($i);
    }
  }
  else {
    $archive = new \Archive_Tar($filepath, 'gz');
    $files = [];
    foreach ($archive
      ->listContent() as $file_data) {
      $files[] = $file_data['filename'];
    }
  }
  return array_combine($files, $files);
}