/**
* Tests the getViaUri() and getViaScheme() methods and target functions.
*/
public function testUriFunctions() { $config =
$this->
config('system.file'
);
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::
service('stream_wrapper_manager'
);
$instance =
$stream_wrapper_manager->
getViaUri($this->scheme . '://foo'
);
$this->
assertEquals($this->classname,
get_class($instance), 'Got correct class type for dummy URI.'
);
$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:'
), ''
);