1 file.test StreamWrapperTest::testUriFunctions()

Test the URI and target functions.

File

core/modules/simpletest/tests/file.test, line 2874
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

StreamWrapperTest
Tests stream wrapper functions.

Code

function testUriFunctions() {
  $instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo');
  $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.');

  $instance = file_stream_wrapper_get_instance_by_uri('public://foo');
  $this->assertEqual('BackdropPublicStreamWrapper', get_class($instance), 'Got correct class type for public URI.');

  // Test file_uri_target().
  $this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', 'Got a valid stream target from public://foo/bar.txt.');
  $this->assertFalse(file_uri_target('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');

  // Test file_build_uri() and BackdropLocalStreamWrapper::getDirectoryPath().
  $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.');
  $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), config_get('system.core', 'file_public_path'), 'Expected default directory path was returned.');
  $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), config_get('system.core', 'file_temporary_path'), 'Expected temporary directory path was returned.');

  config_set('system.core', 'file_default_scheme', 'private');
  $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
}