Skip to content

Commit

Permalink
- Fixed issue with absolute dir path
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Oct 17, 2017
1 parent 36682ce commit 2c0779a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
10 changes: 4 additions & 6 deletions src/WebLoader/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public function getFilesCollectionRender(): FilesCollectionRender
$basePath = preg_replace('~^' . $this->documentRoot . '~', '', $this->outputDir, 1);
}

$basePath = trim($basePath, '/');

$this->filesCollectionRender = new FilesCollectionRender(
$this->filesCollections,
$this->documentRoot,
Expand Down Expand Up @@ -432,9 +434,7 @@ public function setDocumentRoot(string $path): Compiler
throw new Exception('Given document root "' . $path . '" doesn\'t exists or is not a directory.');
}

$path = trim($path, '/');

$this->documentRoot = $path;
$this->documentRoot = rtrim($path, '/');
return $this;
}

Expand All @@ -449,9 +449,7 @@ public function setOutputDir(string $path): Compiler
throw new Exception('Given output dir "' . $path . '" is not writable.');
}

$path = trim($path, '/');

$this->outputDir = $path;
$this->outputDir = rtrim($path, '/');
return $this;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ abstract class AbstractTestCase extends TestCase
{

const
ACTUAL_DIR = self::WEBTEMP_DIR . '/actual',
ACTUAL_DIR = self::WEBTEMP_DIR . '/' . self::ACTUAL_DIR_NAME,
ACTUAL_DIR_NAME = 'actual',
BASE_PATH = self::WEBTEMP_DIR_NAME . '/' . self::ACTUAL_DIR_NAME,
DOCUMENT_ROOT = __DIR__,
EXPECTED_DIR = self::WEBTEMP_DIR . '/expected',
WEBTEMP_DIR = 'webtemp';
WEBTEMP_DIR = self::DOCUMENT_ROOT . '/' . self::WEBTEMP_DIR_NAME,
WEBTEMP_DIR_NAME = 'webtemp';

const PATHS_PLACEHOLDERS = [
'cssFixtures' => 'fixtures/css',
Expand Down
32 changes: 16 additions & 16 deletions tests/CompilerTestsCase.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class CompilerTestsCase extends AbstractTestCase
});

Assert::equal(
'<link type="text/css" rel="stylesheet" href="/' . self::ACTUAL_DIR . '/' . $collectionName . '.css?v=' . $version . '">',
'<link type="text/css" rel="stylesheet" href="/' . self::BASE_PATH . '/' . $collectionName . '.css?v=' . $version . '">',
$compiler->getFilesCollectionRender()->css($collectionName)
);

Expand Down Expand Up @@ -68,7 +68,7 @@ final class CompilerTestsCase extends AbstractTestCase
$version = $compiler->getVersion();

Assert::equal(
'<script async type="text/javascript" src="/' . self::ACTUAL_DIR . '/' . $collectionName . '.js?v=' . $version . '"></script>',
'<script async type="text/javascript" src="/' . self::BASE_PATH . '/' . $collectionName . '.js?v=' . $version . '"></script>',
$compiler->getFilesCollectionRender()->js($collectionName, ['async' => TRUE])
);

Expand Down Expand Up @@ -113,12 +113,12 @@ final class CompilerTestsCase extends AbstractTestCase
$render = $compiler->getFilesCollectionRender();

Assert::equal(
'<link type="text/css" rel="stylesheet" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.css?v=' . $version . '">',
'<link type="text/css" rel="stylesheet" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.css?v=' . $version . '">',
$render->css($collectionNameA)
);

Assert::equal(
'<script async defer type="text/javascript" src="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.js?v=' . $version . '"></script>',
'<script async defer type="text/javascript" src="/' . self::BASE_PATH . '/' . $collectionNameB . '.js?v=' . $version . '"></script>',
$render->js($collectionNameB, ['async' => TRUE, 'defer' => TRUE])
);

Expand Down Expand Up @@ -156,28 +156,28 @@ final class CompilerTestsCase extends AbstractTestCase

$render = $compiler->getFilesCollectionsContainerRender()->selectContainer('testContainer');

$collectionALink = '<link type="text/css" rel="stylesheet" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link type="text/css" rel="stylesheet" href="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.css?v=' . $version . '">';
$collectionALink = '<link type="text/css" rel="stylesheet" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link type="text/css" rel="stylesheet" href="/' . self::BASE_PATH . '/' . $collectionNameB . '.css?v=' . $version . '">';
Assert::equal($collectionALink . $collectionBLink, $render->css());

$collectionALink = '<link rel="prefetch" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link rel="prefetch" href="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.css?v=' . $version . '">';
$collectionALink = '<link rel="prefetch" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link rel="prefetch" href="/' . self::BASE_PATH . '/' . $collectionNameB . '.css?v=' . $version . '">';
Assert::equal($collectionALink . $collectionBLink, $render->cssPrefetch());

$collectionALink = '<link rel="preload" as="style" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link rel="preload" as="style" href="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.css?v=' . $version . '">';
$collectionALink = '<link rel="preload" as="style" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.css?v=' . $version . '">';
$collectionBLink = '<link rel="preload" as="style" href="/' . self::BASE_PATH . '/' . $collectionNameB . '.css?v=' . $version . '">';
Assert::equal($collectionALink . $collectionBLink, $render->cssPreload());

$collectionALink = '<script async defer type="text/javascript" src="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.js?v=' . $version . '"></script>';
$collectionBLink = '<script async defer type="text/javascript" src="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.js?v=' . $version . '"></script>';
$collectionALink = '<script async defer type="text/javascript" src="/' . self::BASE_PATH . '/' . $collectionNameA . '.js?v=' . $version . '"></script>';
$collectionBLink = '<script async defer type="text/javascript" src="/' . self::BASE_PATH . '/' . $collectionNameB . '.js?v=' . $version . '"></script>';
Assert::equal($collectionALink . $collectionBLink, $render->js(NULL, ['async' => TRUE, 'defer' => TRUE]));

$collectionALink = '<link rel="prefetch" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.js?v=' . $version . '">';
$collectionBLink = '<link rel="prefetch" href="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.js?v=' . $version . '">';
$collectionALink = '<link rel="prefetch" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.js?v=' . $version . '">';
$collectionBLink = '<link rel="prefetch" href="/' . self::BASE_PATH . '/' . $collectionNameB . '.js?v=' . $version . '">';
Assert::equal($collectionALink . $collectionBLink, $render->jsPrefetch());

$collectionALink = '<link rel="preload" as="script" href="/' . self::ACTUAL_DIR . '/' . $collectionNameA . '.js?v=' . $version . '">';
$collectionBLink = '<link rel="preload" as="script" href="/' . self::ACTUAL_DIR . '/' . $collectionNameB . '.js?v=' . $version . '">';
$collectionALink = '<link rel="preload" as="script" href="/' . self::BASE_PATH . '/' . $collectionNameA . '.js?v=' . $version . '">';
$collectionBLink = '<link rel="preload" as="script" href="/' . self::BASE_PATH . '/' . $collectionNameB . '.js?v=' . $version . '">';
Assert::equal($collectionALink . $collectionBLink, $render->jsPreload());

$this->matchCssFile($collectionNameA);
Expand Down

0 comments on commit 2c0779a

Please sign in to comment.