You are here

public function AltStreamWrapperTest::testUriFunctions in Alternative Stream Wrappers 8

Test the getViaUri() and getViaScheme() methods and target functions.

Overrides StreamWrapperTest::testUriFunctions

File

tests/src/Kernel/AltStreamWrapperTest.php, line 28

Class

AltStreamWrapperTest
Class AltStreamWrapperTest.

Namespace

Drupal\Tests\alt_stream_wrappers\Kernel

Code

public function testUriFunctions() {
  $config = $this
    ->config('alt_stream_wrappers.settings');

  // Test file_uri_target().
  $this
    ->assertTrue(\Drupal::service('stream_wrapper_manager')
    ->getViaScheme('alttemporary'), 'Could not find the alttemporary scheme.');
  $this
    ->assertEqual(\Drupal::service('stream_wrapper_manager')
    ->getViaScheme('alttemporary')
    ->getDirectoryPath(), $config
    ->get('path.temporary'), 'Expected temporary directory path was returned.');

  // Test file_create_url()
  // TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs
  // route information to work.
  $this->container
    ->get('router.builder')
    ->rebuild();
  $this
    ->assertTrue(strpos(file_create_url('alttemporary://test.txt'), '/alt_stream_wrappers/temporary?file=test.txt'), 'Temporary external URL correctly built.');
}