Commit aedfef1e by Carsten Brandt

added tests for smarty and worked around a small bug

fixes #2265
parent cd07a416
...@@ -79,7 +79,8 @@ ...@@ -79,7 +79,8 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",
"twig/twig": "*" "twig/twig": "*",
"smarty/smarty": "*"
}, },
"suggest": { "suggest": {
"phpdocumentor/reflection": "required by yii2-apidoc extension", "phpdocumentor/reflection": "required by yii2-apidoc extension",
...@@ -92,6 +93,7 @@ ...@@ -92,6 +93,7 @@
"imagine/imagine": "required by yii2-imagine extension", "imagine/imagine": "required by yii2-imagine extension",
"smarty/smarty": "required by yii2-smarty extension", "smarty/smarty": "required by yii2-smarty extension",
"swiftmailer/swiftmailer": "required by yii2-swiftmailer extension", "swiftmailer/swiftmailer": "required by yii2-swiftmailer extension",
"twig/twig": "required by yii2-twig extension",
"yiisoft/yii2-coding-standards": "you can use this package to check for code style issues when contributing to yii" "yiisoft/yii2-coding-standards": "you can use this package to check for code style issues when contributing to yii"
}, },
"autoload": { "autoload": {
......
...@@ -88,7 +88,7 @@ class ViewRenderer extends BaseViewRenderer ...@@ -88,7 +88,7 @@ class ViewRenderer extends BaseViewRenderer
public function render($view, $file, $params) public function render($view, $file, $params)
{ {
/** @var \Smarty_Internal_Template $template */ /** @var \Smarty_Internal_Template $template */
$template = $this->smarty->createTemplate($file, null, null, $params, true); $template = $this->smarty->createTemplate($file, null, null, empty($params) ? null : $params, true);
$template->assign('app', \Yii::$app); $template->assign('app', \Yii::$app);
$template->assign('this', $view); $template->assign('this', $view);
......
<?php
/**
*
*
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace yiiunit\extensions\smarty;
use yii\web\AssetManager;
use yii\web\JqueryAsset;
use yii\web\View;
use Yii;
use yiiunit\TestCase;
/**
* @group smarty
*/
class ViewRendererTest extends TestCase
{
protected function setUp()
{
$this->mockApplication();
}
/**
* https://github.com/yiisoft/yii2/issues/2265
*/
public function testNoParams()
{
$view = $this->mockView();
$content = $view->renderFile('@yiiunit/extensions/smarty/views/simple.tpl');
$this->assertEquals('simple view without parameters.', $content);
}
public function testRender()
{
$view = $this->mockView();
$content = $view->renderFile('@yiiunit/extensions/smarty/views/view.tpl', ['param' => 'Hello World!']);
$this->assertEquals('test view Hello World!.', $content);
}
/**
* @return View
*/
protected function mockView()
{
return new View([
'renderers' => [
'tpl' => [
'class' => 'yii\smarty\ViewRenderer',
],
],
'assetManager' => $this->mockAssetManager(),
]);
}
protected function mockAssetManager()
{
$assetDir = Yii::getAlias('@runtime/assets');
if (!is_dir($assetDir)) {
mkdir($assetDir, 0777, true);
}
return new AssetManager([
'basePath' => $assetDir,
'baseUrl' => '/assets',
]);
}
}
\ No newline at end of file
simple view without parameters.
\ No newline at end of file
test view {$param}.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment