// 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.'
);
$this->
assertStringContainsString('system/files/test.txt',
$file_url_generator->
generateString('private://test.txt'
), 'Private external URL correctly built.'
);
} /**
* Tests some file handle functions.
*/
public function testFileFunctions() { $filename = 'public://' .
$this->
randomMachineName();
file_put_contents($filename,
str_repeat('d', 1000
));