修正block标签嵌套不能解析的问题,改进对未定义变量输出的判断

This commit is contained in:
oldrind
2016-06-28 10:14:50 +08:00
parent 9ca4911c44
commit ab1ee18364
2 changed files with 31 additions and 24 deletions

View File

@@ -78,7 +78,7 @@ EOF;
{\$name.a==\$name.b?='test'}
EOF;
$data = <<<EOF
<?php if(\$name['a']==\$name['b']) echo 'test'; ?>
<?php if(!empty(\$name['a']) && \$name['a']==\$name['b']) echo 'test'; ?>
EOF;
$template->parse($content);
@@ -88,7 +88,7 @@ EOF;
{\$name.a==\$name.b?'a':'b'}
EOF;
$data = <<<EOF
<?php echo (\$name['a']==\$name['b'])?'a':'b'; ?>
<?php echo !empty(\$name['a']) && \$name['a']==\$name['b']?'a':'b'; ?>
EOF;
$template->parse($content);
@@ -98,7 +98,7 @@ EOF;
{\$name.a|default='test'==\$name.b?'a':'b'}
EOF;
$data = <<<EOF
<?php echo ((isset(\$name['a']) && (\$name['a'] !== '')?\$name['a']:'test')==\$name['b'])?'a':'b'; ?>
<?php echo (isset(\$name['a']) && (\$name['a'] !== '')?\$name['a']:'test')==\$name['b']?'a':'b'; ?>
EOF;
$template->parse($content);
@@ -210,7 +210,7 @@ EOF;
<#\$info.a??'test'#>
EOF;
$data = <<<EOF
<?php echo (is_array(\$info)?\$info['a']:\$info->a) ? (is_array(\$info)?\$info['a']:\$info->a) : 'test'; ?>
<?php echo ((is_array(\$info)?\$info['a']:\$info->a)) ? (is_array(\$info)?\$info['a']:\$info->a) : 'test'; ?>
EOF;
$template->parse($content);
@@ -326,7 +326,7 @@ EOF;
];
$data = ['name' => 'value'];
$template->layout('layout')->fetch('display', $data, $config);
$this->expectOutputString('value');
$this->expectOutputString('<div>value</div>');
}
public function testDisplay()
@@ -407,7 +407,7 @@ EOF;
public function testIsCache()
{
$template = new Template(['cache_id' => '__CACHE_ID__', 'display_cache' => true]);
$this->assertTrue(!$template->isCache('__CACHE_ID__'));
$this->assertTrue($template->isCache('__CACHE_ID__'));
$template->display_cache = false;
$this->assertTrue(!$template->isCache('__CACHE_ID__'));
}