You are here

protected function FileTest::getModuleHandlerMock in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/freelinking/FileTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\FileTest::getModuleHandlerMock()

Get a mock of the module handler service depending on file_download result.

Parameters

int $fileAvailability: Whether the file should not exist (0), exist (1) or not be accessible (-1).

Return value

\Drupal\Core\Extension\ModuleHandlerInterface The module handler service mock.

2 calls to FileTest::getModuleHandlerMock()
FileTest::setUp in tests/src/Unit/Plugin/freelinking/FileTest.php
FileTest::testBuildLink in tests/src/Unit/Plugin/freelinking/FileTest.php
Assert that buildLink is functional.

File

tests/src/Unit/Plugin/freelinking/FileTest.php, line 212

Class

FileTest
Tests the freelinking file plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

protected function getModuleHandlerMock($fileAvailability = 0) {

  // Mock module handler service.
  $moduleHandlerProphet = $this
    ->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $moduleHandlerProphet
    ->invokeAll('file_download', Argument::any())
    ->will(function ($args) use ($fileAvailability) {
    $ret = [];
    if ($fileAvailability === -1) {
      $ret['file'] = -1;
    }
    return $ret;
  });
  return $moduleHandlerProphet
    ->reveal();
}