diff --git a/.gitignore b/.gitignore
index 7579f74..eb02d2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
vendor
composer.lock
+.phpunit.cache/
+tools-libs/
diff --git a/.phive/phars.xml b/.phive/phars.xml
new file mode 100644
index 0000000..da47c6c
--- /dev/null
+++ b/.phive/phars.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/ReadMe.md b/ReadMe.md
index 7882e28..9c691df 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -47,6 +47,33 @@ Alternative setup composer local zip file repot:
1) Update and leep the label/pos changes
5) Create new release version as official relase number
+## Test
+
+After any update run `tools/phpunit` to test the compare output, also a visual check can be done by accessing the `test/` folder
+
+- Translations should work
+- pos/label names for checkbox/options should work
+- get var output should work
+- plugin test load should work
+
+### For intelephense users when phpunit was installed as phar
+
+Intelephense cannot directly access the phar file, if phpunit was installed as a phar file (eg via phive) then the following commands must be used to setup the intelephense parser
+
+In the base folder:
+
+```sh
+php -r "(new Phar('/path/to/phive/folder/.phive/phars/phpunit-10.3.5.phar'))->extractTo('tools-libs/phpunit');"
+```
+
+Then open the vscode settings and set for the Folder (if multiple folders are in the workspace) or the Workspace the following setting
+
+```txt
+"intelephense.environment.includePaths": [
+ "/tools-libs/phpunit/"
+]
+```
+
## Updated files (different from master)
### New
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..42d9c68
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,14 @@
+
+
+
+
+ test
+
+
+
diff --git a/src/Template.php b/src/Template.php
index 242fb23..b2a732e 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -154,6 +154,7 @@ class Template extends TemplateBase {
if ($this->smarty->debugging) {
$this->smarty->getDebug()->start_template($this, $display);
}
+ // exit;
// checks if template exists
if ($this->compile_check && !$this->getSource()->exists) {
throw new Exception(
diff --git a/test/SmartyExtendedTest.php b/test/SmartyExtendedTest.php
new file mode 100644
index 0000000..c42c033
--- /dev/null
+++ b/test/SmartyExtendedTest.php
@@ -0,0 +1,258 @@
+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 = <<
+
+
+ Smarty v5 tst
+
+
+
+
+ BASE: /storage/var/www/html/developers/clemens/core_data/composer-packages/Smarty-Extended/test/
+
+
+ SMARTY_TEST: Test Data
+
+
+ TEST INSTALL
+
+
+ MERGE DATA:
+
+ This is a test for Smarty 5
+
+ POPUP HERE (hover mouse)
+
+
+ POPUP PLUGIN HERE (hover mouse)
+
+
+ Outside translation test
+ TRANSLATION CLASS (OUT): Are we translated?
+ TRANSLATION CLASS (OUT FUNCTION): Are we translated?
+ TRANSLATION CLASS (SMARTY): Are we translated?
+
+
+ Translate Test with replace:
+ ORIGINAL: Original with string: %1 (Replaced)
+ TRANSLATED: Translated with string: Replaced
+ TRANSLATED (escape): Translated with string: on
+ Capture test: INPUT TEST
+ Plural test 0: multi
+ Plural test 1: single
+ Plural test 2: multi
+
+
+ Plugin Test:
+ ORIGINAL: Original with string: %1 (Replaced)
+ TRANSLATED: Translated with string: Replaced
+
+
+ Variable variables:
+ Test: foo
+ Foo: bar
+ vFoo (\$test = \$foo = bar): bar
+ vFoo (\$bar = \$test = foo): foo
+
+
+
+
+ Some content here or asdfasdfasf
+
+
+ TRANSLATION SMARTY: I should be translated
+
+
+
+
LOOP TEST
+
LOOP OUTPUT: 1
+
LOOP OUTPUT: 2
+
LOOP OUTPUT: 3
+
LOOP OUTPUT: 4
+
LOOP OUTPUT: 5
+
+
+
+ Foo
+ Bar
+ Foo Bar
+
+
+
+
+
+ 選択してください
+
+ 4/25(木) 11:00-11:50
+ 4/25(木) 12:20-13:00
+
+
+ 4/26(金) 11:00-11:50
+ 4/26(金) 12:20-13:00
+
+
+ 4/27(土) 11:00-11:50
+ 4/27(土) 12:20-13:00
+
+
+
+
+
+ On
+ Off
+ Undefined
+
+
+ On
+ Off
+ Undefined
+
+
+ On
+ Off
+ Undefined
+
+
+
+
+
+
+ HTML;
+
+ $this->assertEquals(
+ $compare_smarty_compiled,
+ trim($smarty->fetch(
+ $template_name,
+ $CACHE_ID,
+ $COMPILE_ID
+ ))
+ );
+ }
+}
+
+// __END__
diff --git a/test/bootstrap.php b/test/bootstrap.php
new file mode 100644
index 0000000..8a7789d
--- /dev/null
+++ b/test/bootstrap.php
@@ -0,0 +1,15 @@
+ $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,
diff --git a/tools/phpunit b/tools/phpunit
new file mode 120000
index 0000000..f1897d5
--- /dev/null
+++ b/tools/phpunit
@@ -0,0 +1 @@
+/home/clemens/.phive/phars/phpunit-10.3.5.phar
\ No newline at end of file