You are here

public function FeaturesGenerateTest::testExportArchive in Features 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/FeaturesGenerateTest.php \Drupal\Tests\features\Kernel\FeaturesGenerateTest::testExportArchive()

@covers \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationArchive

File

tests/src/Kernel/FeaturesGenerateTest.php, line 74

Class

FeaturesGenerateTest
@group features

Namespace

Drupal\Tests\features\Kernel

Code

public function testExportArchive() {
  $filename = $this->fileSystem
    ->getTempDirectory() . '/' . self::PACKAGE_NAME . '.tar.gz';
  if (file_exists($filename)) {
    unlink($filename);
  }
  $this
    ->assertFalse(file_exists($filename), 'Archive file already exists.');
  $this->generator
    ->generatePackages('archive', $this->assigner
    ->getBundle(), [
    self::PACKAGE_NAME,
  ]);
  $this
    ->assertTrue(file_exists($filename), 'Archive file was not generated.');
  $archive = new ArchiveTar($filename);
  $files = $archive
    ->listContent();
  $this
    ->assertEquals(3, count($files));
  $this
    ->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml', $files[0]['filename']);
  $this
    ->assertEquals(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.features.yml', $files[1]['filename']);
  $this
    ->assertEquals(self::PACKAGE_NAME . '/config/install/system.site.yml', $files[2]['filename']);
  $expected_info = [
    "name" => "My test package",
    "type" => "module",
    "core_version_requirement" => "^8.9 || ^9",
  ];
  $info = Yaml::decode($archive
    ->extractInString(self::PACKAGE_NAME . '/' . self::PACKAGE_NAME . '.info.yml'));
  $this
    ->assertEquals($expected_info, $info, 'Incorrect info file generated');
}