$instance =
$stream_wrapper_manager->
getViaUri('public://foo'
);
$this->
assertEquals('Drupal\Core\StreamWrapper\PublicStream',
get_class($instance), 'Got correct class type for public URI.'
);
// Test file_uri_target().
$this->
assertEquals('foo/bar.txt',
$stream_wrapper_manager::
getTarget('public://foo/bar.txt'
), 'Got a valid stream target from public://foo/bar.txt.'
);
$this->
assertEquals('image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==',
$stream_wrapper_manager::
getTarget('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
));
$this->
assertFalse($stream_wrapper_manager::
getTarget('foo/bar.txt'
), 'foo/bar.txt is not a valid stream.'
);
$this->
assertSame($stream_wrapper_manager::
getTarget('public://'
), ''
);
$this->
assertSame($stream_wrapper_manager::
getTarget('data:'
), ''
);
// Test Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
$this->
assertEquals(PublicStream::
basePath(),
$stream_wrapper_manager->
getViaScheme('public'
)->
getDirectoryPath(), 'Expected default directory path was returned.'
);
$file_system = \Drupal::
service('file_system'
);
assert($file_system instanceof FileSystemInterface
);
$this->
assertEquals($file_system->
getTempDirectory(),
$stream_wrapper_manager->
getViaScheme('temporary'
)->
getDirectoryPath(), 'Expected temporary directory path was returned.'
);
// Test FileUrlGeneratorInterface::generateString()
// TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs
// route information to work.
$file_url_generator =
$this->container->
get('file_url_generator'
);
assert($file_url_generator instanceof FileUrlGeneratorInterface
);
$this->
assertStringContainsString('system/temporary?file=test.txt',
$file_url_generator->
generateString('temporary://test.txt'
), 'Temporary external URL correctly built.'
);
$this->
assertStringContainsString(Settings::
get('file_public_path'
) . '/test.txt',
$file_url_generator->
generateString('public://test.txt'
), 'Public external URL correctly built.'
);