AssetConverterTest.php 1.01 KB
Newer Older
1 2 3 4 5 6
<?php
/**
 * @author Carsten Brandt <mail@cebe.cc>
 */

namespace yiiunit\framework\web;
AlexGx committed
7

8 9 10 11 12 13 14
use yii\web\AssetConverter;

/**
 * @group web
 */
class AssetConverterTest extends \yiiunit\TestCase
{
15 16 17 18 19 20 21 22 23 24 25 26 27
    protected function setUp()
    {
        parent::setUp();
        $this->mockApplication();
    }

    public function testConvert()
    {
        $tmpPath = \Yii::$app->runtimePath . '/assetConverterTest';
        if (!is_dir($tmpPath)) {
            mkdir($tmpPath, 0777, true);
        }
        file_put_contents($tmpPath . '/test.php', <<<EOF
28 29 30 31 32
<?php

echo "Hello World!\n";
echo "Hello Yii!";
EOF
33
        );
34

35 36 37
        $converter = new AssetConverter();
        $converter->commands['php'] = ['txt', 'php {from} > {to}'];
        $this->assertEquals('test.txt', $converter->convert('test.php', $tmpPath));
38

39 40 41
        $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'));
    }
AlexGx committed
42
}