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,175 @@
<?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\Asset;
use Assetic\Asset\AssetCache;
class AssetCacheTest extends \PHPUnit_Framework_TestCase
{
private $inner;
private $cache;
private $asset;
protected function setUp()
{
$this->inner = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->cache = $this->getMock('Assetic\\Cache\\CacheInterface');
$this->asset = new AssetCache($this->inner, $this->cache);
}
public function testLoadFromCache()
{
$content = 'asdf';
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->inner->expects($this->once())
->method('getFilters')
->will($this->returnValue(array($filter)));
$this->cache->expects($this->once())
->method('has')
->with($this->isType('string'))
->will($this->returnValue(true));
$this->cache->expects($this->once())
->method('get')
->with($this->isType('string'))
->will($this->returnValue($content));
$this->inner->expects($this->once())
->method('setContent')
->with($content);
$this->asset->load($filter);
}
public function testLoadToCache()
{
$content = 'asdf';
$this->inner->expects($this->once())
->method('getFilters')
->will($this->returnValue(array()));
$this->cache->expects($this->once())
->method('has')
->with($this->isType('string'))
->will($this->returnValue(false));
$this->inner->expects($this->once())->method('load');
$this->inner->expects($this->once())
->method('getContent')
->will($this->returnValue($content));
$this->cache->expects($this->once())
->method('set')
->with($this->isType('string'), $content);
$this->asset->load();
}
public function testDumpFromCache()
{
$content = 'asdf';
$this->inner->expects($this->once())
->method('getFilters')
->will($this->returnValue(array()));
$this->cache->expects($this->once())
->method('has')
->with($this->isType('string'))
->will($this->returnValue(true));
$this->cache->expects($this->once())
->method('get')
->with($this->isType('string'))
->will($this->returnValue($content));
$this->assertEquals($content, $this->asset->dump(), '->dump() returns the cached value');
}
public function testDumpToCache()
{
$content = 'asdf';
$this->inner->expects($this->once())
->method('getFilters')
->will($this->returnValue(array()));
$this->cache->expects($this->once())
->method('has')
->with($this->isType('string'))
->will($this->returnValue(false));
$this->inner->expects($this->once())
->method('dump')
->will($this->returnValue($content));
$this->cache->expects($this->once())
->method('set')
->with($this->isType('string'), $content);
$this->assertEquals($content, $this->asset->dump(), '->dump() returns the dumped value');
}
public function testEnsureFilter()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$this->inner->expects($this->once())->method('ensureFilter');
$this->asset->ensureFilter($filter);
}
public function testGetFilters()
{
$this->inner->expects($this->once())
->method('getFilters')
->will($this->returnValue(array()));
$this->assertInternalType('array', $this->asset->getFilters(), '->getFilters() returns the inner asset filters');
}
public function testGetContent()
{
$this->inner->expects($this->once())
->method('getContent')
->will($this->returnValue('asdf'));
$this->assertEquals('asdf', $this->asset->getContent(), '->getContent() returns the inner asset content');
}
public function testSetContent()
{
$this->inner->expects($this->once())
->method('setContent')
->with('asdf');
$this->asset->setContent('asdf');
}
public function testGetSourceRoot()
{
$this->inner->expects($this->once())
->method('getSourceRoot')
->will($this->returnValue('asdf'));
$this->assertEquals('asdf', $this->asset->getSourceRoot(), '->getSourceRoot() returns the inner asset source root');
}
public function testGetSourcePath()
{
$this->inner->expects($this->once())
->method('getSourcePath')
->will($this->returnValue('asdf'));
$this->assertEquals('asdf', $this->asset->getSourcePath(), '->getSourcePath() returns the inner asset source path');
}
public function testGetLastModified()
{
$this->inner->expects($this->once())
->method('getLastModified')
->will($this->returnValue(123));
$this->assertEquals(123, $this->asset->getLastModified(), '->getLastModified() returns the inner asset last modified');
}
}

View File

