Skip to content
Snippets Groups Projects
Commit cb41013e authored by Øyvind gjesdal's avatar Øyvind gjesdal
Browse files

add Haanga test changes

parent f70295eb
No related branches found
No related tags found
1 merge request!1Resolve "Ta inn endringer fra skeivt arkiv lodspeakr"
File added
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-07-03 16:17+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#:
msgid "hello"
msgstr "hola"
#: assert_templates/trans.tpl:1 assert_templates/trans.tpl:1
msgid "Translation"
msgstr "Traducción"
#: assert_templates/trans.tpl:2 assert_templates/trans.tpl:2
#, c-format
msgid "Translation by %s"
msgstr "Traducción por %s"
foo
foo
FOO
FOO
bar
BAR
{{ Object.method }}
{{ Object.method() }}
{{ Object.method|upper }}
{{ Object.method()|upper }}
{{ Object.bar }}
{{ Object.bar|upper }}
hi I'm 5 !
Hola
hi I'm 5 !
hi I'm 5 !
<?php
$data = array('b' => 3);
hi I'm {{ 1+1+b }} !
{{ "hola"|title}}
hi I'm {{ 1+1+b|title }} !
hi I'm {{ 1 > 2 ? 4 : 5 }} !
......@@ -5,9 +5,11 @@ if (!is_callable('bindtextdomain')) {
throw new Exception('no gettext enabled');
}
$locale='es_ES.UTF-8';
$locale='en_US.utf8';
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
if (!setlocale(LC_ALL, $locale)) {
throw new Exception('no gettext enabled');
}
bindtextdomain("messages", dirname(__FILE__)."/locale");
bindtextdomain("messages", dirname(__FILE__) . "/locale");
textdomain("messages");
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = array(
'cache_dir' => __DIR__ . '/tmp/',
'autoload' => true,
'template_dir' => __DIR__,
'debug' => TRUE,
'use_hash_filename' => FALSE,
'compiler' => array(
'allow_exec' => TRUE,
'global' => array('test_global', 'global1'),
)
);
Haanga::Configure($config);
date_default_timezone_set('UTC');
@mkdir(__DIR__ . "/tmp/");
foreach (glob(__DIR__ . "/tmp/*/*") as $file) {
@unlink($file);
}
......@@ -9,9 +9,8 @@ class errorTest extends PHPUnit_Framework_TestCase
* @dataProvider tplProvider
*
*/
function testInvalidTemplates($tpl)
public function testInvalidTemplates($tpl)
{
TestSuite::init();
Haanga_Compiler::setOption('allow_exec', FALSE);
try {
Haanga::Load($tpl);
......@@ -22,11 +21,11 @@ class errorTest extends PHPUnit_Framework_TestCase
}
}
public function tplProvider()
public static function tplProvider()
{
$datas = array();
foreach (glob("err_templates/*.tpl") as $err_file) {
$datas[] = array($err_file);
foreach (glob(__DIR__ . "/err_templates/*.tpl") as $err_file) {
$datas[] = array(substr($err_file, strlen(__DIR__)));
}
return $datas;
......
......@@ -25,19 +25,10 @@ class Foo_Bar {
*/
class templateTest extends PHPUnit_Framework_TestCase
{
public function testInit()
{
/* setup */
@mkdir("tmp/");
foreach (glob("tmp/*/*") as $file) {
@unlink($file);
}
TestSuite::init();
}
public function init($test_file, &$expected)
{
if ($test_file == 'assert_templates/strip_whitespace.tpl') {
Haanga_Compiler::setOption('allow_exec', true);
if ($test_file === '/assert_templates/strip_whitespace.tpl') {
Haanga_Compiler::setOption('strip_whitespace', TRUE);
$expected = rtrim($expected). ' '; /* weird output */
} else {
......@@ -52,6 +43,7 @@ class templateTest extends PHPUnit_Framework_TestCase
$this->init($test_file, $expected);
$output = Haanga::Load($test_file, $data, TRUE);
$this->assertEquals($output, $expected);
$this->assertTrue(filemtime(__DIR__ . $test_file) <= filemtime(__DIR__ . '/tmp/assert_templates/' . basename($test_file) . '.php'));
}
/**
......@@ -59,8 +51,9 @@ class templateTest extends PHPUnit_Framework_TestCase
*/
public function testLambda($test_file, $data, $expected)
{
chdir(dirname(__DIR__ . '/' . $test_file));
$this->init($test_file, $expected);
$callback = Haanga::compile(file_get_contents($test_file), $data);
$callback = Haanga::compile(file_get_contents(__DIR__ . $test_file), $data);
$output = $callback($data);
$this->assertEquals($output, $expected);
}
......@@ -78,37 +71,14 @@ class templateTest extends PHPUnit_Framework_TestCase
$this->assertFalse(Haanga::$has_compiled);
}
/**
* @dataProvider tplProvider
* /
public function testCLICompiler($test_file, $data, $expected)
{
TestSuite::init();
$GLOBALS['argv'][1] = $test_file;
$GLOBALS['argv'][2] = '--notags';
ob_start();
Haanga_Compiler::main_cli();
$code = ob_get_clean();
eval($code);
$file = basename($test_file);
$pos = strpos($file,'.');
$function = substr($file, 0, $pos).'_template';
$output = call_user_func($function, $data, TRUE);
$this->assertEquals($output, $expected);
}
/* */
public function tplProvider()
public static function tplProvider()
{
$datas = array();
foreach (glob("assert_templates/*.tpl") as $test_file) {
foreach (glob(__DIR__ . "/assert_templates/*.tpl") as $test_file) {
$data = array();
$data_file = substr($test_file, 0, -3)."php";
$expected = substr($test_file, 0, -3)."html";
$test_file = substr($test_file, strlen(__DIR__));
if (!is_file($expected)) {
if (!is_file($expected.".php")) {
continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment