You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
11 years ago
|
<?php
|
||
|
/**
|
||
|
* @author Carsten Brandt <mail@cebe.cc>
|
||
|
*/
|
||
|
|
||
|
namespace yiiunit\framework\web;
|
||
11 years ago
|
|
||
10 years ago
|
use yii\helpers\FileHelper;
|
||
11 years ago
|
use yii\web\AssetConverter;
|
||
|
|
||
|
/**
|
||
|
* @group web
|
||
|
*/
|
||
|
class AssetConverterTest extends \yiiunit\TestCase
|
||
|
{
|
||
10 years ago
|
/**
|
||
|
* @var string temporary files path
|
||
|
*/
|
||
|
protected $tmpPath;
|
||
|
|
||
11 years ago
|
protected function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->mockApplication();
|
||
10 years ago
|
$this->tmpPath = \Yii::$app->runtimePath . '/assetConverterTest_' . getmypid();
|
||
|
if (!is_dir($this->tmpPath)) {
|
||
|
mkdir($this->tmpPath, 0777, true);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
protected function tearDown()
|
||
11 years ago
|
{
|
||
10 years ago
|
if (is_dir($this->tmpPath)) {
|
||
|
FileHelper::removeDirectory($this->tmpPath);
|
||
11 years ago
|
}
|
||
10 years ago
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
// Tests :
|
||
|
|
||
|
public function testConvert()
|
||
|
{
|
||
|
$tmpPath = $this->tmpPath;
|
||
11 years ago
|
file_put_contents($tmpPath . '/test.php', <<<EOF
|
||
11 years ago
|
<?php
|
||
|
|
||
|
echo "Hello World!\n";
|
||
|
echo "Hello Yii!";
|
||
|
EOF
|
||
11 years ago
|
);
|
||
11 years ago
|
|
||
11 years ago
|
$converter = new AssetConverter();
|
||
|
$converter->commands['php'] = ['txt', 'php {from} > {to}'];
|
||
|
$this->assertEquals('test.txt', $converter->convert('test.php', $tmpPath));
|
||
11 years ago
|
|
||
11 years ago
|
$this->assertTrue(file_exists($tmpPath . '/test.txt'), 'Failed asserting that asset output file exists.');
|
||
|
$this->assertEquals("Hello World!\nHello Yii!", file_get_contents($tmpPath . '/test.txt'));
|
||
|
}
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @depends testConvert
|
||
|
*/
|
||
|
public function testForceConvert()
|
||
|
{
|
||
|
$tmpPath = $this->tmpPath;
|
||
|
file_put_contents($tmpPath . '/test.php', <<<EOF
|
||
|
<?php
|
||
|
|
||
|
echo microtime();
|
||
|
EOF
|
||
|
);
|
||
|
|
||
|
$converter = new AssetConverter();
|
||
|
$converter->commands['php'] = ['txt', 'php {from} > {to}'];
|
||
|
|
||
|
$converter->convert('test.php', $tmpPath);
|
||
|
$initialConvertTime = file_get_contents($tmpPath . '/test.txt');
|
||
|
|
||
|
usleep(1);
|
||
|
$converter->convert('test.php', $tmpPath);
|
||
|
$this->assertEquals($initialConvertTime, file_get_contents($tmpPath . '/test.txt'));
|
||
|
|
||
|
$converter->forceConvert = true;
|
||
|
$converter->convert('test.php', $tmpPath);
|
||
|
$this->assertNotEquals($initialConvertTime, file_get_contents($tmpPath . '/test.txt'));
|
||
|
}
|
||
11 years ago
|
}
|