Initial commit with Symfony 2.1+Vendors

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-07-01 09:52:20 +02:00
commit 082a0130c2
5381 changed files with 416709 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2012 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\Extension\Twig;
use Assetic\Factory\AssetFactory;
use Assetic\Extension\Twig\AsseticExtension;
class AsseticExtensionTest extends \PHPUnit_Framework_TestCase
{
private $am;
private $fm;
private $factory;
private $twig;
protected function setUp()
{
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not installed.');
}
$this->am = $this->getMock('Assetic\\AssetManager');
$this->fm = $this->getMock('Assetic\\FilterManager');
$this->valueSupplier = $this->getMock('Assetic\ValueSupplierInterface');
$this->factory = new AssetFactory(__DIR__.'/templates');
$this->factory->setAssetManager($this->am);
$this->factory->setFilterManager($this->fm);
$this->twig = new \Twig_Environment();
$this->twig->setLoader(new \Twig_Loader_Filesystem(__DIR__.'/templates'));
$this->twig->addExtension(new AsseticExtension($this->factory, array(), $this->valueSupplier));
}
public function testReference()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->any())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$xml = $this->renderXml('reference.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/', (string) $xml->asset['url']);
}
public function testGlob()
{
$xml = $this->renderXml('glob.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/', (string) $xml->asset['url']);
}
public function testAbsolutePath()
{
$xml = $this->renderXml('absolute_path.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/', (string) $xml->asset['url']);
}
public function testFilters()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->fm->expects($this->at(0))
->method('get')
->with('foo')
->will($this->returnValue($filter));
$this->fm->expects($this->at(1))
->method('get')
->with('bar')
->will($this->returnValue($filter));
$xml = $this->renderXml('filters.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/', (string) $xml->asset['url']);
}
public function testOptionalFilter()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->fm->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($filter));
$xml = $this->renderXml('optional_filter.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/', (string) $xml->asset['url']);
}
public function testOutputPattern()
{
$xml = $this->renderXml('output_pattern.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringStartsWith('css/packed/', (string) $xml->asset['url']);
$this->assertStringEndsWith('.css', (string) $xml->asset['url']);
}
public function testOutput()
{
$xml = $this->renderXml('output_url.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertEquals('explicit_url.css', (string) $xml->asset['url']);
}
public function testMixture()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->any())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$xml = $this->renderXml('mixture.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertEquals('packed/mixture', (string) $xml->asset['url']);
}
public function testDebug()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->fm->expects($this->once())
->method('get')
->with('bar')
->will($this->returnValue($filter));
$xml = $this->renderXml('debug.twig');
$this->assertEquals(2, count($xml->asset));
$this->assertStringStartsWith('css/packed_', (string) $xml->asset[0]['url']);
$this->assertStringEndsWith('.css', (string) $xml->asset[0]['url']);
}
public function testCombine()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->fm->expects($this->once())
->method('get')
->with('bar')
->will($this->returnValue($filter));
$xml = $this->renderXml('combine.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertEquals('css/packed.css', (string) $xml->asset[0]['url']);
}
public function testImage()
{
$xml = $this->renderXml('image.twig');
$this->assertEquals(1, count($xml->image));
$this->assertStringEndsWith('.png', (string) $xml->image[0]['url']);
}
public function testFilterFunction()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->fm->expects($this->once())
->method('get')
->with('some_filter')
->will($this->returnValue($filter));
$this->twig->addExtension(new AsseticExtension($this->factory, array(
'some_func' => array(
'filter' => 'some_filter',
'options' => array('output' => 'css/*.css'),
),
)));
$xml = $this->renderXml('function.twig');
$this->assertEquals(1, count($xml->asset));
$this->assertStringEndsWith('.css', (string) $xml->asset[0]['url']);
}
public function testVariables()
{
$this->valueSupplier->expects($this->once())
->method('getValues')
->will($this->returnValue(array('foo' => 'a', 'bar' => 'b')));
$xml = $this->renderXml('variables.twig');
$this->assertEquals(2, $xml->url->count());
$this->assertEquals("js/7d0828c_foo_1.a.b.js", (string) $xml->url[0]);
$this->assertEquals("js/7d0828c_variable_input.a_2.a.b.js", (string) $xml->url[1]);
}
private function renderXml($name, $context = array())
{
return new \SimpleXMLElement($this->twig->loadTemplate($name)->render($context));
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2012 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\Extension\Twig;
use Assetic\Factory\AssetFactory;
use Assetic\Extension\Twig\AsseticExtension;
use Assetic\Extension\Twig\TwigFormulaLoader;
class TwigFormulaLoaderTest extends \PHPUnit_Framework_TestCase
{
private $am;
private $fm;
private $twig;
protected function setUp()
{
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not installed.');
}
$this->am = $this->getMock('Assetic\\AssetManager');
$this->fm = $this->getMock('Assetic\\FilterManager');
$factory = new AssetFactory(__DIR__.'/templates');
$factory->setAssetManager($this->am);
$factory->setFilterManager($this->fm);
$twig = new \Twig_Environment();
$twig->addExtension(new AsseticExtension($factory, array(
'some_func' => array(
'filter' => 'some_filter',
'options' => array('output' => 'css/*.css'),
),
)));
$this->loader = new TwigFormulaLoader($twig);
}
public function testMixture()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$expected = array(
'mixture' => array(
array('foo', 'foo/*', '@foo'),
array(),
array(
'output' => 'packed/mixture',
'name' => 'mixture',
'debug' => false,
'combine' => null,
'vars' => array(),
),
),
);
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
$resource->expects($this->once())
->method('getContent')
->will($this->returnValue(file_get_contents(__DIR__.'/templates/mixture.twig')));
$this->am->expects($this->any())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$formulae = $this->loader->load($resource);
$this->assertEquals($expected, $formulae);
}
public function testFunction()
{
$expected = array(
'my_asset' => array(
array('path/to/asset'),
array('some_filter'),
array('output' => 'css/*.css', 'name' => 'my_asset'),
),
);
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
$resource->expects($this->once())
->method('getContent')
->will($this->returnValue(file_get_contents(__DIR__.'/templates/function.twig')));
$formulae = $this->loader->load($resource);
$this->assertEquals($expected, $formulae);
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2012 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\Extension\Twig;
use Assetic\Extension\Twig\TwigResource;
class TwigResourceTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not installed.');
}
}
public function testInvalidTemplateNameGetContent()
{
$loader = $this->getMock('Twig_LoaderInterface');
$loader->expects($this->once())
->method('getSource')
->with('asdf')
->will($this->throwException(new \Twig_Error_Loader('')));
$resource = new TwigResource($loader, 'asdf');
$this->assertEquals('', $resource->getContent());
}
public function testInvalidTemplateNameIsFresh()
{
$loader = $this->getMock('Twig_LoaderInterface');
$loader->expects($this->once())
->method('isFresh')
->with('asdf', 1234)
->will($this->throwException(new \Twig_Error_Loader('')));
$resource = new TwigResource($loader, 'asdf');
$this->assertFalse($resource->isFresh(1234));
}
}

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets '/path/to/something.css' as='foo' %}<asset url="{{ foo }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo.css' 'bar.css' filter='?foo,bar' output='css/packed.css' debug=true combine=true %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo.css' 'bar.css' filter='?foo,bar' output='css/packed.css' debug=true %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo' filter='foo, bar' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
<asset url="{{ some_func('path/to/asset', { 'name': 'my_asset' }) }}" />
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'css/src/*' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<images>
{% image 'images/foo.png' %}<image url="{{ asset_url }}" />{% endimage %}
</images>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo' 'foo/*' '@foo' output='packed/*' name='mixture' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo' filter='?foo' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo' output='css/packed/*.css' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets 'foo' output='explicit_url.css' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,3 @@
<assets>
{% stylesheets '@foo' %}<asset url="{{ asset_url }}" />{% endstylesheets %}
</assets>

View File

@@ -0,0 +1,5 @@
<assets>
{% javascripts "foo.js" "variable_input.{foo}.js" vars=["foo", "bar"] debug=true %}
<url>{{ asset_url }}</url>
{% endjavascripts %}
</assets>