259 lines
8.5 KiB
PHP
259 lines
8.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Test class for Smarty
|
|
* @coversDefaultClass \Smarty
|
|
* @testdox \Smarty method tests for extended smarty plugins
|
|
*/
|
|
final class SmartyExtendedTest extends TestCase
|
|
{
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @testdox Output\Form\Elements Class tests
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testSmartyExtended()
|
|
{
|
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
|
$locale = 'ja_JP.UTF-8';
|
|
$domain = 'frontend';
|
|
$locale_path = BASE . 'includes/locale/';
|
|
$encoding = 'UTF-8';
|
|
$l10n = new \CoreLibs\Language\L10n(
|
|
$locale,
|
|
$domain,
|
|
$locale_path,
|
|
$encoding
|
|
);
|
|
$locale = $l10n->getLocaleAsArray();
|
|
\CoreLibs\Language\L10n::loadFunctions();
|
|
_setlocale(LC_MESSAGES, $locale['locale']);
|
|
_textdomain($locale['domain']);
|
|
_bindtextdomain($locale['domain'], $locale['path']);
|
|
_bind_textdomain_codeset($locale['domain'], $locale['encoding']);
|
|
|
|
$template_name = "test.full.tpl";
|
|
$CACHE_ID = 'SmartyV5PHPUnit';
|
|
$COMPILE_ID = 'SmartyV5PHPUnit';
|
|
$CONTENT_DATA = [
|
|
'BASE' => BASE,
|
|
// 'TEST_INSTALL' => $smarty->testInstall(),
|
|
'HTML_TITLE' => 'Smarty v5 tst',
|
|
// smarty test
|
|
'SMARTY_TEST' => 'Test Data',
|
|
'TRANSLATE_TEST' => $l10n->__('Are we translated?'),
|
|
'TRANSLATE_TEST_FUNCTION' => _gettext('Are we translated?'),
|
|
'TRANSLATE_TEST_SMARTY' => $l10n->__('Are we translated?'),
|
|
'replace' => 'Replaced',
|
|
// variable variables
|
|
'test' => 'foo',
|
|
'foo' => 'bar',
|
|
// loop
|
|
'loop_start' => 5,
|
|
// drop down test with optgroups
|
|
'drop_down_test' => [
|
|
'foo' => 'Foo',
|
|
'bar' => 'Bar',
|
|
'foobar' => 'Foo Bar',
|
|
],
|
|
'drop_down_test_selected' => 'bar',
|
|
'drop_down_test_nested' => [
|
|
'' => '選択してください',
|
|
'4/25(木)' => [
|
|
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
|
'4/25(木) 12:20-13:00' => '4/25(木) 12:20-13:00'
|
|
],
|
|
'4/26(金)' => [
|
|
'4/26(金) 11:00-11:50' => '4/26(金) 11:00-11:50',
|
|
'4/26(金) 12:20-13:00' => '4/26(金) 12:20-13:00'
|
|
],
|
|
'4/27(土)' => [
|
|
'4/27(土) 11:00-11:50' => '4/27(土) 11:00-11:50',
|
|
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
|
],
|
|
],
|
|
'drop_down_test_nested_selected' => '',
|
|
'radio_test' => [
|
|
'0' => 'On',
|
|
'1' => 'Off',
|
|
'-1' => 'Undefined'
|
|
],
|
|
'radio_test_selected' => -1,
|
|
'checkbox_test' => [
|
|
'0' => 'On',
|
|
'1' => 'Off',
|
|
'-1' => 'Undefined'
|
|
],
|
|
'checkbox_test_pos' => [
|
|
'0' => 'A',
|
|
'1' => 'B'
|
|
],
|
|
'checkbox_test_selected' => ['1', '-1'],
|
|
'checkbox_test_pos_selected' => ['0', '-1'],
|
|
];
|
|
|
|
$smarty = new \Smarty\Smarty();
|
|
$smarty->setTemplateDir(BASE . 'includes/templates/frontend');
|
|
$smarty->setConfigDir(BASE . 'configs');
|
|
$smarty->setCompileDir(BASE . 'templates_c');
|
|
$smarty->setCacheDir(BASE . 'cache');
|
|
|
|
$smarty->setEscapeHtml(true);
|
|
// get var test
|
|
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$smarty, 'getTemplateVars']);
|
|
// for testing plugin tyoes
|
|
require 'plugins/block.t.php';
|
|
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'tp', 'smarty_block_t');
|
|
require 'plugins/function.popup_init.php';
|
|
require 'plugins/function.popup.php';
|
|
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'popinit', 'smarty_function_popup_init');
|
|
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'pop', 'smarty_function_popup');
|
|
|
|
foreach ($CONTENT_DATA as $key => $value) {
|
|
$smarty->assign($key, $value);
|
|
}
|
|
|
|
// the data as it should look like
|
|
// base created by running the index.php and copy the data from the tmp folder for the template
|
|
// eg "test.full.tpl" is "tmp/test.full.tpl.html"
|
|
$compare_smarty_compiled = <<<HTML
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>Smarty v5 tst</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=">
|
|
<script type="text/javascript" language="JavaScript" src="./js/overlib/overlib.js"></script>
|
|
</head>
|
|
<body>
|
|
BASE: /storage/var/www/html/developers/clemens/core_data/composer-packages/Smarty-Extended/test/<br>
|
|
<hr>
|
|
<div>
|
|
SMARTY_TEST: Test Data
|
|
</div>
|
|
<div>
|
|
TEST INSTALL
|
|
</div>
|
|
<div>
|
|
MERGE DATA:
|
|
</div>
|
|
<div onmouseover="return overlib('Text block<br>Control<br>SMARTY 5',WIDTH,250,CAPTION,'Info v5',BGCOLOR,'#ece86d',FGCOLOR,'#ecb96d',CAPCOLOR,'black');" onmouseout="nd();">This is a test for Smarty 5</div>
|
|
<div onmouseover="return overlib('Text block<br>Control',WIDTH,250,CAPTION,'Info');" onmouseout="nd();" style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
|
|
POPUP HERE (hover mouse)
|
|
</div>
|
|
<div onmouseover="return overlib('Text block<br>Control<br>Plugin',WIDTH,250,CAPTION,'Info');" onmouseout="nd();" style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
|
|
POPUP PLUGIN HERE (hover mouse)
|
|
</div>
|
|
<div>
|
|
<b>Outside translation test</b><br>
|
|
TRANSLATION CLASS (OUT): Are we translated?<br>
|
|
TRANSLATION CLASS (OUT FUNCTION): Are we translated?<br>
|
|
TRANSLATION CLASS (SMARTY): Are we translated?<br>
|
|
</div>
|
|
<div>
|
|
<b>Translate Test with replace:</b><br>
|
|
ORIGINAL: Original with string: %1 (Replaced)<br>
|
|
TRANSLATED: Translated with string: Replaced<br>
|
|
TRANSLATED (escape): Translated with string: on<br>
|
|
Capture test: INPUT TEST<br>
|
|
Plural test 0: multi<br>
|
|
Plural test 1: single<br>
|
|
Plural test 2: multi<br>
|
|
</div>
|
|
<div>
|
|
<b>Plugin Test:</b><br>
|
|
ORIGINAL: Original with string: %1 (Replaced)<br>
|
|
TRANSLATED: Translated with string: Replaced<br>
|
|
</div>
|
|
<div>
|
|
<b>Variable variables:</b><br>
|
|
Test: foo<br>
|
|
Foo: bar<br>
|
|
vFoo (\$test = \$foo = bar): bar<br>
|
|
vFoo (\$bar = \$test = foo): foo
|
|
</div>
|
|
<div class="jq-container">
|
|
<div id="jq-test" class="jp-test">
|
|
<div id="test-div" class="test-div">
|
|
Some content here or asdfasdfasf
|
|
</div>
|
|
<div id="translate-div">
|
|
TRANSLATION SMARTY: I should be translated </div>
|
|
</div>
|
|
</div>
|
|
<div class="loop-test">
|
|
<div><b>LOOP TEST</b></div>
|
|
<div>LOOP OUTPUT: 1</div>
|
|
<div>LOOP OUTPUT: 2</div>
|
|
<div>LOOP OUTPUT: 3</div>
|
|
<div>LOOP OUTPUT: 4</div>
|
|
<div>LOOP OUTPUT: 5</div>
|
|
</div>
|
|
<div>
|
|
<select id="drop_down_test" name="drop_down_test">
|
|
<option label="Foo" value="foo">Foo</option>
|
|
<option label="Bar" value="bar" selected="selected">Bar</option>
|
|
<option label="Foo Bar" value="foobar">Foo Bar</option>
|
|
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
|
<option label="選択してください" value="" selected="selected">選択してください</option>
|
|
<optgroup label="4/25(木)">
|
|
<option label="4/25(木) 11:00-11:50" value="4/25(木) 11:00-11:50">4/25(木) 11:00-11:50</option>
|
|
<option label="4/25(木) 12:20-13:00" value="4/25(木) 12:20-13:00">4/25(木) 12:20-13:00</option>
|
|
</optgroup>
|
|
<optgroup label="4/26(金)">
|
|
<option label="4/26(金) 11:00-11:50" value="4/26(金) 11:00-11:50">4/26(金) 11:00-11:50</option>
|
|
<option label="4/26(金) 12:20-13:00" value="4/26(金) 12:20-13:00">4/26(金) 12:20-13:00</option>
|
|
</optgroup>
|
|
<optgroup label="4/27(土)">
|
|
<option label="4/27(土) 11:00-11:50" value="4/27(土) 11:00-11:50">4/27(土) 11:00-11:50</option>
|
|
<option label="4/27(土) 12:20-13:00" value="4/27(土) 12:20-13:00">4/27(土) 12:20-13:00</option>
|
|
</optgroup>
|
|
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label><input type="radio" name="radio_test" value="0" />On</label>
|
|
<label><input type="radio" name="radio_test" value="1" />Off</label>
|
|
<label><input type="radio" name="radio_test" value="-1" checked="checked" />Undefined</label>
|
|
</div>
|
|
<div>
|
|
<label><input type="checkbox" name="checkbox_test[]" value="0" />On</label>
|
|
<label><input type="checkbox" name="checkbox_test[]" value="1" checked="checked" />Off</label>
|
|
<label><input type="checkbox" name="checkbox_test[]" value="-1" checked="checked" />Undefined</label>
|
|
</div>
|
|
<div>
|
|
<label><input type="checkbox" name="checkbox_test_pos[]" value="0" checked="checked" />On</label>
|
|
<label><input type="checkbox" name="checkbox_test_pos[]" value="1" />Off</label>
|
|
<label><input type="checkbox" name="checkbox_test_pos[]" value="-1" checked="checked" />Undefined</label>
|
|
</div>
|
|
<div>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|
|
HTML;
|
|
|
|
$this->assertEquals(
|
|
$compare_smarty_compiled,
|
|
trim($smarty->fetch(
|
|
$template_name,
|
|
$CACHE_ID,
|
|
$COMPILE_ID
|
|
))
|
|
);
|
|
}
|
|
}
|
|
|
|
// __END__
|