Commit dff0eb3b authored by Tino Goratsch's avatar Tino Goratsch

increased the unit test coverage of the FileResolver class

parent 4af5933e
......@@ -126,7 +126,7 @@ class Bootstrap extends AbstractBootstrap
$this->appPath
->setDesignPathWeb($this->appPath->getWebRoot() . $path)
->setDesignPathInternal(ACP3_ROOT_DIR . $path)
->setDesignPathInternal($this->systemSettings['design'] . '/')
->setDesignPathAbsolute(
$this->container->get('core.http.request')->getScheme()
. $this->container->get('core.http.request')->getHttpHost()
......
......@@ -38,10 +38,6 @@ class FileResolver
* @var bool
*/
protected $newAssetPathsAdded = false;
/**
* @var string
*/
protected $modulesAssetsPath;
/**
* @var string
*/
......@@ -64,9 +60,6 @@ class FileResolver
$this->appPath = $appPath;
$this->vendors = $vendors;
$this->cachedPaths = $resourcesCache->getCache();
$this->modulesAssetsPath = $appPath->getModulesDir();
$this->designAssetsPath = $appPath->getDesignPathInternal();
}
/**
......@@ -99,7 +92,7 @@ class FileResolver
$dir .= '/';
}
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
$systemAssetPath = $this->appPath->getModulesDir() . $modulePath . $dir . $file;
// Return early, if the path has been already cached
if (isset($this->cachedPaths[$systemAssetPath])) {
......@@ -115,7 +108,7 @@ class FileResolver
*/
protected function needsTrailingSlash($path)
{
return strpos($path, '.') === false && !preg_match('=/$=', $path);
return $path !== '' && strpos($path, '.') === false && !preg_match('=/$=', $path);
}
/**
......@@ -128,6 +121,10 @@ class FileResolver
*/
private function resolveAssetPath($modulePath, $designPath, $dir, $file)
{
if ($this->designAssetsPath === null) {
$this->designAssetsPath = $this->appPath->getDesignPathInternal();
}
$assetPath = '';
$designAssetPath = $this->designAssetsPath . $designPath . $dir . $file;
......@@ -139,14 +136,14 @@ class FileResolver
// Recursively iterate over the nested themes
if (!empty($designInfo['parent'])) {
$this->designAssetsPath = ACP3_ROOT_DIR . 'designs/' . $designInfo['parent'];
$this->designAssetsPath = $this->appPath->getDesignRootPathInternal() . $designInfo['parent'] . '/';
$assetPath = $this->getStaticAssetPath($modulePath, $designPath, $dir, $file);
$this->designAssetsPath = $this->appPath->getDesignPathInternal();
}
// No overrides have been found -> iterate over all possible module namespaces
foreach (array_reverse($this->vendors->getVendors()) as $vendor) {
$moduleAssetPath = $this->modulesAssetsPath . $vendor . '/' . $modulePath . $dir . $file;
$moduleAssetPath = $this->appPath->getModulesDir() . $vendor . '/' . $modulePath . $dir . $file;
if (is_file($moduleAssetPath) === true) {
$assetPath = $moduleAssetPath;
break;
......@@ -154,7 +151,7 @@ class FileResolver
}
}
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
$systemAssetPath = $this->appPath->getModulesDir() . $modulePath . $dir . $file;
$this->cachedPaths[$systemAssetPath] = $assetPath;
$this->newAssetPathsAdded = true;
......@@ -168,11 +165,9 @@ class FileResolver
*/
public function resolveTemplatePath($template)
{
$modulesPath = '';
// A path without any slash was given -> has to be the layout file of the current design
if (strpos($template, '/') === false) {
return $this->getStaticAssetPath($modulesPath, '', '', $template);
return $this->getStaticAssetPath('', '', '', $template);
} else {
// Split the template path in its components
$fragments = explode('/', ucfirst($template));
......@@ -180,7 +175,7 @@ class FileResolver
if (isset($fragments[2])) {
$fragments[1] = ucfirst($fragments[1]);
}
$modulesPath .= $fragments[0] . '/Resources/';
$modulesPath = $fragments[0] . '/Resources/';
$designPath = $fragments[0];
$template = $fragments[1];
if (isset($fragments[2])) {
......
......@@ -35,6 +35,10 @@ class ApplicationPath
* @var string
*/
protected $cacheDir;
/**
* @var string
*/
protected $designRootPathInternal;
/**
* @var string
*/
......@@ -62,6 +66,7 @@ class ApplicationPath
$this->modulesDir = $this->appDir . 'Modules/';
$this->uploadsDir = ACP3_ROOT_DIR . 'uploads/';
$this->cacheDir = ACP3_ROOT_DIR . 'cache/' . $applicationMode . '/';
$this->designRootPathInternal = ACP3_ROOT_DIR . 'designs/';
}
/**
......@@ -197,6 +202,25 @@ class ApplicationPath
return $this;
}
/**
* @return string
*/
public function getDesignRootPathInternal()
{
return $this->designRootPathInternal;
}
/**
* @param string $designRootPathInternal
*
* @return ApplicationPath
*/
public function setDesignRootPathInternal($designRootPathInternal)
{
$this->designRootPathInternal = $designRootPathInternal;
return $this;
}
/**
* @return string
*/
......@@ -212,7 +236,7 @@ class ApplicationPath
*/
public function setDesignPathInternal($designPathInternal)
{
$this->designPathInternal = $designPathInternal;
$this->designPathInternal = $this->designRootPathInternal . $designPathInternal;
return $this;
}
......
......@@ -43,7 +43,9 @@ class FileResolverTest extends \PHPUnit_Framework_TestCase
$this->xml = new XML();
$this->appPath = new ApplicationPath(ApplicationMode::DEVELOPMENT);
$this->appPath->setDesignPathInternal(ACP3_ROOT_DIR . 'tests/designs/acp3/');
$this->appPath
->setDesignRootPathInternal(ACP3_ROOT_DIR . 'tests/designs/')
->setDesignPathInternal('acp3/');
$this->vendors = new Vendor($this->appPath);
$this->fileResolver = new FileResolver(
......@@ -74,4 +76,13 @@ class FileResolverTest extends \PHPUnit_Framework_TestCase
$actual = $this->fileResolver->resolveTemplatePath('System/Partials/mark.tpl');
$this->assertEquals($expected, $actual);
}
public function testResolveTemplatePathWithMultipleInheritance()
{
$this->appPath->setDesignPathInternal('acp3-inherit/');
$expected = ACP3_ROOT_DIR . 'tests/designs/acp3/layout.tpl';
$actual = $this->fileResolver->resolveTemplatePath('layout.tpl');
$this->assertEquals($expected, $actual);
}
}
......@@ -23,7 +23,9 @@ class AssetsTest extends \PHPUnit_Framework_TestCase
$this->setUpMockObjects();
$appPath = new ApplicationPath(ApplicationMode::DEVELOPMENT);
$appPath->setDesignPathInternal(ACP3_ROOT_DIR . 'tests/designs/acp3/');
$appPath
->setDesignRootPathInternal(ACP3_ROOT_DIR . 'tests/designs/')
->setDesignPathInternal('acp3/');
$libraries = new Assets\Libraries($this->eventDispatcherMock);
$this->assets = new Assets($appPath, $libraries);
......
......@@ -62,7 +62,7 @@ class Designs extends Core\Controller\AbstractAdminAction
$bool = false;
if ((bool)preg_match('=/=', $design) === false &&
is_file(ACP3_ROOT_DIR . 'designs/' . $design . '/info.xml') === true
is_file($this->appPath->getDesignRootPathInternal() . $design . '/info.xml') === true
) {
$bool = $this->config->setSettings(['design' => $design], Schema::MODULE_NAME);
......@@ -85,7 +85,7 @@ class Designs extends Core\Controller\AbstractAdminAction
protected function getAvailableDesigns()
{
$designs = [];
$path = ACP3_ROOT_DIR . 'designs/';
$path = $this->appPath->getDesignRootPathInternal();
$directories = Core\Filesystem::scandir($path);
foreach ($directories as $directory) {
$designInfo = $this->xml->parseXmlFile($path . $directory . '/info.xml', '/design');
......
......@@ -61,7 +61,7 @@ class Bootstrap extends Core\Application\AbstractBootstrap
{
$this->appPath
->setDesignPathWeb($this->appPath->getInstallerWebRoot() . 'design/')
->setDesignPathInternal(ACP3_ROOT_DIR . 'installation/design/');
->setDesignPathInternal('');
}
/**
......
......@@ -43,6 +43,7 @@ class ApplicationPath extends \ACP3\Core\Environment\ApplicationPath
$this->installerAppDir = realpath($this->appDir . '../installation') . '/Installer/';
$this->installerModulesDir = $this->installerAppDir . 'Modules/';
$this->installerClassesDir = $this->installerAppDir . 'Core/';
$this->designRootPathInternal = ACP3_ROOT_DIR . 'installation/design/';
}
/**
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016 by the ACP3 Developers.
~ See the LICENCE file at the top-level module directory for licencing details.
-->
<design>
<name>PHPUnit Theme (Inheritance Test)</name>
<description>PHPUnit Theme Description</description>
<author>Tino Goratsch</author>
<version core="true"/>
<use_bootstrap>true</use_bootstrap>
<parent>acp3</parent>
</design>
<!DOCTYPE html>
<html>
<head>
<title>Fixture Layout</title>
</head>
<body>
</body>
</html>
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