You are here

public function PDFPreviewGeneratorTest::testGetDestinationUri in PDFPreview 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/PdfPreviewGeneratorTest.php \Drupal\Tests\pdfpreview\Unit\PdfPreviewGeneratorTest::testGetDestinationUri()

@covers ::getDestinationURI

File

tests/src/Unit/PDFPreviewGeneratorTest.php, line 37

Class

PDFPreviewGeneratorTest
@coversDefaultClass \Drupal\pdfpreview\PDFPreviewGenerator

Namespace

Drupal\Tests\pdfpreview\Unit

Code

public function testGetDestinationUri() {
  $filename = 'Test File.pdf';
  $id = '1234';
  $md5 = '117aa294817277a5c090bf18d515d885';
  $file = $this
    ->getFileMock($filename, $id);
  $generator = $this
    ->getPdfPreviewGeneratorMock();
  $reflection = new \ReflectionClass(PDFPreviewGenerator::class);
  $method = $reflection
    ->getMethod('getDestinationURI');
  $method
    ->setAccessible(TRUE);
  $file_config = $this
    ->prophesize(ImmutableConfig::class);
  $this->configFactory
    ->get('system.file')
    ->willReturn($file_config
    ->reveal());
  $file_config
    ->get('default_scheme')
    ->willReturn('public');
  $config = $this
    ->prophesize(ImmutableConfig::class);
  $this->configFactory
    ->get('pdfpreview.settings')
    ->willReturn($config
    ->reveal());
  $config
    ->get('path')
    ->willReturn('pdfpreview');

  // MD5 filename, JPG.
  $config
    ->get('filenames')
    ->willReturn('md5');
  $config
    ->get('type')
    ->willReturn('jpg');
  $filename_md5_jpg = 'public://pdfpreview/' . $md5 . '.jpg';
  $this
    ->assertEquals($filename_md5_jpg, $method
    ->invoke($generator, $file));

  // MD5 filename, PNG.
  $config
    ->get('type')
    ->willReturn('png');
  $filename_md5_png = 'public://pdfpreview/' . $md5 . '.png';
  $this
    ->assertEquals($filename_md5_png, $method
    ->invoke($generator, $file));

  // Human filename, PNG.
  $config
    ->get('filenames')
    ->willReturn('human');
  $filename_human_png = 'public://pdfpreview/1234-test-file.png';
  $this
    ->assertEquals($filename_human_png, $method
    ->invoke($generator, $file));
}