summaryrefslogtreecommitdiff
path: root/tests/UnitTests
diff options
context:
space:
mode:
authorSimon Wisselink <wisskid@users.noreply.github.com>2022-07-19 22:55:07 +0200
committerGitHub <noreply@github.com>2022-07-19 22:55:07 +0200
commit20a8026ccd6970432a789dfe2941655b4d7e2617 (patch)
tree820b4ffb68d094cd2f34702149888cde1c1cdb6a /tests/UnitTests
parent27910bf2c1ee69e14eeaa54585cd2f9ccce7e38b (diff)
downloadsmarty-20a8026ccd6970432a789dfe2941655b4d7e2617.tar.gz
smarty-20a8026ccd6970432a789dfe2941655b4d7e2617.tar.bz2
smarty-20a8026ccd6970432a789dfe2941655b4d7e2617.zip
Merge branch 'fix-issue-549-v3' of github.com:AnrDaemon/smarty into AnrDaemon-fix-issue-549-v3 (#771)
Diffstat (limited to 'tests/UnitTests')
-rw-r--r--tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php1
-rw-r--r--tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php77
-rw-r--r--tests/UnitTests/TemplateSource/_Issues/549/cache/.gitignore2
-rw-r--r--tests/UnitTests/TemplateSource/_Issues/549/templates_c/.gitignore2
4 files changed, 82 insertions, 0 deletions
diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php
index 84e74bb8..26ea6faa 100644
--- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php
+++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlSelectDateTest.php
@@ -210,6 +210,7 @@ class PluginFunctionHtmlSelectDateTest extends PHPUnit_Smarty
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
+ $this->smarty->setErrorReporting(E_ALL & ~E_DEPRECATED);
$year = date('Y');
$this->now = mktime(15, 0, 0, 2, 20, $year);
diff --git a/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php b/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php
new file mode 100644
index 00000000..aafef311
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Smarty PHPunit tests - issue #549 regression tests
+ *
+ * @package PHPunit
+ * @author Andrey Repin <anrdaemon@yandex.ru>
+ */
+
+/**
+ * class for compiler tests
+ *
+ * @runTestsInSeparateProcess
+ * @preserveGlobalState disabled
+ * @backupStaticAttributes enabled
+ *
+ * mb_split breaks if Smarty encoding is not the same as mbstring regex encoding.
+ */
+class MbSplitEncodingIssue549Test extends PHPUnit_Smarty
+{
+ /** @var string Saved Smarty charset */
+ private $charset;
+
+ /** @var array Source data for tests, hexed to protect from accidental reencoding */
+ private $data = array(
+ "subject" => '4772c3bc6e6577616c64', // "Grünewald"
+ "pattern" => '77616c64', // "wald"
+ "replacement" => '7374c3bc726d', // "stürm"
+ "result" => '4772c3bc6e657374c3bc726d', // "Grünestürm"
+ );
+
+ public function setUp(): void
+ {
+ if(!\Smarty::$_MBSTRING)
+ {
+ $this->markTestSkipped("mbstring extension is not in use by Smarty");
+ }
+
+ $this->charset = \Smarty::$_CHARSET;
+ $this->setUpSmarty(dirname(__FILE__));
+ }
+
+ protected function tearDown(): void
+ {
+ \Smarty::$_CHARSET = $this->charset ?: \Smarty::$_CHARSET;
+ $this->cleanDirs();
+ }
+
+ /** Provider for testReplaceModifier
+ */
+ public function encodingPairsProvider()
+ {
+ return array(
+ "with non-UNICODE src/non-UNICODE regex (PHP < 5.6 default)" => array("Windows-1252", "EUC-JP"),
+ "with UTF-8 src/non-UNICODE regex (PHP < 5.6 default)" => array("UTF-8", "EUC-JP"),
+ "with UTF-8 src/UTF-8 regex (PHP >= 5.6)" => array("UTF-8", "UTF-8"),
+ "with non-UNICODE src/UTF-8 regex" => array("Windows-1252", "UTF-8"),
+ );
+ }
+
+ /** Test behavior of `replace` modifier with different source and regex encodings
+ *
+ * @dataProvider encodingPairsProvider
+ */
+ public function testReplaceModifier($mb_int_encoding, $mb_regex_encoding)
+ {
+ $data = $this->data;
+ \array_walk($data, function(&$value, $key) use($mb_int_encoding) {
+ $value = \mb_convert_encoding(pack("H*", $value), $mb_int_encoding, "UTF-8");
+ });
+ \extract($data, \EXTR_SKIP);
+
+ \mb_regex_encoding($mb_regex_encoding);
+ \Smarty::$_CHARSET = $mb_int_encoding;
+ $this->assertEquals($result, $this->smarty->fetch("string:{\"$subject\"|replace:\"$pattern\":\"$replacement\"}"));
+ }
+
+}
diff --git a/tests/UnitTests/TemplateSource/_Issues/549/cache/.gitignore b/tests/UnitTests/TemplateSource/_Issues/549/cache/.gitignore
new file mode 100644
index 00000000..d88cc144
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/_Issues/549/cache/.gitignore
@@ -0,0 +1,2 @@
+# Ignore anything in here, but keep this directory
+*
diff --git a/tests/UnitTests/TemplateSource/_Issues/549/templates_c/.gitignore b/tests/UnitTests/TemplateSource/_Issues/549/templates_c/.gitignore
new file mode 100644
index 00000000..d88cc144
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/_Issues/549/templates_c/.gitignore
@@ -0,0 +1,2 @@
+# Ignore anything in here, but keep this directory
+*