@@ -0,0 +1,318 @@
<?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\Asset;
use Assetic\Asset\StringAsset;
use Assetic\Asset\AssetCollection;
use Assetic\Filter\CallablesFilter;
class AssetCollectionTest extends \PHPUnit_Framework_TestCase
{
public function testInterface()
{
$coll = new AssetCollection();
$this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $coll, 'AssetCollection implements AssetInterface');
}
public function testLoadFilter()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())->method('filterLoad');
$coll = new AssetCollection(array(new StringAsset('')), array($filter));
$coll->load();
}
public function testDumpFilter()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())->method('filterDump');
$coll = new AssetCollection(array(new StringAsset('')), array($filter));
$coll->dump();
}
public function testNestedCollectionLoad()
{
$content = 'foobar';
$count = 0;
$matches = array();
$filter = new CallablesFilter(function($asset) use ($content, & $matches, & $count)
{
++$count;
if ($content == $asset->getContent()) {
$matches[] = $asset;
}
});
$innerColl = new AssetCollection(array(new StringAsset($content)));
$outerColl = new AssetCollection(array($innerColl), array($filter));
$outerColl->load();
$this->assertEquals(1, count($matches), '->load() applies filters to leaves');
$this->assertEquals(1, $count, '->load() applies filters to leaves only');
}
public function testMixedIteration()
{
$asset = new StringAsset('asset');
$nestedAsset = new StringAsset('nested');
$innerColl = new AssetCollection(array($nestedAsset));
$contents = array();
$filter = new CallablesFilter(function($asset) use(& $contents)
{
$contents[] = $asset->getContent();
});
$coll = new AssetCollection(array($asset, $innerColl), array($filter));
$coll->load();
$this->assertEquals(array('asset', 'nested'), $contents, '->load() iterates over multiple levels');
}
public function testLoadDedupBySourceUrl()
{
$asset1 = new StringAsset('asset', array(), '/some/dir', 'foo.bar');
$asset2 = new StringAsset('asset', array(), '/some/dir', 'foo.bar');
$coll = new AssetCollection(array($asset1, $asset2));
$coll->load();
$this->assertEquals('asset', $coll->getContent(), '->load() detects duplicate assets based on source URL');
}
public function testLoadDedupByStrictEquality()
{
$asset = new StringAsset('foo');
$coll = new AssetCollection(array($asset, $asset));
$coll->load();
$this->assertEquals('foo', $coll->getContent(), '->load() detects duplicate assets based on strict equality');
}
public function testDumpDedupBySourceUrl()
{
$asset1 = new StringAsset('asset', array(), '/some/dir', 'foo.bar');
$asset2 = new StringAsset('asset', array(), '/some/dir', 'foo.bar');
$coll = new AssetCollection(array($asset1, $asset2));
$coll->load();
$this->assertEquals('asset', $coll->dump(), '->dump() detects duplicate assets based on source URL');
}
public function testDumpDedupByStrictEquality()
{
$asset = new StringAsset('foo');
$coll = new AssetCollection(array($asset, $asset));
$coll->load();
$this->assertEquals('foo', $coll->dump(), '->dump() detects duplicate assets based on strict equality');
}
public function testIterationFilters()
{
$count = 0;
$filter = new CallablesFilter(function() use(&$count) { ++$count; });
$coll = new AssetCollection();
$coll->add(new StringAsset(''));
$coll->ensureFilter($filter);
foreach ($coll as $asset) {
$asset->dump();
}
$this->assertEquals(1, $count, 'collection filters are called when child assets are iterated over');
}
public function testSetContent()
{
$coll = new AssetCollection();
$coll->setContent('asdf');
$this->assertEquals('asdf', $coll->getContent(), '->setContent() sets the content');
}
/**
* @dataProvider getTimestampsAndExpected
*/
public function testGetLastModified($timestamps, $expected)
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
for ($i = 0; $i < count($timestamps); $i++) {
$asset->expects($this->at($i))
->method('getLastModified')
->will($this->returnValue($timestamps[$i]));
}
$coll = new AssetCollection(array_fill(0, count($timestamps), $asset));
$this->assertEquals($expected, $coll->getLastModified(), '->getLastModifed() returns the highest last modified');
}
public function getTimestampsAndExpected()
{
return array(
array(array(1, 2, 3), 3),
array(array(5, 4, 3), 5),
array(array(3, 8, 5), 8),
array(array(3, 8, null), 8),
);
}
public function testRecursiveIteration()
{
$asset1 = $this->getMock('Assetic\\Asset\\AssetInterface');
$asset2 = $this->getMock('Assetic\\Asset\\AssetInterface');
$asset3 = $this->getMock('Assetic\\Asset\\AssetInterface');
$asset4 = $this->getMock('Assetic\\Asset\\AssetInterface');
$coll3 = new AssetCollection(array($asset1, $asset2));
$coll2 = new AssetCollection(array($asset3, $coll3));
$coll1 = new AssetCollection(array($asset4, $coll2));
$i = 0;
foreach ($coll1 as $a) {
$i++;
}
$this->assertEquals(4, $i, 'iteration with a recursive iterator is recursive');
}
public function testRecursiveDeduplication()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$coll3 = new AssetCollection(array($asset, $asset));
$coll2 = new AssetCollection(array($asset, $coll3));
$coll1 = new AssetCollection(array($asset, $coll2));
$i = 0;
foreach ($coll1 as $a) {
$i++;
}
$this->assertEquals(1, $i, 'deduplication is performed recursively');
}
public function testIteration()
{
$asset1 = new StringAsset('asset1', array(), '/some/dir', 'foo.css');
$asset2 = new StringAsset('asset2', array(), '/some/dir', 'foo.css');
$asset3 = new StringAsset('asset3', array(), '/some/dir', 'bar.css');
$coll = new AssetCollection(array($asset1, $asset2, $asset3));
$count = 0;
foreach ($coll as $a) {
++$count;
}
$this->assertEquals(2, $count, 'iterator filters duplicates based on url');
}
public function testBasenameCollision()
{
$asset1 = new StringAsset('asset1', array(), '/some/dir', 'foo/foo.css');
$asset2 = new StringAsset('asset2', array(), '/some/dir', 'bar/foo.css');
$coll = new AssetCollection(array($asset1, $asset2));
$urls = array();
foreach ($coll as $leaf) {
$urls[] = $leaf->getTargetPath();
}
$this->assertEquals(2, count(array_unique($urls)), 'iterator prevents basename collisions');
}
public function testEmptyMtime()
{
$coll = new AssetCollection();
$this->assertNull($coll->getLastModified(), '->getLastModified() returns null on empty collection');
}
public function testLeafManipulation()
{
$coll = new AssetCollection(array(new StringAsset('asdf')));
foreach ($coll as $leaf) {
$leaf->setTargetPath('asdf');
}
foreach ($coll as $leaf) {
$this->assertEquals('asdf', $leaf->getTargetPath(), 'leaf changes persist between iterations');
}
}
public function testRemoveLeaf()
{
$coll = new AssetCollection(array(
$leaf = new StringAsset('asdf'),
));
$this->assertTrue($coll->removeLeaf($leaf));
}
public function testRemoveRecursiveLeaf()
{
$coll = new AssetCollection(array(
new AssetCollection(array(
$leaf = new StringAsset('asdf'),
))
));
$this->assertTrue($coll->removeLeaf($leaf));
}
public function testRemoveInvalidLeaf()
{
$this->setExpectedException('InvalidArgumentException');
$coll = new AssetCollection();
$coll->removeLeaf(new StringAsset('asdf'));
}
public function testReplaceLeaf()
{
$coll = new AssetCollection(array(
$leaf = new StringAsset('asdf'),
));
$this->assertTrue($coll->replaceLeaf($leaf, new StringAsset('foo')));
}
public function testReplaceRecursiveLeaf()
{
$coll = new AssetCollection(array(
new AssetCollection(array(
$leaf = new StringAsset('asdf'),
)),
));
$this->assertTrue($coll->replaceLeaf($leaf, new StringAsset('foo')));
}
public function testReplaceInvalidLeaf()
{
$this->setExpectedException('InvalidArgumentException');
$coll = new AssetCollection();
$coll->replaceLeaf(new StringAsset('foo'), new StringAsset('bar'));
}
}

