You are here

public function MinisiteTest::testMissingFile in Mini site 8

Test that missing physical file throws exception.

@covers \Drupal\minisite\Minisite::setArchiveFile @covers \Drupal\minisite\Minisite::validateArchive

File

tests/src/Functional/MinisiteTest.php, line 91

Class

MinisiteTest
Class MinisiteTest.

Namespace

Drupal\Tests\minisite\Functional

Code

public function testMissingFile() {
  $randomizer = new Random();

  /** @var \Drupal\file\Entity\File $archive_file */
  $archive_file = $this
    ->getTestArchiveValid();

  // Create a field and a node.
  $field_name = 'field_' . $randomizer
    ->string();
  $node = Node::create([
    'title' => $randomizer
      ->string(),
    'type' => $randomizer
      ->string(),
  ]);
  $uri = $archive_file
    ->getFileUri();
  unlink($uri);
  $this
    ->expectException(MissingArchiveException::class);
  $this
    ->expectExceptionMessage(sprintf('Archive file "%s" is missing.', $uri));
  $minisite = new Minisite($node, $field_name, $archive_file);
  $this
    ->assertNull($minisite);
}