Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 22, 2024
1 parent f6f5fb3 commit c793536
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/_data/views/filters/default.volt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ robot.price|default(10.0) }}
1 change: 1 addition & 0 deletions tests/_data/views/filters/default_json_encode.volt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ preparedParams|default([])|json_encode }}
3 changes: 3 additions & 0 deletions tests/_data/views/layouts/compiler.volt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if some_eval %}
Clearly, the song is: {{ content() }}.
{% endif %}
81 changes: 81 additions & 0 deletions tests/unit/Compiler/CompileFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Compiler;

use Phalcon\Volt\Compiler;
use PHPUnit\Framework\TestCase;

class CompileFileTest extends TestCase
{
public static function defaultFilterProvider(): array
{
return [
[
'default',
"<?= (empty(\$robot->price) ? (10.0) : (\$robot->price)) ?>\n",
],

[
'default_json_encode',
"<?= json_encode((empty(\$preparedParams) ? ([]) : (\$preparedParams))) ?>\n",
],
];
}

/**
* Tests Phalcon\Mvc\View\Engine\Volt\Compiler :: compileFile()
*
* @author Phalcon Team <[email protected]>
* @since 2017-01-17
*/
public function testMvcViewEngineVoltCompilerCompileFile(): void
{
$viewFile = 'tests/_data/views/layouts/compiler.volt';
$compileFile = $viewFile . 'compiler.volt.php';

$expected = '<?php if ($some_eval) { ?>
Clearly, the song is: <?= $this->getContent() ?>.
<?php } ?>';

$volt = new Compiler();

$volt->compileFile($viewFile, $compileFile);
$this->assertEquals($expected, file_get_contents($compileFile));

unlink($compileFile);
}

/**
* Tests Phalcon\Mvc\View\Engine\Volt\Compiler :: compileFile()
*
* @issue https://github.com/phalcon/cphalcon/issues/13242
*
* @author Phalcon Team <[email protected]>
* @since 2018-11-13
*
* @dataProvider defaultFilterProvider
*/
public function testMvcViewEngineVoltCompilerCompileFileDefaultFilter(
string $view,
string $expected
): void {
$viewFile = sprintf('tests/_data/views/filters/%s.volt', $view);
$compiledFile = $viewFile . '.php';

$volt = new Compiler();
$volt->compileFile($viewFile, $compiledFile);
$this->assertEquals($expected, file_get_contents($compiledFile));
//unlink($compiledFile);
}
}

0 comments on commit c793536

Please sign in to comment.