protected function FileUrlGeneratorTest::createFileUrlGenerator in CDN 8.3
Creates a FileUrlGenerator with mostly dummies.
Parameters
string $base_path: The base path to let Request::getBasePath() return.
array $raw_config: The raw config for the cdn.settings.yml config.
Return value
\Drupal\cdn\File\FileUrlGenerator The FileUrlGenerator to test.
2 calls to FileUrlGeneratorTest::createFileUrlGenerator()
- FileUrlGeneratorTest::testGenerate in tests/
src/ Unit/ File/ FileUrlGeneratorTest.php - @covers ::generate @dataProvider urlProvider
- FileUrlGeneratorTest::testGenerateFarfuture in tests/
src/ Unit/ File/ FileUrlGeneratorTest.php - @covers ::generate
File
- tests/
src/ Unit/ File/ FileUrlGeneratorTest.php, line 301
Class
- FileUrlGeneratorTest
- @coversDefaultClass \Drupal\cdn\File\FileUrlGenerator @group cdn
Namespace
Drupal\Tests\cdn\Unit\FileCode
protected function createFileUrlGenerator($base_path, array $raw_config) {
$request = $this
->prophesize(Request::class);
$request
->getBasePath()
->willReturn($base_path);
$request
->getSchemeAndHttpHost()
->willReturn('http://example.com');
$request_stack = $this
->prophesize(RequestStack::class);
$request_stack
->getCurrentRequest()
->willReturn($request
->reveal());
// @todo make this more elegant: the current URI is normally stored on the
// PublicStream instance, but while it is prophesized, that does not seem
// possible.
$current_uri = '';
$public_stream_wrapper = $this
->prophesize(PublicStream::class);
$public_stream_wrapper
->getExternalUrl()
->will(function () use ($base_path, &$current_uri) {
return 'http://example.com' . $base_path . '/sites/default/files/' . UrlHelper::encodePath(substr($current_uri, 9));
});
$file_stream_wrapper = $this
->prophesize(LocalStream::class);
$root = $this->root;
$file_stream_wrapper
->getExternalUrl()
->will(function () use ($root, $base_path, &$current_uri) {
// The file:// stream wrapper is only used for testing FF.
return 'http://example.com/inaccessible';
});
$stream_wrapper_manager = $this
->prophesize(StreamWrapperManagerInterface::class);
$stream_wrapper_manager
->getWrappers(StreamWrapperInterface::LOCAL_NORMAL)
->willReturn([
'public' => TRUE,
]);
$stream_wrapper_manager
->getViaUri(Argument::that(function ($uri) {
return substr($uri, 0, 9) === 'public://';
}))
->will(function ($args) use (&$public_stream_wrapper, &$current_uri) {
$s = $public_stream_wrapper
->reveal();
$current_uri = $args[0];
return $s;
});
$stream_wrapper_manager
->getViaUri(Argument::that(function ($uri) {
return substr($uri, 0, 7) === 'file://';
}))
->will(function ($args) use (&$file_stream_wrapper, &$current_uri) {
$s = $file_stream_wrapper
->reveal();
$current_uri = $args[0];
return $s;
});
$private_key = $this
->prophesize(PrivateKey::class);
$private_key
->get()
->willReturn(static::$privateKey);
return new FileUrlGenerator($this->root, $stream_wrapper_manager
->reveal(), $request_stack
->reveal(), $private_key
->reveal(), new CdnSettings($this
->getConfigFactoryStub([
'cdn.settings' => $raw_config,
]), $stream_wrapper_manager
->reveal()));
}