Skip to content

Commit

Permalink
Bug fixes (#24)
Browse files Browse the repository at this point in the history
* Bug fixes

* Test for the bug
  • Loading branch information
bajb committed Feb 7, 2020
1 parent 48d3515 commit 6dbc741
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Resources/NestedResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Packaged\Dispatch\Tests\Resources;

use Packaged\Dispatch\Dispatch;
use Packaged\Dispatch\ResourceManager;
use Packaged\Dispatch\Resources\CssResource;
use Packaged\Helpers\Path;
use PHPUnit\Framework\TestCase;

class NestedResourceTest extends TestCase
{
public function testProcessesContent()
{
$root = Path::system(dirname(__DIR__), '_root');
Dispatch::bind(new Dispatch($root, '/_r/'))->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);
}
}

0 comments on commit 6dbc741

Please sign in to comment.