Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug volt #1272

Merged
merged 3 commits into from
Sep 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ext/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ PHP_METHOD(Phalcon_Filter, sanitize){
*/
if (Z_TYPE_P(value) == IS_ARRAY && !zend_is_true(norecursive)) {

zend_print_zval(norecursive, 0);
PHALCON_INIT_VAR(sanizited_value);
array_init(sanizited_value);

Expand Down
4 changes: 2 additions & 2 deletions ext/mvc/view/engine/volt/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3449,12 +3449,12 @@ int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_
ZVAL_NULL(result);

if (Z_TYPE_P(view_code) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "View code must be a string");
PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "View code must be a string");
return FAILURE;
}

if (phvolt_internal_parse_view(&result, view_code, template_path, &error_msg TSRMLS_CC) == FAILURE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg));
PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg));
return FAILURE;
}

Expand Down
52 changes: 40 additions & 12 deletions unit-tests/ViewEnginesVoltTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ public function valid()
}
}

function phalcon_prepare_virtual_path($path, $separator) {
$virtual_str = '';

if (!is_string($path) || !is_string($separator)) {
if (is_string($path)) {
return $path;
} else {
return "";
}
}

for ($i = 0; $i < strlen($path); $i++) {
$ch = $path[$i];
if ($ch == '\0') {
break;
}
if ($ch == '/' || $ch == '\\' || $ch == ':') {
$virtual_str .= $separator;
} else {
$virtual_str .= strtolower($ch);
}
}

return $virtual_str;
}

class ViewEnginesVoltTest extends PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -226,7 +252,7 @@ public function testVoltParser()
$this->assertTrue(is_array($intermediate));
$this->assertEquals(count($intermediate), 1);

$intermediate = $volt->parse('{{ --10 }}');
$intermediate = $volt->parse('{{ 10-- }}');
$this->assertTrue(is_array($intermediate));
$this->assertEquals(count($intermediate), 1);

Expand Down Expand Up @@ -549,20 +575,20 @@ public function testVoltSyntaxError()
}

try {
$volt->parse('{{ v++ }}');
$volt->parse('{{ ++v }}');
$this->assertTrue(false);
}
catch(Phalcon\Mvc\View\Exception $e){
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token + in eval code on line 1');
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token ++ in eval code on line 1');
}

try {
$volt->parse('{{
v++ }}');
++v }}');
$this->assertTrue(false);
}
catch(Phalcon\Mvc\View\Exception $e){
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token + in eval code on line 2');
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token ++ in eval code on line 2');
}

try {
Expand Down Expand Up @@ -604,7 +630,7 @@ public function testVoltSyntaxError()
$this->assertTrue(false);
}
catch(Phalcon\Mvc\View\Exception $e){
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token + in eval code on line 8');
$this->assertEquals($e->getMessage(), 'Syntax error, unexpected token IDENTIFIER(y) in eval code on line 8');
}

try {
Expand All @@ -626,7 +652,7 @@ public function testVoltSyntaxError()
$this->assertTrue(false);
}
catch(Phalcon\Mvc\View\Exception $e){
$this->assertEquals($e->getMessage(), "Parsing error before 'album.uri, \"<img...' in eval code on line 1");
$this->assertEquals($e->getMessage(), "Scanning error before 'album.uri, \"<img...' in eval code on line 1");
}

}
Expand Down Expand Up @@ -1012,13 +1038,13 @@ public function testVoltCompiler()
$this->assertEquals($compilation, '<?php foreach (array(0, 1, 3, 5, 4) as $key => $value) { ?> hello <?php } ?>');

$compilation = $volt->compileString('{% for key, value in [0, 1, 3, 5, 4] if key!=3 %} hello {% endfor %}');
$this->assertEquals($compilation, '<?php foreach (array(0, 1, 3, 5, 4) as $key => $value) { if ($key != 3) { ?> hello <?php } } ?>');
$this->assertEquals($compilation, '<?php foreach (array(0, 1, 3, 5, 4) as $key => $value) { if ($key != 3) { ?> hello <?php } ?><?php } ?>');

$compilation = $volt->compileString('{% for a in 1..10 %} hello {% endfor %}');
$this->assertEquals($compilation, '<?php foreach (range(1, 10) as $a) { ?> hello <?php } ?>');

$compilation = $volt->compileString('{% for a in 1..10 if a is even %} hello {% endfor %}');
$this->assertEquals($compilation, '<?php foreach (range(1, 10) as $a) { if (((($a) % 2) == 0)) { ?> hello <?php } } ?>');
$this->assertEquals($compilation, '<?php foreach (range(1, 10) as $a) { if (((($a) % 2) == 0)) { ?> hello <?php } ?><?php } ?>');

$compilation = $volt->compileString('{% for a in 1..10 %} {% for b in 1..10 %} hello {% endfor %} {% endfor %}');
$this->assertEquals($compilation, '<?php foreach (range(1, 10) as $a) { ?> <?php foreach (range(1, 10) as $b) { ?> hello <?php } ?> <?php } ?>');
Expand Down Expand Up @@ -1067,7 +1093,7 @@ public function testVoltUsersFunctions()
$volt = new \Phalcon\Mvc\View\Engine\Volt\Compiler();

//Single string function
$volt->addFunction('random', 'mt_rand()');
$volt->addFunction('random', 'mt_rand');

//Function with closure
$volt->addFunction('shuffle', function($arguments, $exprArguments){
Expand Down Expand Up @@ -1238,8 +1264,10 @@ public function testVoltCompilerFileOptions()
$volt->render('unit-tests/views/test10/index.volt', array('song' => 'Lights'), true);
$view->finish();

$this->assertTrue(file_exists('unit-tests/cache/unit-tests.views.test10.index.volt.compiled'));
$this->assertEquals(file_get_contents('unit-tests/cache/unit-tests.views.test10.index.volt.compiled'), 'Hello <?php echo $song; ?>!');
$path = 'unit-tests/cache/'.phalcon_prepare_virtual_path(realpath("unit-tests/"), ".").'.views.test10.index.volt.compiled';

$this->assertTrue(file_exists($path));
$this->assertEquals(file_get_contents($path), 'Hello <?php echo $song; ?>!');
$this->assertEquals($view->getContent(), 'Hello Lights!');

}
Expand Down