View File

@@ -0,0 +1,126 @@
<?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\Asset;
use Assetic\Asset\AssetReference;
class AssetReferenceTest extends \PHPUnit_Framework_TestCase
{
private $am;
private $ref;
protected function setUp()
{
$this->am = $this->getMock('Assetic\\AssetManager');
$this->ref = new AssetReference($this->am, 'foo');
}
/**
* @dataProvider getMethodAndRetVal
*/
public function testMethods($method, $returnValue)
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->once())
->method($method)
->will($this->returnValue($returnValue));
$this->assertEquals($returnValue, $this->ref->$method(), '->'.$method.'() returns the asset value');
}
public function getMethodAndRetVal()
{
return array(
array('getContent', 'asdf'),
array('getSourceRoot', 'asdf'),
array('getSourcePath', 'asdf'),
array('getTargetPath', 'asdf'),
array('getLastModified', 123),
);
}
public function testLazyFilters()
{
$this->am->expects($this->never())->method('get');
$this->ref->ensureFilter($this->getMock('Assetic\\Filter\\FilterInterface'));
}
public function testFilterFlush()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->exactly(2))
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->once())->method('ensureFilter');
$asset->expects($this->once())
->method('getFilters')
->will($this->returnValue(array()));
$this->ref->ensureFilter($this->getMock('Assetic\\Filter\\FilterInterface'));
$this->assertInternalType('array', $this->ref->getFilters(), '->getFilters() flushes and returns filters');
}
public function testSetContent()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->once())
->method('setContent')
->with('asdf');
$this->ref->setContent('asdf');
}
public function testLoad()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->exactly(2))
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->once())
->method('load')
->with($filter);
$this->ref->load($filter);
}
public function testDump()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$this->am->expects($this->exactly(2))
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->once())
->method('dump')
->with($filter);
$this->ref->dump($filter);
}
}

