Skip to content

Commit

Permalink
Merge pull request #27 from sabbelasichon/bugfix/issue-8-resolve-path…
Browse files Browse the repository at this point in the history
…-to-file

[BUGFIX] Resolve pathToFile
  • Loading branch information
sabbelasichon authored Feb 21, 2020
2 parents aeb529c + 96adb25 commit 8251d4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 0 additions & 1 deletion Classes/Middleware/PreloadAssetsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down
12 changes: 9 additions & 3 deletions Classes/ViewHelpers/AssetViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Ssch\Typo3Encore\Integration\FilesystemInterface;
use Ssch\Typo3Encore\Integration\PackageFactoryInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand All @@ -25,20 +26,25 @@ final class AssetViewHelper extends AbstractViewHelper
* @var PackageFactoryInterface
*/
private $packageFactory;
/**
* @var FilesystemInterface
*/
private $filesystem;

public function __construct(PackageFactoryInterface $packageFactory)
public function __construct(PackageFactoryInterface $packageFactory, FilesystemInterface $filesystem)
{
$this->packageFactory = $packageFactory;
$this->filesystem = $filesystem;
}

public function initializeArguments()
public function initializeArguments(): void
{
$this->registerArgument('pathToFile', 'string', 'The path to the file', true);
$this->registerArgument('package', 'string', 'The package configuration to use', false, '_default');
}

public function render()
{
return $this->packageFactory->getPackage($this->arguments['package'])->getUrl($this->arguments['pathToFile']);
return $this->packageFactory->getPackage($this->arguments['package'])->getUrl($this->filesystem->getRelativeFilePath($this->arguments['pathToFile']));
}
}
15 changes: 13 additions & 2 deletions Tests/Unit/ViewHelpers/AssetViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase;
use PHPUnit\Framework\MockObject\MockObject;
use Ssch\Typo3Encore\Integration\FilesystemInterface;
use Ssch\Typo3Encore\Integration\PackageFactoryInterface;
use Ssch\Typo3Encore\ViewHelpers\AssetViewHelper;
use Symfony\Component\Asset\PackageInterface;
Expand All @@ -30,16 +32,24 @@ final class AssetViewHelperTest extends ViewHelperBaseTestcase
*/
protected $viewHelper;

/**
* @var MockObject|PackageInterface
*/
protected $package;

/**
* @var FilesystemInterface|MockObject
*/
protected $filesystem;

protected function setUp()
{
parent::setUp();
$this->package = $this->getMockBuilder(PackageInterface::class)->getMock();

$this->filesystem = $this->getMockBuilder(FilesystemInterface::class)->getMock();
$packageFactory = $this->getMockBuilder(PackageFactoryInterface::class)->getMock();
$packageFactory->method('getPackage')->willReturn($this->package);
$this->viewHelper = new AssetViewHelper($packageFactory);
$this->viewHelper = new AssetViewHelper($packageFactory, $this->filesystem);
}

/**
Expand All @@ -50,6 +60,7 @@ public function returnResolvedPathForFile()
$pathToFile = 'EXT:typo3_encore/Tests/Build/UnitTests.xml';
$this->viewHelper->setArguments(['pathToFile' => $pathToFile, 'package' => '_default']);

$this->filesystem->expects($this->once())->method('getRelativeFilePath')->willReturn($pathToFile);
$this->package->expects($this->once())->method('getUrl')->willReturn($pathToFile);
$this->assertEquals($pathToFile, $this->viewHelper->initializeArgumentsAndRender());
}
Expand Down
1 change: 0 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use TYPO3\CMS\Core\Core\Environment;

if (! defined('TYPO3_MODE')) {
die('Access denied.');
Expand Down

0 comments on commit 8251d4e

Please sign in to comment.