Commit d3703f9f authored by catch's avatar catch

Issue #2352855 by slashrsm: TemporaryStream::getExternalUrl() is broken

parent f007e491
......@@ -7,6 +7,8 @@
namespace Drupal\Core\StreamWrapper;
use \Drupal\Core\Url;
/**
* Defines a Drupal temporary (temporary://) stream wrapper class.
*
......@@ -48,6 +50,6 @@ public function getDirectoryPath() {
*/
public function getExternalUrl() {
$path = str_replace('\\', '/', $this->getTarget());
return $this->url('system.temporary', ['scheme' => $path], ['absolute' => TRUE]);
return Url::fromRoute('system.temporary', [], ['absolute' => TRUE, 'query' => ['file' => $path]])->toString();
}
}
......@@ -7,7 +7,10 @@
namespace Drupal\system\Tests\File;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PublicStream;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests stream wrapper functions.
......@@ -37,6 +40,17 @@ class StreamWrapperTest extends FileTestBase {
*/
protected $classname = 'Drupal\file_test\StreamWrapper\DummyStreamWrapper';
function setUp() {
// Add file_private_path setting.
$settings = Settings::getAll();
$request = Request::create('/');;
$site_path = DrupalKernel::findSitePath($request);
$settings['file_private_path'] = $site_path . '/private';
new Settings($settings + Settings::getAll());
parent::setUp();
}
/**
* Test the getClassName() function.
*/
......@@ -84,6 +98,15 @@ function testUriFunctions() {
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.');
$config->set('default_scheme', 'private')->save();
$this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
// Test file_create_url()
// TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs
// route information to work.
$this->installSchema('system', 'router');
$this->container->get('router.builder')->rebuild();
$this->assertTrue(strpos(file_create_url('temporary://test.txt'), 'system/temporary?file=test.txt'), 'Temporary external URL correctly built.');
$this->assertTrue(strpos(file_create_url('public://test.txt'), Settings::get('file_public_path') . '/test.txt'), 'Public external URL correctly built.');
$this->assertTrue(strpos(file_create_url('private://test.txt'), 'system/files/test.txt'), 'Private external URL correctly built.');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment