Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: paxal/assetic
...
head fork: paxal/assetic
Checking mergeability… Don't worry, you can still create the pull request.
  • 15 commits
  • 32 files changed
  • 0 commit comments
  • 1 contributor
Showing with 878 additions and 107 deletions.
  1. +3 −2 composer.json
  2. +21 −84 src/Assetic/Factory/AssetFactory.php
  3. +59 −0 src/Assetic/Resolver/AssetReferenceResolver.php
  4. +30 −0 src/Assetic/Resolver/AssetResolverInterface.php
  5. +95 −0 src/Assetic/Resolver/FileAssetResolver.php
  6. +44 −0 src/Assetic/Resolver/GlobAssetResolver.php
  7. +42 −0 src/Assetic/Resolver/HttpAssetResolver.php
  8. +251 −0 src/Assetic/Resolver/PipelineAssetResolver.php
  9. +12 −21 tests/Assetic/Test/Factory/AssetFactoryTest.php
  10. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/global.css.scss
  11. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/menu/main.css
  12. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/menu/user/bar.css.less
  13. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/js/simple_script.js
  14. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/js/unindexed_library/file1.js
  15. +1 −0  tests/Assetic/Test/Fixture/pipeline/track1/js/unindexed_library/file2.js
  16. +1 −0  tests/Assetic/Test/Fixture/pipeline/track2/css/library/sublib/index.css
  17. +1 −0  tests/Assetic/Test/Fixture/pipeline/track2/css/style.css
  18. +1 −0  tests/Assetic/Test/Fixture/pipeline/track2/js/subdir/subscript.js
  19. +1 −0  tests/Assetic/Test/Fixture/pipeline/track3/css/style.css
  20. +1 −0  tests/Assetic/Test/Fixture/pipeline/track3/js/library/index.js
  21. +1 −0  tests/Assetic/Test/Fixture/pipeline/track3/js/unindexed_library/file1.js
  22. +1 −0  tests/Assetic/Test/Fixture/pipeline/track3/js/unindexed_library/file2.js
  23. +1 −0  tests/Assetic/Test/Fixture/root/bar.js
  24. +1 −0  tests/Assetic/Test/Fixture/root/css/main.css
  25. +1 −0  tests/Assetic/Test/Fixture/root/css/more.sass
  26. +1 −0  tests/Assetic/Test/Fixture/root/foo.css
  27. +1 −0  tests/Assetic/Test/Fixture/root/foo.js
  28. +43 −0 tests/Assetic/Test/Resolver/AssetReferenceResolverTest.php
  29. +51 −0 tests/Assetic/Test/Resolver/FileAssetResolverTest.php
  30. +39 −0 tests/Assetic/Test/Resolver/GlobAssetResolverTest.php
  31. +51 −0 tests/Assetic/Test/Resolver/HttpAssetResolverTest.php
  32. +119 −0 tests/Assetic/Test/Resolver/PipelineAssetResolverTest.php
