StreamWrapperTest::testUriFunctions

7 file.test StreamWrapperTest::testUriFunctions()
8 file.test StreamWrapperTest::testUriFunctions()

Test the URI and target functions.

File

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

Code

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

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

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

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

  variable_set('file_default_scheme', 'private');
  $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', t('Got a valid URI from foo/bar.txt.'));
}
Login or register to post comments