Fix tests for translations, where missing in the po/mo files Add original and post translation for compare for outside and inside smarty translation Update documentation and only keep the git update path, the others are deprecated Update phpunit to v11 and update tests according to this, including updated test template data file Add the tools folder to git ignore
283 lines
9.1 KiB
PHP
283 lines
9.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
/**
|
|
* Test class for Smarty
|
|
* @coversDefaultClass \Smarty
|
|
*/
|
|
#[TestDox("\Smarty method tests for extended smarty plugins")]
|
|
#[CoversClass(\Smarty\Smarty::class)]
|
|
final class SmartyExtendedTest extends TestCase
|
|
{
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @return void
|
|
*/
|
|
#[Test]
|
|
#[TestDox("Test Smarty Extended rendering")]
|
|
public function testSmartyExtended(): void
|
|
{
|
|
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',
|
|
'TRANSLATED_ORIGINAL' => 'Are we translated?',
|
|
'TRANSLATED_REPLACED' => 'Yes, we are translated!',
|
|
'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>
|
|
TRANSLATED ORIGINAL: Are we translated?<br>
|
|
TRANSLATED REPLACED: Yes, we are translated!<br>
|
|
TRANSLATION CLASS (OUT): Yes, we are translated!<br>
|
|
TRANSLATION CLASS (OUT FUNCTION): Yes, we are translated!<br>
|
|
TRANSLATION CLASS (SMARTY): Yes, we are translated!<br>
|
|
</div>
|
|
<div>
|
|
<b>Translate Test with replace:</b><br>
|
|
ORIGINAL: Original with string: %1 (Replaced)<br>
|
|
TRANSLATED: Translated 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>
|
|
Drop Down simple
|
|
</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>
|
|
Drop Down nested
|
|
</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>
|
|
radio plain
|
|
</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>
|
|
checkbox plain
|
|
</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>
|
|
checkbox pos
|
|
</div>
|
|
<div>
|
|
<label><input type="checkbox" name="checkbox_test_pos[A]" value="0" checked="checked" />On</label>
|
|
<label><input type="checkbox" name="checkbox_test_pos[B]" 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__
|