Skip to content

Commit

Permalink
[AsseticBundle] added setting asset root when using bundle notation
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed May 15, 2011
1 parent b173884 commit 7f7ea42
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/Symfony/Bundle/AsseticBundle/Factory/AssetFactory.php
Expand Up @@ -42,15 +42,23 @@ public function __construct(KernelInterface $kernel, ContainerInterface $contain
}

/**
* Adds support for bundle notation and globs.
* Adds support for bundle notation file and glob assets.
*
* Please note this is a naive implementation of globs in that it doesn't
* FIXME: This is a naive implementation of globs in that it doesn't
* attempt to support bundle inheritance within the glob pattern itself.
*/
protected function parseInput($input, array $options = array())
{
// expand bundle notation
if ('@' == $input[0] && false !== strpos($input, '/')) {
// use the bundle path as this asset's root
$bundle = substr($input, 1);
if (false !== $pos = strpos($bundle, '/')) {
$bundle = substr($bundle, 0, $pos);
}
$options['root'] = array($this->kernel->getBundle($bundle)->getPath());

// canonicalize the input
if (false !== $pos = strpos($input, '*')) {
// locateResource() does not support globs so we provide a naive implementation here
list($before, $after) = explode('*', $input, 2);
Expand Down
Expand Up @@ -33,26 +33,51 @@ protected function setUp()
public function testBundleNotation()
{
$input = '@MyBundle/Resources/css/main.css';
$bundle = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');

$this->kernel->expects($this->once())
->method('getBundle')
->with('MyBundle')
->will($this->returnValue($bundle));
$this->kernel->expects($this->once())
->method('locateResource')
->with($input)
->will($this->returnValue('/path/to/bundle/Resources/css/main.css'));
->will($this->returnValue('/path/to/MyBundle/Resources/css/main.css'));
$bundle->expects($this->once())
->method('getPath')
->will($this->returnValue('/path/to/MyBundle'));

$coll = $this->factory->createAsset($input)->all();
$asset = $coll[0];

$this->factory->createAsset($input);
$this->assertEquals('/path/to/MyBundle', $asset->getSourceRoot(), '->createAsset() sets the asset root');
$this->assertEquals('Resources/css/main.css', $asset->getSourcePath(), '->createAsset() sets the asset path');
}

/**
* @dataProvider getGlobs
*/
public function testBundleGlobNotation($input)
{
$bundle = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');

$this->kernel->expects($this->once())
->method('getBundle')
->with('MyBundle')
->will($this->returnValue($bundle));
$this->kernel->expects($this->once())
->method('locateResource')
->with('@MyBundle/Resources/css/')
->will($this->returnValue('/path/to/bundle/Resources/css/'));
->will($this->returnValue('/path/to/MyBundle/Resources/css/'));
$bundle->expects($this->once())
->method('getPath')
->will($this->returnValue('/path/to/MyBundle'));

$coll = $this->factory->createAsset($input)->all();
$asset = $coll[0];

$this->factory->createAsset($input);
$this->assertEquals('/path/to/MyBundle', $asset->getSourceRoot(), '->createAsset() sets the asset root');
$this->assertNull($asset->getSourcePath(), '->createAsset() sets the asset path to null');
}

public function getGlobs()
Expand Down

0 comments on commit 7f7ea42

Please sign in to comment.