View
5 composer.json
@@ -13,8 +13,9 @@
}
],
"require": {
- "php": ">=5.3.0",
- "symfony/process": "2.1.*"
+ "php": ">=5.3.0",
+ "symfony/process": "2.1.*",
+ "symfony/finder": "2.1.*"
},
"require-dev": {
"twig/twig": ">=1.6.0,<2.0"
View
105 src/Assetic/Factory/AssetFactory.php
@@ -11,13 +11,10 @@
namespace Assetic\Factory;
+use Assetic\Resolver\AssetResolverInterface;
use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetCollectionInterface;
use Assetic\Asset\AssetInterface;
-use Assetic\Asset\AssetReference;
-use Assetic\Asset\FileAsset;
-use Assetic\Asset\GlobAsset;
-use Assetic\Asset\HttpAsset;
use Assetic\AssetManager;
use Assetic\Factory\Worker\WorkerInterface;
use Assetic\FilterManager;
@@ -33,6 +30,7 @@ class AssetFactory
private $debug;
private $output;
private $workers;
+ private $resolvers;
private $am;
private $fm;
@@ -49,6 +47,7 @@ public function __construct($root, $debug = false)
$this->debug = $debug;
$this->output = 'assetic/*';
$this->workers = array();
+ $this->resolvers = array();
}
/**
@@ -92,6 +91,16 @@ public function addWorker(WorkerInterface $worker)
}
/**
+ * Adds asset resolver.
+ *
+ * @param AssetResolverInterface $resolver A resolver
+ */
+ public function addResolver(AssetResolverInterface $resolver)
+ {
+ $this->resolvers[] = $resolver;
+ }
+
+ /**
* Returns the current asset manager.
*
* @return AssetManager|null The asset manager
@@ -195,7 +204,7 @@ public function createAsset($inputs = array(), $filters = array(), array $option
// nested formula
$asset->add(call_user_func_array(array($this, 'createAsset'), $input));
} else {
- $asset->add($this->parseInput($input, $options));
+ $asset->add($this->resolveAsset($input, $options));
$extensions[pathinfo($input, PATHINFO_EXTENSION)] = true;
}
}
@@ -249,48 +258,22 @@ public function generateAssetName($inputs, $filters, $options = array())
}
/**
- * Parses an input string string into an asset.
- *
- * The input string can be one of the following:
- *
- * * A reference: If the string starts with an "at" sign it will be interpreted as a reference to an asset in the asset manager
- * * An absolute URL: If the string contains "://" or starts with "//" it will be interpreted as an HTTP asset
- * * A glob: If the string contains a "*" it will be interpreted as a glob
- * * A path: Otherwise the string is interpreted as a filesystem path
- *
- * Both globs and paths will be absolutized using the current root directory.
+ * Uses registered asset resolvers to create asset instance from provided input.
*
* @param string $input An input string
* @param array $options An array of options
*
* @return AssetInterface An asset
*/
- protected function parseInput($input, array $options = array())
+ protected function resolveAsset($input, array $options = array())
{
- if ('@' == $input[0]) {
- return $this->createAssetReference(substr($input, 1));
- }
-
- if (false !== strpos($input, '://') || 0 === strpos($input, '//')) {
- return $this->createHttpAsset($input, $options['vars']);
- }
-
- if (self::isAbsolutePath($input)) {
- if ($root = self::findRootDir($input, $options['root'])) {
- $path = ltrim(substr($input, strlen($root)), '/');
- } else {
- $path = null;
+ foreach ($this->resolvers as $resolver) {
+ if ($asset = $resolver->resolve($input, $options)) {
+ return $asset;
}
- } else {
- $root = $this->root;
- $path = $input;
- $input = $this->root.'/'.$path;
- }
- if (false !== strpos($input, '*')) {
- return $this->createGlobAsset($input, $root, $options['vars']);
- } else {
- return $this->createFileAsset($input, $root, $path, $options['vars']);
}
+
+ throw new \LogicException(sprintf('Can not resolve asset "%s".', $input));
}
protected function createAssetCollection(array $assets = array(), array $options = array())
@@ -298,30 +281,6 @@ protected function createAssetCollection(array $assets = array(), array $options
return new AssetCollection($assets, array(), null, isset($options['vars']) ? $options['vars'] : array());
}
- protected function createAssetReference($name)
- {
- if (!$this->am) {
- throw new \LogicException('There is no asset manager.');
- }
-
- return new AssetReference($this->am, $name);
- }
-
- protected function createHttpAsset($sourceUrl, $vars)
- {
- return new HttpAsset($sourceUrl, array(), false, $vars);
- }
-
- protected function createGlobAsset($glob, $root = null, $vars)
- {
- return new GlobAsset($glob, array(), $root, $vars);
- }
-
- protected function createFileAsset($source, $root = null, $path = null, $vars)
- {
- return new FileAsset($source, array(), $root, $path, $vars);
- }
-
protected function getFilter($name)
{
if (!$this->fm) {
@@ -361,26 +320,4 @@ private function applyWorkers(AssetCollectionInterface $asset)
return $asset instanceof AssetCollectionInterface ? $asset : $this->createAssetCollection(array($asset));
}
-
- static private function isAbsolutePath($path)
- {
- return '/' == $path[0] || '\\' == $path[0] || (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] == ':' && ('\\' == $path[2] || '/' == $path[2]));
- }
-
- /**
- * Loops through the root directories and returns the first match.
- *
- * @param string $path An absolute path
- * @param array $roots An array of root directories
- *
- * @return string|null The matching root directory, if found
- */
- static private function findRootDir($path, array $roots)
- {
- foreach ($roots as $root) {
- if (0 === strpos($path, $root)) {
- return $root;
- }
- }
- }
}
View
59 src/Assetic/Resolver/AssetReferenceResolver.php
@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+use Assetic\AssetManager;
+use Assetic\Asset\AssetReference;
+
+/**
+ * Transforms asset manager reference string into asset.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+class AssetReferenceResolver implements AssetResolverInterface
+{
+ private $am;
+
+ /**
+ * Constructor.
+ *
+ * @param AssetManager $am The asset manager
+ */
+ public function __construct(AssetManager $am)
+ {
+ $this->am = $am;
+ }
+
+ /**
+ * Parses an input string into an asset.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset
+ */
+ public function resolve($input, array $options = array())
+ {
+ if ('@' == $input[0]) {
+ return $this->createAssetReference(substr($input, 1));
+ }
+ }
+
+ protected function createAssetReference($name)
+ {
+ if (!$this->am) {
+ throw new \LogicException('There is no asset manager.');
+ }
+
+ return new AssetReference($this->am, $name);
+ }
+}
View
30 src/Assetic/Resolver/AssetResolverInterface.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+/**
+ * The asset resolver resolves asset string into asset instance.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+interface AssetResolverInterface
+{
+ /**
+ * Parses an input string string into an asset.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset
+ */
+ function resolve($input, array $options = array());
+}
View
95 src/Assetic/Resolver/FileAssetResolver.php
@@ -0,0 +1,95 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+use Assetic\Asset\FileAsset;
+
+/**
+ * Transforms filesystem path into asset.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+class FileAssetResolver implements AssetResolverInterface
+{
+ private $root;
+
+ /**
+ * Constructor.
+ *
+ * @param string $root The default root directory
+ */
+ public function __construct($root)
+ {
+ $this->root = $root;
+ }
+
+ /**
+ * Parses an input string into an asset.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset
+ */
+ public function resolve($input, array $options = array())
+ {
+ list($root, $path, $input) = $this->prepareRootPathInput($input, $options);
+
+ if (file_exists($input) && is_file($input)) {
+ return $this->createFileAsset($input, $root, $path, $options['vars']);
+ }
+ }
+
+ protected function createFileAsset($source, $root = null, $path = null, $vars)
+ {
+ return new FileAsset($source, array(), $root, $path, $vars);
+ }
+
+ protected function prepareRootPathInput($input, array $options = array())
+ {
+ if (self::isAbsolutePath($input)) {
+ if ($root = self::findRootDir($input, $options['root'])) {
+ $path = ltrim(substr($input, strlen($root)), '/');
+ } else {
+ $path = null;
+ }
+ } else {
+ $root = $this->root;
+ $path = $input;
+ $input = $this->root.'/'.$path;
+ }
+
+ return array($root, $path, $input);
+ }
+
+ /**
+ * Loops through the root directories and returns the first match.
+ *
+ * @param string $path An absolute path
+ * @param array $roots An array of root directories
+ *
+ * @return string|null The matching root directory, if found
+ */
+ static protected function findRootDir($path, array $roots)
+ {
+ foreach ($roots as $root) {
+ if (0 === strpos($path, $root)) {
+ return $root;
+ }
+ }
+ }
+
+ static protected function isAbsolutePath($path)
+ {
+ return '/' == $path[0] || '\\' == $path[0] || (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] == ':' && ('\\' == $path[2] || '/' == $path[2]));
+ }
+}
View
44 src/Assetic/Resolver/GlobAssetResolver.php
@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+use Assetic\Asset\GlobAsset;
+
+/**
+ * Transforms glob path into asset.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+class GlobAssetResolver extends FileAssetResolver
+{
+ /**
+ * Parses an input string into an asset.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset
+ */
+ public function resolve($input, array $options = array())
+ {
+ list($root, $path, $input) = $this->prepareRootPathInput($input, $options);
+
+ if (false !== strpos($input, '*')) {
+ return $this->createGlobAsset($input, $root, $options['vars']);
+ }
+ }
+
+ protected function createGlobAsset($glob, $root = null, $vars)
+ {
+ return new GlobAsset($glob, array(), $root, $vars);
+ }
+}
View
42 src/Assetic/Resolver/HttpAssetResolver.php
@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+use Assetic\Asset\HttpAsset;
+
+/**
+ * Transforms http url into an asset.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+class HttpAssetResolver implements AssetResolverInterface
+{
+ /**
+ * Parses an input string into an asset.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset
+ */
+ public function resolve($input, array $options = array())
+ {
+ if (false !== strpos($input, '://') || 0 === strpos($input, '//')) {
+ return $this->createHttpAsset($input, $options['vars']);
+ }
+ }
+
+ protected function createHttpAsset($sourceUrl, $vars)
+ {
+ return new HttpAsset($sourceUrl, array(), false, $vars);
+ }
+}
View
251 src/Assetic/Resolver/PipelineAssetResolver.php
@@ -0,0 +1,251 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Resolver;
+
+use Assetic\Asset\AssetCollection;
+use Symfony\Component\Finder\Finder;
+
+/**
+ * resolves resource in watched folders by its relative path.
+ *
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ */
+class PipelineAssetResolver extends FileAssetResolver
+{
+ private $paths;
+
+ /**
+ * Constructor.
+ *
+ * @param string $paths Paths to asset roots
+ */
+ public function __construct(array $paths = array())
+ {
+ foreach ($paths as $path) {
+ $this->addPath($path);
+ }
+ }
+
+ /**
+ * Adds path to pipeline locator resources stack.
+ *
+ * @param string $path Assets root path
+ */
+ public function addPath($path)
+ {
+ $this->paths[] = rtrim($path, '/');
+ }
+
+ /**
+ * Searches for a resource in watched paths.
+ *
+ * @param string $input An input string
+ * @param array $options An array of options
+ *
+ * @return AssetInterface An asset or asset collection
+ */
+ public function resolve($input, array $options = array())
+ {
+ $type = isset($options['type'])
+ ? $options['type']
+ : pathinfo($options['output'], PATHINFO_EXTENSION);
+
+ if (2 == count($typeParts = explode('/', $type))) {
+ switch ($typeParts[0]) {
+ case 'index':
+ return $this->resolveIndexAsset($input, $typeParts[1], $options);
+ case 'directory':
+ return $this->resolveDirectoryAssets($input, $typeParts[1], $options);
+ case 'tree':
+ return $this->resolveTreeAssets($input, $typeParts[1], $options);
+ default:
+ return $this->resolveSingleAsset($input, $typeParts[1], $options);
+ }
+ }
+
+ return $this->resolveSingleAsset($input, $type, $options)
+ ?: $this->resolveIndexAsset($input, $type, $options)
+ ?: $this->resolveDirectoryAssets($input, $type, $options);
+ }
+
+ /**
+ * resolves single asset in watched paths.
+ *
+ * @param string $resource An asset resource string
+ * @param string $type An asset type (js, css)
+ * @param array $options An array of options
+ *
+ * @return AssetInterface|null
+ */
+ protected function resolveSingleAsset($resource, $type, array $options)
+ {
+ $subpath = pathinfo($resource, PATHINFO_DIRNAME);
+ $resource = pathinfo($resource, PATHINFO_BASENAME);
+
+ $paths = array();
+ foreach ($this->paths as $path) {
+ if (is_dir($path = $path.'/'.$type.('.' != $subpath ? '/'.$subpath : ''))) {
+ $paths[] = $path;
+ }
+ }
+
+ if (!count($paths)) {
+ return;
+ }
+
+ $files = Finder::create()->files()->depth(0)->name($resource.'*')->in($paths);
+
+ return $this->createAssetFromFinder($files, $options);
+ }
+
+ /**
+ * resolves index asset for provided path in watched paths.
+ *
+ * @param string $resource An asset path resource string
+ * @param string $type An asset type (js, css)
+ * @param array $options An array of options
+ *
+ * @return AssetInterface|null
+ */
+ protected function resolveIndexAsset($resource, $type, array $options)
+ {
+ $paths = array();
+ foreach ($this->paths as $path) {
+ if (is_dir($path = $path.'/'.$type.'/'.$resource)) {
+ $paths[] = $path;
+ }
+ }
+
+ if (!count($paths)) {
+ return;
+ }
+
+ $files = Finder::create()
+ ->files()
+ ->depth(0)
+ ->name('index*')
+ ->in($paths);
+
+ return $this->createAssetFromFinder($files, $options);
+ }
+
+ /**
+ * resolves all 0-level assets inside provided directory resource in watched paths.
+ *
+ * @param string $resource An asset directory resource string
+ * @param string $type An asset type (js, css)
+ * @param array $options An array of options
+ *
+ * @return AssetCollection|null
+ */
+ protected function resolveDirectoryAssets($resource, $type, array $options)
+ {
+ if (null === $path = $this->getDirectoryPath($resource, $type)) {
+ return;
+ }
+
+ $files = Finder::create()
+ ->files()
+ ->depth(0)
+ ->sortByName(true)
+ ->in($path);
+
+ $asset = null;
+ foreach ($files as $file) {
+ $asset = $asset ?: new AssetCollection();
+ $asset->add($this->createAssetFromPath((string) $file, $options));
+ }
+
+ return $asset;
+ }
+
+ /**
+ * resolves all multilevel assets inside provided directory resource in watched paths.
+ *
+ * @param string $resource An asset directory resource string
+ * @param string $type An asset type (js, css)
+ * @param array $options An array of options
+ *
+ * @return AssetCollection|null
+ */
+ protected function resolveTreeAssets($resource, $type, array $options)
+ {
+ if (null === $path = $this->getDirectoryPath($resource, $type)) {
+ return;
+ }
+
+ $files = Finder::create()
+ ->files()
+ ->sortByName(true)
+ ->in($path);
+
+ $asset = new AssetCollection();
+ foreach ($files as $file) {
+ $asset->add($this->createAssetFromPath((string) $file, $options));
+ }
+
+ return $asset;
+ }
+
+ /**
+ * Searches for existing path in watched paths.
+ *
+ * @param string $resource A directory resource
+ *
+ * @return string|null
+ */
+ private function getDirectoryPath($resource, $type)
+ {
+ foreach ($this->paths as $watchedPath) {
+ if (is_dir($path = $watchedPath.'/'.$type.'/'.$resource)) {
+ return $path;
+ }
+ }
+ }
+
+ /**
+ * Creates asset from finder instance.
+ *
+ * @param Finder $files Finder instance
+ * @param array $options An array of options
+ *
+ * @return AssetInterface|null
+ */
+ private function createAssetFromFinder(Finder $files, array $options)
+ {
+ $input = null;
+ foreach ($files as $file) {
+ $input = (string) $file;
+ break;
+ }
+ if (null === $input) {
+ return;
+ }
+
+ return $this->createAssetFromPath($input, $options);
+ }
+
+ /**
+ * Creates asset instance from provided path.
+ *
+ * @param string $path An asset path
+ * @param array $options An array of options
+ *
+ * @return AssetInterface|null
+ */
+ private function createAssetFromPath($path, array $options)
+ {
+ list($root, $path, $input) = $this->prepareRootPathInput($path, $options);
+
+ return $this->createFileAsset($input, $root, $path, $options['vars']);
+ }
+}
View
33 tests/Assetic/Test/Factory/AssetFactoryTest.php
@@ -27,28 +27,19 @@ protected function setUp()
$this->factory = new AssetFactory(__DIR__);
$this->factory->setAssetManager($this->am);
$this->factory->setFilterManager($this->fm);
- }
-
- public function testNoAssetManagerReference()
- {
- $this->setExpectedException('LogicException', 'There is no asset manager.');
-
- $factory = new AssetFactory('.');
- $factory->createAsset(array('@foo'));
- }
- public function testNoAssetManagerNotReference()
- {
- $factory = new AssetFactory('.');
- $this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $factory->createAsset(array('foo')));
+ $this->factory->addResolver(new \Assetic\Resolver\AssetReferenceResolver($this->am));
+ $this->factory->addResolver(new \Assetic\Resolver\HttpAssetResolver());
+ $this->factory->addResolver(new \Assetic\Resolver\GlobAssetResolver(__DIR__));
+ $this->factory->addResolver(new \Assetic\Resolver\FileAssetResolver(__DIR__));
}
- public function testNoFilterManager()
+ public function testNoAppropriateResolver()
{
- $this->setExpectedException('LogicException', 'There is no filter manager.');
+ $this->setExpectedException('LogicException', 'Can not resolve asset "@foo".');
$factory = new AssetFactory('.');
- $factory->createAsset(array('foo'), array('foo'));
+ $factory->createAsset(array('@foo'));
}
public function testCreateAssetReference()
@@ -143,7 +134,7 @@ public function testIncludingOptionalFilter()
->with('foo')
->will($this->returnValue($this->getMock('Assetic\\Filter\\FilterInterface')));
- $this->factory->createAsset(array('foo.css'), array('?foo'));
+ $this->factory->createAsset(array('../Fixture/root/foo.css'), array('?foo'));
}
public function testWorkers()
@@ -156,7 +147,7 @@ public function testWorkers()
->with($this->isInstanceOf('Assetic\\Asset\\AssetInterface'));
$this->factory->addWorker($worker);
- $this->factory->createAsset(array('foo.js', 'bar.js'));
+ $this->factory->createAsset(array('../Fixture/root/foo.js', '../Fixture/root/bar.js'));
}
public function testWorkerReturn()
@@ -170,7 +161,7 @@ public function testWorkerReturn()
->will($this->returnValue($asset));
$this->factory->addWorker($worker);
- $coll = $this->factory->createAsset(array('foo.js', 'bar.js'));
+ $coll = $this->factory->createAsset(array('../Fixture/root/foo.js', '../Fixture/root/bar.js'));
$this->assertEquals(1, count(iterator_to_array($coll)));
}
@@ -183,10 +174,10 @@ public function testNestedFormula()
->will($this->returnValue($this->getMock('Assetic\\Filter\\FilterInterface')));
$inputs = array(
- 'css/main.css',
+ '../Fixture/root/css/main.css',
array(
// nested formula
- array('css/more.sass'),
+ array('../Fixture/root/css/more.sass'),
array('foo'),
),
);
View
1  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/global.css.scss
@@ -0,0 +1 @@
+/* global stylesheet */
View
1  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/menu/main.css
@@ -0,0 +1 @@
+/* main menu */
View
1  tests/Assetic/Test/Fixture/pipeline/track1/css/unindexed_tree/menu/user/bar.css.less
@@ -0,0 +1 @@
+/* userbar */
View
1  tests/Assetic/Test/Fixture/pipeline/track1/js/simple_script.js
@@ -0,0 +1 @@
+// simple javascript file
View
1  tests/Assetic/Test/Fixture/pipeline/track1/js/unindexed_library/file1.js
@@ -0,0 +1 @@
+// first script in a library
View
1  tests/Assetic/Test/Fixture/pipeline/track1/js/unindexed_library/file2.js
@@ -0,0 +1 @@
+// second script in a library
View
1  tests/Assetic/Test/Fixture/pipeline/track2/css/library/sublib/index.css
@@ -0,0 +1 @@
+/* sublib index */
View
1  tests/Assetic/Test/Fixture/pipeline/track2/css/style.css
@@ -0,0 +1 @@
+/* stylesheet */
View
1  tests/Assetic/Test/Fixture/pipeline/track2/js/subdir/subscript.js
@@ -0,0 +1 @@
+// subscript
View
1  tests/Assetic/Test/Fixture/pipeline/track3/css/style.css
@@ -0,0 +1 @@
+/* stylesheet */
View
1  tests/Assetic/Test/Fixture/pipeline/track3/js/library/index.js
@@ -0,0 +1 @@
+// library index
View
1  tests/Assetic/Test/Fixture/pipeline/track3/js/unindexed_library/file1.js
@@ -0,0 +1 @@
+// first script in a library
View
1  tests/Assetic/Test/Fixture/pipeline/track3/js/unindexed_library/file2.js
@@ -0,0 +1 @@
+// second script in a library
View
1  tests/Assetic/Test/Fixture/root/bar.js
@@ -0,0 +1 @@
+// bar script
View
1  tests/Assetic/Test/Fixture/root/css/main.css
@@ -0,0 +1 @@
+/* main CSS stylesheet */
View
1  tests/Assetic/Test/Fixture/root/css/more.sass
@@ -0,0 +1 @@
+// more stylesheet
View
1  tests/Assetic/Test/Fixture/root/foo.css
@@ -0,0 +1 @@
+/* CSS file */
View
1  tests/Assetic/Test/Fixture/root/foo.js
@@ -0,0 +1 @@
+// js script
View
43 tests/Assetic/Test/Resolver/AssetReferenceResolverTest.php
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Resolver;
+
+use Assetic\Resolver\AssetReferenceResolver;
+
+class AssetReferenceResolverTest extends \PHPUnit_Framework_TestCase
+{
+ private $locator;
+
+ protected function setUp()
+ {
+ $am = $this->getMockBuilder('Assetic\\AssetManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->locator = new AssetReferenceResolver($am);
+ }
+
+ public function testCorrectInput()
+ {
+ $asset = $this->locator->resolve('@jquery');
+
+ $this->assertNotNull($asset);
+ $this->assertInstanceOf('Assetic\\Asset\\AssetReference', $asset);
+ }
+
+ public function testWrongInput()
+ {
+ $asset = $this->locator->resolve('jquery');
+
+ $this->assertNull($asset);
+ }
+}
View
51 tests/Assetic/Test/Resolver/FileAssetResolverTest.php
@@ -0,0 +1,51 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Resolver;
+
+use Assetic\Resolver\FileAssetResolver;
+
+class FileAssetResolverTest extends \PHPUnit_Framework_TestCase
+{
+ private $locator;
+
+ protected function setUp()
+ {
+ $this->locator = new FileAssetResolver(__DIR__.'/../Fixture/root');
+ }
+
+ public function filesystemPaths()
+ {
+ return array(
+ array('foo.js'),
+ array('bar.js'),
+ array('css/more.sass'),
+ );
+ }
+
+ /**
+ * @dataProvider filesystemPaths
+ */
+ public function testCorrectInput($input)
+ {
+ $asset = $this->locator->resolve($input, array('vars' => array()));
+
+ $this->assertNotNull($asset);
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ }
+
+ public function testWrongInput()
+ {
+ $asset = $this->locator->resolve('css/jquery.js', array('vars' => array()));
+
+ $this->assertNull($asset);
+ }
+}
View
39 tests/Assetic/Test/Resolver/GlobAssetResolverTest.php
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Resolver;
+
+use Assetic\Resolver\GlobAssetResolver;
+
+class GlobAssetResolverTest extends \PHPUnit_Framework_TestCase
+{
+ private $locator;
+
+ protected function setUp()
+ {
+ $this->locator = new GlobAssetResolver(__DIR__.'/../Fixture/root');
+ }
+
+ public function testCorrectInput()
+ {
+ $asset = $this->locator->resolve('*.js', array('vars' => array()));
+
+ $this->assertNotNull($asset);
+ $this->assertInstanceOf('Assetic\\Asset\\GlobAsset', $asset);
+ }
+
+ public function testWrongInput()
+ {
+ $asset = $this->locator->resolve('js/jquery.js', array('vars' => array()));
+
+ $this->assertNull($asset);
+ }
+}
View
51 tests/Assetic/Test/Resolver/HttpAssetResolverTest.php
@@ -0,0 +1,51 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Resolver;
+
+use Assetic\Resolver\HttpAssetResolver;
+
+class HttpAssetResolverTest extends \PHPUnit_Framework_TestCase
+{
+ private $locator;
+
+ protected function setUp()
+ {
+ $this->locator = new HttpAssetResolver();
+ }
+
+ public function getHttpUrls()
+ {
+ return array(
+ array('http://example.com/foo.css'),
+ array('https://example.com/foo.css'),
+ array('//example.com/foo.css'),
+ );
+ }
+
+ /**
+ * @dataProvider getHttpUrls
+ */
+ public function testCorrectInput($sourceUrl)
+ {
+ $asset = $this->locator->resolve($sourceUrl, array('vars' => array()));
+
+ $this->assertNotNull($asset);
+ $this->assertInstanceOf('Assetic\\Asset\\HttpAsset', $asset, '->resolve() creates proper asset');
+ }
+
+ public function testWrongInput()
+ {
+ $asset = $this->locator->resolve('example.com/foo.css');
+
+ $this->assertNull($asset);
+ }
+}
View
119 tests/Assetic/Test/Resolver/PipelineAssetResolverTest.php
@@ -0,0 +1,119 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2011 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Resolver;
+
+use Assetic\Resolver\PipelineAssetResolver;
+
+class PipelineAssetResolverTest extends \PHPUnit_Framework_TestCase
+{
+ private $path;
+ private $locator;
+
+ protected function setUp()
+ {
+ $this->path = realpath(__DIR__.'/../Fixture/pipeline');
+
+ $this->locator = new PipelineAssetResolver(array(
+ $this->path.'/track3',
+ $this->path.'/track2',
+ $this->path.'/track1',
+ ));
+ }
+
+ public function testresolveSingleAsset()
+ {
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'simple_script', array('vars' => array(), 'output' => '*.js', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track1/js', $asset->getSourceRoot());
+ $this->assertSame('simple_script.js', $asset->getSourcePath());
+
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'subdir/subscript.js', array('vars' => array(), 'output' => '*.js', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track2/js/subdir', $asset->getSourceRoot());
+ $this->assertSame('subscript.js', $asset->getSourcePath());
+
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'style', array('vars' => array(), 'output' => '*.css', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track3/css', $asset->getSourceRoot());
+ $this->assertSame('style.css', $asset->getSourcePath());
+ }
+
+ public function testresolveIndexAsset()
+ {
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'library', array('vars' => array(), 'output' => '*.js', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track3/js/library', $asset->getSourceRoot());
+ $this->assertSame('index.js', $asset->getSourcePath());
+
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'library/sublib', array('vars' => array(), 'output' => '*.css', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track2/css/library/sublib', $asset->getSourceRoot());
+ $this->assertSame('index.css', $asset->getSourcePath());
+ }
+
+ public function testresolveDirectoryAssets()
+ {
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'unindexed_library', array('vars' => array(), 'output' => '*.js', 'root' => array())
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\AssetCollection', $asset);
+
+ $assets = $asset->all();
+ $this->assertSame(2, count($assets));
+
+ $asset = $assets[0];
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track3/js/unindexed_library', $asset->getSourceRoot());
+ $this->assertSame('file1.js', $asset->getSourcePath());
+
+ $asset = $assets[1];
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track3/js/unindexed_library', $asset->getSourceRoot());
+ $this->assertSame('file2.js', $asset->getSourcePath());
+ }
+
+ public function testresolveTreeAssets()
+ {
+ $this->assertNotNull($asset = $this->locator->resolve(
+ 'unindexed_tree', array('vars' => array(), 'output' => '*.css', 'root' => array(), 'type' => 'tree/css')
+ ));
+ $this->assertInstanceOf('Assetic\\Asset\\AssetCollection', $asset);
+
+ $assets = $asset->all();
+ $this->assertSame(3, count($assets));
+
+ $asset = $assets[0];
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track1/css/unindexed_tree', $asset->getSourceRoot());
+ $this->assertSame('global.css.scss', $asset->getSourcePath());
+
+ $asset = $assets[1];
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track1/css/unindexed_tree/menu', $asset->getSourceRoot());
+ $this->assertSame('main.css', $asset->getSourcePath());
+
+ $asset = $assets[2];
+ $this->assertInstanceOf('Assetic\\Asset\\FileAsset', $asset);
+ $this->assertSame($this->path.'/track1/css/unindexed_tree/menu/user', $asset->getSourceRoot());
+ $this->assertSame('bar.css.less', $asset->getSourcePath());
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.