Files
Smarty-Extended/test/index.php
Clemens Schwaighofer 856a88d891 Update to Smarty 5.7.0
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
2026-01-07 10:06:39 +09:00

147 lines
3.8 KiB
PHP

<?php // phpcs:ignore PSR1.Files.SideEffects
/**
* AUTOR: Clemens Schwaighofer
* CREATED: 2024/7/22
* DESCRIPTION:
* Smarty 5 Test: Just base call
*/
declare(strict_types=1);
require "../vendor/autoload.php";
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
# public \CoreLibs\Language\L10n $l10n;
$locale = 'ja_JP.UTF-8';
$domain = 'frontend';
$locale_path = 'includes/locale/';
$encoding = 'UTF-8';
$l10n = new \CoreLibs\Language\L10n(
$locale,
$domain,
$locale_path,
$encoding
);
// $smarty_ml = new \CoreLibs\Template\SmartyExtend($l10n, 'Smarty5TestCache', 'Smarty5TestCompile');
// $smarty_ml->setTemplateDir('includes/templates/frontend');
// $smarty_ml->setConfigDir('configs');
// $smarty_ml->setCompileDir('templates_c');
// $smarty_ml->setCacheDir('cache');
// $smarty_ml->setSmartyPaths();
// $smarty_ml->setSmartyVarsFrontend();
// $smarty_ml->renderSmarty();
$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";
// $template_name = "test.simple.tpl";
$CACHE_ID = 'SmartyV5Test';
$COMPILE_ID = 'SmartyV5Test';
// $smarty = \Smarty::__construct();
$smarty = new \Smarty\Smarty();
$smarty->setTemplateDir('includes/templates/frontend');
$smarty->setConfigDir('configs');
$smarty->setCompileDir('templates_c');
$smarty->setCacheDir('cache');
$smarty->setEscapeHtml(true);
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$smarty, 'getTemplateVars']);
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');
// $smarty->testInstall();
$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'],
];
foreach ($CONTENT_DATA as $key => $value) {
$smarty->assign($key, $value);
}
file_put_contents('tmp/' . $template_name . '.html', $smarty->fetch(
$template_name,
$CACHE_ID,
$COMPILE_ID
));
// write to display
$smarty->display(
$template_name,
$CACHE_ID,
$COMPILE_ID
);
// __END__