You are here

protected function PDFPreviewGeneratorTest::getPdfPreviewGeneratorMock in PDFPreview 8

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

Gets a mocked PDF Preview Generator for testing.

Return value

\Drupal\pdfpreview\PDFPreviewGenerator Mocked PDF Preview Generator.

1 call to PDFPreviewGeneratorTest::getPdfPreviewGeneratorMock()
PDFPreviewGeneratorTest::testGetDestinationUri in tests/src/Unit/PDFPreviewGeneratorTest.php
@covers ::getDestinationURI

File

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

Class

PDFPreviewGeneratorTest
@coversDefaultClass \Drupal\pdfpreview\PDFPreviewGenerator

Namespace

Drupal\Tests\pdfpreview\Unit

Code

protected function getPdfPreviewGeneratorMock() {
  $file_system = $this
    ->getMockBuilder('\\Drupal\\Core\\File\\FileSystem')
    ->disableOriginalConstructor()
    ->getMock();
  $file_system
    ->expects($this
    ->any())
    ->method('basename')
    ->with('public://Test File.pdf', '.pdf')
    ->willReturn('Test File');
  $transliteration = $this
    ->getMockBuilder(TransliterationInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $transliteration
    ->expects($this
    ->any())
    ->method('transliterate')
    ->with('Test File', 'en')
    ->willReturn('test-file');
  $image_toolkit_manager = $this
    ->createMock('\\Drupal\\Core\\ImageToolkit\\ImageToolkitManager');
  $language = $this
    ->getMockBuilder('Drupal\\Core\\Language\\Language')
    ->disableOriginalConstructor()
    ->getMock();
  $language
    ->expects($this
    ->any())
    ->method('getId')
    ->willReturn('en');
  $language_manager = $this
    ->getMockBuilder('Drupal\\Core\\Language\\LanguageManager')
    ->disableOriginalConstructor()
    ->getMock();
  $language_manager
    ->expects($this
    ->any())
    ->method('getCurrentLanguage')
    ->willReturn($language);
  $generator = $this
    ->getMockBuilder('\\Drupal\\pdfpreview\\PDFPreviewGenerator')
    ->setConstructorArgs([
    $this->configFactory
      ->reveal(),
    $file_system,
    $transliteration,
    $image_toolkit_manager,
    $language_manager,
  ])
    ->getMock();
  return $generator;
}