From 6dbc74193bc761dcd87bd4669c724bd320ace2bf Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Fri, 7 Feb 2020 13:08:16 +0000 Subject: [PATCH] Bug fixes (#24) * Bug fixes * Test for the bug --- src/ResourceManager.php | 9 ++++----- tests/Resources/NestedResourceTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/Resources/NestedResourceTest.php diff --git a/src/ResourceManager.php b/src/ResourceManager.php index ab43fef..b55d67f 100644 --- a/src/ResourceManager.php +++ b/src/ResourceManager.php @@ -74,9 +74,8 @@ public function getBaseUri() { if($this->_baseUri === null) { - $this->_baseUri = (Dispatch::instance() ? Dispatch::instance()->getBaseUri() : '/') - . '/' . $this->_type . '/' . implode('/', $this->_mapOptions); - $this->_baseUri = trim($this->_baseUri, '/'); + $this->_baseUri = Dispatch::instance() ? Dispatch::instance()->getBaseUri() : ''; + $this->_baseUri = Path::url($this->_baseUri, $this->_type, implode('/', $this->_mapOptions)); } return $this->_baseUri; } @@ -307,8 +306,8 @@ public function getResourceUri($relativeFullPath, bool $allowComponentBubble = t return null; } - return $this->getBaseUri() - . '/' . $hash . $relHash . ($bits > 0 ? '-' . base_convert($bits, 10, 36) : '') + $uri = $this->getBaseUri(); + return $uri . (empty($uri) ? '' : '/') . $hash . $relHash . ($bits > 0 ? '-' . base_convert($bits, 10, 36) : '') . '/' . $relativeFullPath; } diff --git a/tests/Resources/NestedResourceTest.php b/tests/Resources/NestedResourceTest.php new file mode 100644 index 0000000..65942fa --- /dev/null +++ b/tests/Resources/NestedResourceTest.php @@ -0,0 +1,25 @@ +addAlias('root', Path::system($root, Dispatch::RESOURCES_DIR)); + $manager = ResourceManager::resources(); + + $resource = new CssResource(); + $resource->setManager($manager); + $resource->setProcessingPath('css/test.css'); + $resource->setContent(file_get_contents(Path::system($root, Dispatch::RESOURCES_DIR, 'css', 'test.css'))); + $content = $resource->getContent(); + $this->assertContains('url(/_r/r/395d1a0e8999/img/x.jpg?x=y&request=b)', $content); + } +}