Initial commit with Symfony 2.1+Vendors
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
203
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/AssetFactoryTest.php
vendored
Normal file
203
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/AssetFactoryTest.php
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
<?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\Factory;
|
||||
|
||||
use Assetic\Factory\AssetFactory;
|
||||
|
||||
class AssetFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $am;
|
||||
private $fm;
|
||||
private $factory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->am = $this->getMock('Assetic\\AssetManager');
|
||||
$this->fm = $this->getMock('Assetic\\FilterManager');
|
||||
|
||||
$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')));
|
||||
}
|
||||
|
||||
public function testNoFilterManager()
|
||||
{
|
||||
$this->setExpectedException('LogicException', 'There is no filter manager.');
|
||||
|
||||
$factory = new AssetFactory('.');
|
||||
$factory->createAsset(array('foo'), array('foo'));
|
||||
}
|
||||
|
||||
public function testCreateAssetReference()
|
||||
{
|
||||
$referenced = $this->getMock('Assetic\\Asset\\AssetInterface');
|
||||
|
||||
$this->am->expects($this->any())
|
||||
->method('get')
|
||||
->with('jquery')
|
||||
->will($this->returnValue($referenced));
|
||||
|
||||
$assets = $this->factory->createAsset(array('@jquery'));
|
||||
$arr = iterator_to_array($assets);
|
||||
$this->assertInstanceOf('Assetic\\Asset\\AssetReference', $arr[0], '->createAsset() creates a reference');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getHttpUrls
|
||||
*/
|
||||
public function testCreateHttpAsset($sourceUrl)
|
||||
{
|
||||
$assets = $this->factory->createAsset(array($sourceUrl));
|
||||
$arr = iterator_to_array($assets);
|
||||
$this->assertInstanceOf('Assetic\\Asset\\HttpAsset', $arr[0], '->createAsset() creates an HTTP asset');
|
||||
}
|
||||
|
||||
public function getHttpUrls()
|
||||
{
|
||||
return array(
|
||||
array('http://example.com/foo.css'),
|
||||
array('https://example.com/foo.css'),
|
||||
array('//example.com/foo.css'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateFileAsset()
|
||||
{
|
||||
$assets = $this->factory->createAsset(array(basename(__FILE__)));
|
||||
$arr = iterator_to_array($assets);
|
||||
$this->assertInstanceOf('Assetic\\Asset\\FileAsset', $arr[0], '->createAsset() creates a file asset');
|
||||
}
|
||||
|
||||
public function testCreateGlobAsset()
|
||||
{
|
||||
$assets = $this->factory->createAsset(array('*'));
|
||||
$arr = iterator_to_array($assets);
|
||||
$this->assertInstanceOf('Assetic\\Asset\\FileAsset', $arr[0], '->createAsset() uses a glob to create a file assets');
|
||||
}
|
||||
|
||||
public function testCreateAssetCollection()
|
||||
{
|
||||
$asset = $this->factory->createAsset(array('*', basename(__FILE__)));
|
||||
$this->assertInstanceOf('Assetic\\Asset\\AssetCollection', $asset, '->createAsset() creates an asset collection');
|
||||
}
|
||||
|
||||
public function testFilter()
|
||||
{
|
||||
$this->fm->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($this->getMock('Assetic\\Filter\\FilterInterface')));
|
||||
|
||||
$asset = $this->factory->createAsset(array(), array('foo'));
|
||||
$this->assertEquals(1, count($asset->getFilters()), '->createAsset() adds filters');
|
||||
}
|
||||
|
||||
public function testInvalidFilter()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->fm->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->throwException(new \InvalidArgumentException()));
|
||||
|
||||
$asset = $this->factory->createAsset(array(), array('foo'));
|
||||
}
|
||||
|
||||
public function testOptionalInvalidFilter()
|
||||
{
|
||||
$this->factory->setDebug(true);
|
||||
|
||||
$asset = $this->factory->createAsset(array(), array('?foo'));
|
||||
|
||||
$this->assertEquals(0, count($asset->getFilters()), '->createAsset() does not add an optional invalid filter');
|
||||
}
|
||||
|
||||
public function testIncludingOptionalFilter()
|
||||
{
|
||||
$this->fm->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($this->getMock('Assetic\\Filter\\FilterInterface')));
|
||||
|
||||
$this->factory->createAsset(array('foo.css'), array('?foo'));
|
||||
}
|
||||
|
||||
public function testWorkers()
|
||||
{
|
||||
$worker = $this->getMock('Assetic\\Factory\\Worker\\WorkerInterface');
|
||||
|
||||
// called once on the collection and once on each leaf
|
||||
$worker->expects($this->exactly(3))
|
||||
->method('process')
|
||||
->with($this->isInstanceOf('Assetic\\Asset\\AssetInterface'));
|
||||
|
||||
$this->factory->addWorker($worker);
|
||||
$this->factory->createAsset(array('foo.js', 'bar.js'));
|
||||
}
|
||||
|
||||
public function testWorkerReturn()
|
||||
{
|
||||
$worker = $this->getMock('Assetic\\Factory\\Worker\\WorkerInterface');
|
||||
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
|
||||
|
||||
$worker->expects($this->at(2))
|
||||
->method('process')
|
||||
->with($this->isInstanceOf('Assetic\\Asset\\AssetCollectionInterface'))
|
||||
->will($this->returnValue($asset));
|
||||
|
||||
$this->factory->addWorker($worker);
|
||||
$coll = $this->factory->createAsset(array('foo.js', 'bar.js'));
|
||||
|
||||
$this->assertEquals(1, count(iterator_to_array($coll)));
|
||||
}
|
||||
|
||||
public function testNestedFormula()
|
||||
{
|
||||
$this->fm->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($this->getMock('Assetic\\Filter\\FilterInterface')));
|
||||
|
||||
$inputs = array(
|
||||
'css/main.css',
|
||||
array(
|
||||
// nested formula
|
||||
array('css/more.sass'),
|
||||
array('foo'),
|
||||
),
|
||||
);
|
||||
|
||||
$asset = $this->factory->createAsset($inputs, array(), array('output' => 'css/*.css'));
|
||||
|
||||
$i = 0;
|
||||
foreach ($asset as $leaf) {
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->assertEquals(2, $i);
|
||||
}
|
||||
}
|
96
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/LazyAssetManagerTest.php
vendored
Normal file
96
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/LazyAssetManagerTest.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Factory;
|
||||
|
||||
use Assetic\Factory\LazyAssetManager;
|
||||
|
||||
class LazyAssetManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $factory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->factory = $this->getMockBuilder('Assetic\\Factory\\AssetFactory')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->am = new LazyAssetManager($this->factory);
|
||||
}
|
||||
|
||||
public function testGetFromLoader()
|
||||
{
|
||||
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
|
||||
$loader = $this->getMock('Assetic\\Factory\\Loader\\FormulaLoaderInterface');
|
||||
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
|
||||
|
||||
$formula = array(
|
||||
array('js/core.js', 'js/more.js'),
|
||||
array('?yui_js'),
|
||||
array('output' => 'js/all.js')
|
||||
);
|
||||
|
||||
$loader->expects($this->once())
|
||||
->method('load')
|
||||
->with($resource)
|
||||
->will($this->returnValue(array('foo' => $formula)));
|
||||
$this->factory->expects($this->once())
|
||||
->method('createAsset')
|
||||
->with($formula[0], $formula[1], $formula[2] + array('name' => 'foo'))
|
||||
->will($this->returnValue($asset));
|
||||
|
||||
$this->am->setLoader('foo', $loader);
|
||||
$this->am->addResource($resource, 'foo');
|
||||
|
||||
$this->assertSame($asset, $this->am->get('foo'), '->get() returns an asset from the loader');
|
||||
|
||||
// test the "once" expectations
|
||||
$this->am->get('foo');
|
||||
}
|
||||
|
||||
public function testGetResources()
|
||||
{
|
||||
$resources = array(
|
||||
$this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'),
|
||||
$this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'),
|
||||
);
|
||||
|
||||
$this->am->addResource($resources[0], 'foo');
|
||||
$this->am->addResource($resources[1], 'bar');
|
||||
|
||||
$ret = $this->am->getResources();
|
||||
|
||||
foreach ($resources as $resource) {
|
||||
$this->assertTrue(in_array($resource, $ret, true));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetResourcesEmpty()
|
||||
{
|
||||
$this->am->getResources();
|
||||
}
|
||||
|
||||
public function testSetFormula()
|
||||
{
|
||||
$this->am->setFormula('foo', array());
|
||||
$this->am->load();
|
||||
$this->assertTrue($this->am->hasFormula('foo'), '->load() does not remove manually added formulae');
|
||||
}
|
||||
|
||||
public function testIsDebug()
|
||||
{
|
||||
$this->factory->expects($this->once())
|
||||
->method('isDebug')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertSame(false, $this->am->isDebug(), '->isDebug() proxies the factory');
|
||||
}
|
||||
}
|
138
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Loader/CachedFormulaLoaderTest.php
vendored
Normal file
138
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Loader/CachedFormulaLoaderTest.php
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
<?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\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\Loader\CachedFormulaLoader;
|
||||
|
||||
class CachedFormulaLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $loader;
|
||||
protected $configCache;
|
||||
protected $resource;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->loader = $this->getMock('Assetic\\Factory\\Loader\\FormulaLoaderInterface');
|
||||
$this->configCache = $this->getMockBuilder('Assetic\\Cache\\ConfigCache')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
|
||||
}
|
||||
|
||||
public function testNotDebug()
|
||||
{
|
||||
$expected = array(
|
||||
'foo' => array(array(), array(), array()),
|
||||
'bar' => array(array(), array(), array()),
|
||||
);
|
||||
|
||||
$this->configCache->expects($this->once())
|
||||
->method('has')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue(false));
|
||||
$this->loader->expects($this->once())
|
||||
->method('load')
|
||||
->with($this->resource)
|
||||
->will($this->returnValue($expected));
|
||||
$this->configCache->expects($this->once())
|
||||
->method('set')
|
||||
->with($this->isType('string'), $expected);
|
||||
|
||||
$loader = new CachedFormulaLoader($this->loader, $this->configCache);
|
||||
$this->assertEquals($expected, $loader->load($this->resource), '->load() returns formulae');
|
||||
}
|
||||
|
||||
public function testNotDebugCached()
|
||||
{
|
||||
$expected = array(
|
||||
'foo' => array(array(), array(), array()),
|
||||
'bar' => array(array(), array(), array()),
|
||||
);
|
||||
|
||||
$this->configCache->expects($this->once())
|
||||
->method('has')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue(true));
|
||||
$this->resource->expects($this->never())
|
||||
->method('isFresh');
|
||||
$this->configCache->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue($expected));
|
||||
|
||||
$loader = new CachedFormulaLoader($this->loader, $this->configCache);
|
||||
$this->assertEquals($expected, $loader->load($this->resource), '->load() returns formulae');
|
||||
}
|
||||
|
||||
public function testDebugCached()
|
||||
{
|
||||
$timestamp = 123;
|
||||
$expected = array(
|
||||
'foo' => array(array(), array(), array()),
|
||||
'bar' => array(array(), array(), array()),
|
||||
);
|
||||
|
||||
$this->configCache->expects($this->once())
|
||||
->method('has')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue(true));
|
||||
$this->configCache->expects($this->once())
|
||||
->method('getTimestamp')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue($timestamp));
|
||||
$this->resource->expects($this->once())
|
||||
->method('isFresh')
|
||||
->with($timestamp)
|
||||
->will($this->returnValue(true));
|
||||
$this->loader->expects($this->never())
|
||||
->method('load');
|
||||
$this->configCache->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue($expected));
|
||||
|
||||
$loader = new CachedFormulaLoader($this->loader, $this->configCache, true);
|
||||
$this->assertEquals($expected, $loader->load($this->resource), '->load() returns formulae');
|
||||
}
|
||||
|
||||
public function testDebugCachedStale()
|
||||
{
|
||||
$timestamp = 123;
|
||||
$expected = array(
|
||||
'foo' => array(array(), array(), array()),
|
||||
'bar' => array(array(), array(), array()),
|
||||
);
|
||||
|
||||
$this->configCache->expects($this->once())
|
||||
->method('has')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue(true));
|
||||
$this->configCache->expects($this->once())
|
||||
->method('getTimestamp')
|
||||
->with($this->isType('string'))
|
||||
->will($this->returnValue($timestamp));
|
||||
$this->resource->expects($this->once())
|
||||
->method('isFresh')
|
||||
->with($timestamp)
|
||||
->will($this->returnValue(false));
|
||||
$this->loader->expects($this->once())
|
||||
->method('load')
|
||||
->with($this->resource)
|
||||
->will($this->returnValue($expected));
|
||||
$this->configCache->expects($this->once())
|
||||
->method('set')
|
||||
->with($this->isType('string'), $expected);
|
||||
|
||||
$loader = new CachedFormulaLoader($this->loader, $this->configCache, true);
|
||||
$this->assertEquals($expected, $loader->load($this->resource), '->load() returns formulae');
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
<?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\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Factory\Loader\FunctionCallsFormulaLoader;
|
||||
use Assetic\Factory\Resource\FileResource;
|
||||
|
||||
class FunctionCallsFormulaLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getJavascriptInputs
|
||||
*/
|
||||
public function testInput($function, $inputs, $name, $expected)
|
||||
{
|
||||
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
|
||||
$factory = $this->getMockBuilder('Assetic\\Factory\\AssetFactory')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$resource->expects($this->once())
|
||||
->method('getContent')
|
||||
->will($this->returnValue('<?php '.$function.'('.$inputs.') ?>'));
|
||||
$factory->expects($this->once())
|
||||
->method('generateAssetName')
|
||||
->will($this->returnValue($name));
|
||||
|
||||
$loader = new FunctionCallsFormulaLoader($factory);
|
||||
$formulae = $loader->load($resource);
|
||||
|
||||
$this->assertEquals($expected, $formulae);
|
||||
}
|
||||
|
||||
public function getJavascriptInputs()
|
||||
{
|
||||
return array(
|
||||
array('assetic_javascripts', '"js/core.js"', 'asdf', array('asdf' => array(array('js/core.js'), array(), array('debug' => false, 'output' => 'js/*.js', 'name' => 'asdf', )))),
|
||||
array('assetic_javascripts', "'js/core.js'", 'asdf', array('asdf' => array(array('js/core.js'), array(), array('debug' => false, 'output' => 'js/*.js', 'name' => 'asdf', )))),
|
||||
array('assetic_javascripts', "array('js/core.js')", 'asdf', array('asdf' => array(array('js/core.js'), array(), array('debug' => false, 'output' => 'js/*.js', 'name' => 'asdf', )))),
|
||||
array('assetic_javascripts', 'array("js/core.js")', 'asdf', array('asdf' => array(array('js/core.js'), array(), array('debug' => false, 'output' => 'js/*.js', 'name' => 'asdf', )))),
|
||||
array('assetic_image', '"images/logo.gif"', 'asdf', array('asdf' => array(array('images/logo.gif'), array(), array('debug' => false, 'output' => 'images/*', 'name' => 'asdf')))),
|
||||
);
|
||||
}
|
||||
|
||||
public function testComplexFormula()
|
||||
{
|
||||
$factory = new AssetFactory(__DIR__.'/templates', true);
|
||||
$loader = new FunctionCallsFormulaLoader($factory);
|
||||
$resource = new FileResource(__DIR__.'/templates/debug.php');
|
||||
$formulae = $loader->load($resource);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'test123' => array(
|
||||
array('foo.css', 'bar.css'),
|
||||
array('?foo', 'bar'),
|
||||
array('name' => 'test123', 'output' => 'css/packed.css', 'debug' => true),
|
||||
),
|
||||
), $formulae);
|
||||
}
|
||||
}
|
8
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Loader/templates/debug.php
vendored
Normal file
8
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Loader/templates/debug.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<assets>
|
||||
<?php foreach (assetic_stylesheets(
|
||||
array('foo.css', 'bar.css'),
|
||||
array('?foo', 'bar'),
|
||||
array('name' => 'test123', 'output' => 'css/packed.css', 'debug' => true)) as $url): ?>
|
||||
<asset url="<?php echo $url ?>" />
|
||||
<?php endforeach; ?>
|
||||
</assets>
|
@@ -0,0 +1,42 @@
|
||||
<?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\Factory\Resource;
|
||||
|
||||
use Assetic\Factory\Resource\CoalescingDirectoryResource;
|
||||
use Assetic\Factory\Resource\DirectoryResource;
|
||||
|
||||
class CoalescingDirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function shouldFilterFiles()
|
||||
{
|
||||
// notice only one directory has a trailing slash
|
||||
$resource = new CoalescingDirectoryResource(array(
|
||||
new DirectoryResource(__DIR__.'/Fixtures/dir1/', '/\.txt$/'),
|
||||
new DirectoryResource(__DIR__.'/Fixtures/dir2', '/\.txt$/'),
|
||||
));
|
||||
|
||||
$paths = array();
|
||||
foreach ($resource as $file) {
|
||||
$paths[] = realpath((string) $file);
|
||||
}
|
||||
sort($paths);
|
||||
|
||||
$this->assertEquals(array(
|
||||
realpath(__DIR__.'/Fixtures/dir1/file1.txt'),
|
||||
realpath(__DIR__.'/Fixtures/dir1/file2.txt'),
|
||||
realpath(__DIR__.'/Fixtures/dir2/file3.txt'),
|
||||
), $paths, 'files from multiple directories are merged');
|
||||
}
|
||||
}
|
108
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/DirectoryResourceTest.php
vendored
Normal file
108
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/DirectoryResourceTest.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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\Factory\Resource;
|
||||
|
||||
use Assetic\Factory\Resource\DirectoryResource;
|
||||
|
||||
class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIsFresh()
|
||||
{
|
||||
$resource = new DirectoryResource(__DIR__);
|
||||
$this->assertTrue($resource->isFresh(time() + 5));
|
||||
$this->assertFalse($resource->isFresh(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPatterns
|
||||
*/
|
||||
public function testGetContent($pattern)
|
||||
{
|
||||
$resource = new DirectoryResource(__DIR__, $pattern);
|
||||
$content = $resource->getContent();
|
||||
|
||||
$this->assertInternalType('string', $content);
|
||||
}
|
||||
|
||||
public function getPatterns()
|
||||
{
|
||||
return array(
|
||||
array(null),
|
||||
array('/\.php$/'),
|
||||
array('/\.foo$/'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPatternsAndEmpty
|
||||
*/
|
||||
public function testIteration($pattern, $empty)
|
||||
{
|
||||
$resource = new DirectoryResource(__DIR__, $pattern);
|
||||
|
||||
$count = 0;
|
||||
foreach ($resource as $r) {
|
||||
++$count;
|
||||
$this->assertInstanceOf('Assetic\\Factory\\Resource\\ResourceInterface', $r);
|
||||
}
|
||||
|
||||
if ($empty) {
|
||||
$this->assertEmpty($count);
|
||||
} else {
|
||||
$this->assertNotEmpty($count);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPatternsAndEmpty()
|
||||
{
|
||||
return array(
|
||||
array(null, false),
|
||||
array('/\.php$/', false),
|
||||
array('/\.foo$/', true),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecursiveIteration()
|
||||
{
|
||||
$resource = new DirectoryResource(realpath(__DIR__.'/..'), '/^'.preg_quote(basename(__FILE__)).'$/');
|
||||
|
||||
$count = 0;
|
||||
foreach ($resource as $r) {
|
||||
++$count;
|
||||
}
|
||||
|
||||
$this->assertEquals(1, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPaths
|
||||
*/
|
||||
public function testTrailingSlash($path)
|
||||
{
|
||||
$resource = new DirectoryResource($path);
|
||||
$this->assertStringEndsWith(DIRECTORY_SEPARATOR, (string) $resource, 'path ends with a slash');
|
||||
}
|
||||
|
||||
public function getPaths()
|
||||
{
|
||||
return array(
|
||||
array(__DIR__),
|
||||
array(__DIR__.DIRECTORY_SEPARATOR),
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidDirectory()
|
||||
{
|
||||
$resource = new DirectoryResource(__DIR__.'foo');
|
||||
$this->assertEquals(0, iterator_count($resource), 'works for non-existent directory');
|
||||
}
|
||||
}
|
42
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/FileResourceTest.php
vendored
Normal file
42
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/FileResourceTest.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\Factory\Resource;
|
||||
|
||||
use Assetic\Factory\Resource\FileResource;
|
||||
|
||||
class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIsFresh()
|
||||
{
|
||||
$resource = new FileResource(__FILE__);
|
||||
$this->assertTrue($resource->isFresh(time() + 5));
|
||||
$this->assertFalse($resource->isFresh(0));
|
||||
}
|
||||
|
||||
public function testGetContent()
|
||||
{
|
||||
$resource = new FileResource(__FILE__);
|
||||
$this->assertEquals(file_get_contents(__FILE__), $resource->getContent());
|
||||
}
|
||||
|
||||
public function testIsFreshOnInvalidPath()
|
||||
{
|
||||
$resource = new FileResource(__FILE__.'foo');
|
||||
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the file does not exist');
|
||||
}
|
||||
|
||||
public function testGetContentOnInvalidPath()
|
||||
{
|
||||
$resource = new FileResource(__FILE__.'foo');
|
||||
$this->assertSame('', $resource->getContent(), '->getContent() returns an empty string when path is invalid');
|
||||
}
|
||||
}
|
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir1/file1.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir1/file1.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir1/file2.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir1/file2.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir2/file1.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir2/file1.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir2/file3.txt
vendored
Normal file
0
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Resource/Fixtures/dir2/file3.txt
vendored
Normal file
47
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Worker/EnsureFilterWorkerTest.php
vendored
Normal file
47
vendor/kriswallsmith/assetic/tests/Assetic/Test/Factory/Worker/EnsureFilterWorkerTest.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Factory\Worker;
|
||||
|
||||
use Assetic\Factory\Worker\EnsureFilterWorker;
|
||||
|
||||
class EnsureFilterWorkerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMatch()
|
||||
{
|
||||
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
|
||||
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
|
||||
|
||||
$asset->expects($this->once())
|
||||
->method('getTargetPath')
|
||||
->will($this->returnValue('css/main.css'));
|
||||
$asset->expects($this->once())
|
||||
->method('ensureFilter')
|
||||
->with($filter);
|
||||
|
||||
$worker = new EnsureFilterWorker('/\.css$/', $filter);
|
||||
$worker->process($asset);
|
||||
}
|
||||
|
||||
public function testNonMatch()
|
||||
{
|
||||
$filter = $this->getMock('Assetic\\Filter\\FilterInterface');
|
||||
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
|
||||
|
||||
$asset->expects($this->once())
|
||||
->method('getTargetPath')
|
||||
->will($this->returnValue('js/all.js'));
|
||||
$asset->expects($this->never())->method('ensureFilter');
|
||||
|
||||
$worker = new EnsureFilterWorker('/\.css$/', $filter);
|
||||
$worker->process($asset);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user