ViewRendererTest.php 1.5 KB
Newer Older
1 2
<?php
/**
3 4
 *
 *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * @author Carsten Brandt <mail@cebe.cc>
 */

namespace yiiunit\extensions\smarty;

use yii\web\AssetManager;
use yii\web\View;
use Yii;
use yiiunit\TestCase;

/**
 * @group smarty
 */
class ViewRendererTest extends TestCase
{
20 21 22 23
    protected function setUp()
    {
        $this->mockApplication();
    }
24

25 26 27 28 29 30 31
    /**
     * https://github.com/yiisoft/yii2/issues/2265
     */
    public function testNoParams()
    {
        $view = $this->mockView();
        $content = $view->renderFile('@yiiunit/extensions/smarty/views/simple.tpl');
32

33 34
        $this->assertEquals('simple view without parameters.', $content);
    }
35

36 37 38 39
    public function testRender()
    {
        $view = $this->mockView();
        $content = $view->renderFile('@yiiunit/extensions/smarty/views/view.tpl', ['param' => 'Hello World!']);
40

41 42
        $this->assertEquals('test view Hello World!.', $content);
    }
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57
    /**
     * @return View
     */
    protected function mockView()
    {
        return new View([
            'renderers' => [
                'tpl' => [
                    'class' => 'yii\smarty\ViewRenderer',
                ],
            ],
            'assetManager' => $this->mockAssetManager(),
        ]);
    }
58

59 60 61 62 63 64 65 66 67 68 69 70
    protected function mockAssetManager()
    {
        $assetDir = Yii::getAlias('@runtime/assets');
        if (!is_dir($assetDir)) {
            mkdir($assetDir, 0777, true);
        }

        return new AssetManager([
            'basePath' => $assetDir,
            'baseUrl' => '/assets',
        ]);
    }
AlexGx committed
71
}