View File

@@ -0,0 +1,72 @@
<?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\Asset;
use Assetic\Asset\FileAsset;
class FileAssetTest extends \PHPUnit_Framework_TestCase
{
public function testInterface()
{
$asset = new FileAsset(__FILE__);
$this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $asset, 'Asset implements AssetInterface');
}
public function testLazyLoading()
{
$asset = new FileAsset(__FILE__);
$this->assertEmpty($asset->getContent(), 'The asset content is empty before load');
$asset->load();
$this->assertNotEmpty($asset->getContent(), 'The asset content is not empty after load');
}
public function testGetLastModifiedType()
{
$asset = new FileAsset(__FILE__);
$this->assertInternalType('integer', $asset->getLastModified(), '->getLastModified() returns an integer');
}
public function testGetLastModifiedTypeFileNotFound()
{
$asset = new FileAsset(__DIR__ . "/foo/bar/baz.css");
$this->setExpectedException("RuntimeException", "The source file");
$asset->getLastModified();
}
public function testGetLastModifiedValue()
{
$asset = new FileAsset(__FILE__);
$this->assertLessThan(time(), $asset->getLastModified(), '->getLastModified() returns the mtime');
}
public function testDefaultBaseAndPath()
{
$asset = new FileAsset(__FILE__);
$this->assertEquals(__DIR__, $asset->getSourceRoot(), '->__construct() defaults base to the asset directory');
$this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() defaults path to the asset basename');
}
public function testPathGuessing()
{
$asset = new FileAsset(__FILE__, array(), __DIR__);
$this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() guesses the asset path');
}
public function testInvalidBase()
{
$this->setExpectedException('InvalidArgumentException');
$asset = new FileAsset(__FILE__, array(), __DIR__.'/foo');
}
}

