You are here

public function PdfPreviewGeneratorTest::testGetDestinationUri in PDFPreview 2.0.x

Same name and namespace in other branches
  1. 8 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));
}