Blame view
sources/3rdparty/kriswallsmith/assetic/tests/Assetic/Test/AssetWriterTest.php
4.58 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2014 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;
use Assetic\Asset\FileAsset;
use Assetic\AssetManager;
use Assetic\AssetWriter;
class AssetWriterTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->dir = sys_get_temp_dir().'/assetic_tests_'.rand(11111, 99999);
mkdir($this->dir);
$this->writer = new AssetWriter($this->dir, array(
'locale' => array('en', 'de', 'fr'),
'browser' => array('ie', 'firefox', 'other'),
'gzip' => array('gzip', '')
));
}
protected function tearDown()
{
array_map('unlink', glob($this->dir.'/*'));
rmdir($this->dir);
}
public function testWriteManagerAssets()
{
$asset = $this->getMock('Assetic\\Asset\\AssetInterface');
$am = $this->getMock('Assetic\\AssetManager');
$am->expects($this->once())
->method('getNames')
->will($this->returnValue(array('foo')));
$am->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($asset));
$asset->expects($this->atLeastOnce())
->method('getTargetPath')
->will($this->returnValue('target_url'));
$asset->expects($this->once())
->method('dump')
->will($this->returnValue('content'));
$asset->expects($this->atLeastOnce())
->method('getVars')
->will($this->returnValue(array()));
$asset->expects($this->atLeastOnce())
->method('getValues')
->will($this->returnValue(array()));
$this->writer->writeManagerAssets($am);
$this->assertFileExists($this->dir.'/target_url');
$this->assertEquals('content', file_get_contents($this->dir.'/target_url'));
}
public function testWriteAssetWithVars()
{
$asset = $this->getMock('Assetic\Asset\AssetInterface');
$asset->expects($this->atLeastOnce())
->method('getVars')
->will($this->returnValue(array('locale')));
$self = $this;
$expectedValues = array(
array('locale' => 'en'),
array('locale' => 'de'),
array('locale' => 'fr'),
);
$asset->expects($this->exactly(3))
->method('setValues')
->will($this->returnCallback(function($values) use ($self, $expectedValues) {
static $counter = 0;
$self->assertEquals($expectedValues[$counter++], $values);
}));
$asset->expects($this->exactly(3))
->method('getValues')
->will($this->returnCallback(function() use ($expectedValues) {
static $counter = 0;
return $expectedValues[$counter++];
}));
$asset->expects($this->exactly(3))
->method('dump')
->will($this->onConsecutiveCalls('en', 'de', 'fr'));
$asset->expects($this->atLeastOnce())
->method('getTargetPath')
->will($this->returnValue('target.{locale}'));
$this->writer->writeAsset($asset);
$this->assertFileExists($this->dir.'/target.en');
$this->assertFileExists($this->dir.'/target.de');
$this->assertFileExists($this->dir.'/target.fr');
$this->assertEquals('en', file_get_contents($this->dir.'/target.en'));
$this->assertEquals('de', file_get_contents($this->dir.'/target.de'));
$this->assertEquals('fr', file_get_contents($this->dir.'/target.fr'));
}
public function testAssetWithInputVars()
{
$asset = new FileAsset(__DIR__.'/Fixture/messages.{locale}.js',
array(), null, null, array('locale'));
$asset->setTargetPath('messages.{locale}.js');
$this->writer->writeAsset($asset);
$this->assertFileExists($this->dir.'/messages.en.js');
$this->assertFileExists($this->dir.'/messages.de.js');
$this->assertFileExists($this->dir.'/messages.fr.js');
$this->assertEquals('var messages = {"text.greeting": "Hello %name%!"};',
file_get_contents($this->dir.'/messages.en.js'));
$this->assertEquals('var messages = {"text.greeting": "Hallo %name%!"};',
file_get_contents($this->dir.'/messages.de.js'));
$this->assertEquals('var messages = {"text.greet": "All\u00f4 %name%!"};',
file_get_contents($this->dir.'/messages.fr.js'));
}
}
|