View File

@@ -0,0 +1,61 @@
<?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\Asset;
use Assetic\Asset\GlobAsset;
class GlobAssetTest extends \PHPUnit_Framework_TestCase
{
public function testInterface()
{
$asset = new GlobAsset(__DIR__.'/*.php');
$this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $asset, 'Asset implements AssetInterface');
}
public function testIteration()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$this->assertGreaterThan(0, iterator_count($assets), 'GlobAsset initializes for iteration');
}
public function testRecursiveIteration()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$this->assertGreaterThan(0, iterator_count($assets), 'GlobAsset initializes for recursive iteration');
}
public function testGetLastModifiedType()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$this->assertInternalType('integer', $assets->getLastModified(), '->getLastModified() returns an integer');
}
public function testGetLastModifiedValue()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$this->assertLessThan(time(), $assets->getLastModified(), '->getLastModified() returns a file mtime');
}
public function testLoad()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$assets->load();
$this->assertNotEmpty($assets->getContent(), '->load() loads contents');
}
public function testDump()
{
$assets = new GlobAsset(__DIR__.'/*.php');
$this->assertNotEmpty($assets->dump(), '->dump() dumps contents');
}
}

View File

@@ -0,0 +1,58 @@
<?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\Asset;
use Assetic\Asset\HttpAsset;
class HttpAssetTest extends \PHPUnit_Framework_TestCase
{
const JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
public function testGetLastModified()
{
if (!extension_loaded('openssl')) {
$this->markTestSkipped('The OpenSSL extension is not loaded.');
}
$asset = new HttpAsset(self::JQUERY);
$this->assertInternalType('integer', $asset->getLastModified(), '->getLastModified() returns an integer');
}
public function testProtocolRelativeUrl()
{
$asset = new HttpAsset(substr(self::JQUERY, 6));
$asset->load();
$this->assertNotEmpty($asset->getContent());
}
public function testMalformedUrl()
{
$this->setExpectedException('InvalidArgumentException');
new HttpAsset(__FILE__);
}
public function testInvalidUrl()
{
$this->setExpectedException('RuntimeException');
$asset = new HttpAsset('http://invalid.com/foobar');
$asset->load();
}
public function testSourceMetadata()
{
$asset = new HttpAsset(self::JQUERY);
$this->assertEquals('https://ajax.googleapis.com', $asset->getSourceRoot(), '->__construct() set the source root');
$this->assertEquals('ajax/libs/jquery/1.6.1/jquery.min.js', $asset->getSourcePath(), '->__construct() set the source path');
}
}

View File

@@ -0,0 +1,79 @@
<?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\Asset;
use Assetic\Asset\StringAsset;
class StringAssetTest extends \PHPUnit_Framework_TestCase
{
public function testInterface()
{
$asset = new StringAsset('');
$this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $asset, 'Asset implements AssetInterface');
}
public function testLoadAppliesFilters()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())->method('filterLoad');
$asset = new StringAsset('foo', array($filter));
$asset->load();
}
public function testAutomaticLoad()
{
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())->method('filterLoad');
$asset = new StringAsset('foo', array($filter));
$asset->dump();
}
public function testGetFilters()
{
$asset = new StringAsset('');
$this->assertInternalType('array', $asset->getFilters(), '->getFilters() returns an array');
}
public function testLoadAppliesAdditionalFilter()
{
$asset = new StringAsset('');
$asset->load();
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())
->method('filterLoad')
->with($asset);
$asset->load($filter);
}
public function testDumpAppliesAdditionalFilter()
{
$asset = new StringAsset('');
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
$filter->expects($this->once())
->method('filterDump')
->with($asset);
$asset->dump($filter);
}
public function testLastModified()
{
$asset = new StringAsset('');
$asset->setLastModified(123);
$this->assertEquals(123, $asset->getLastModified(), '->getLastModified() return the set last modified value');
}
}