-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-issue-549-v3' of github.com:AnrDaemon/smarty into A…
…nrDaemon-fix-issue-549-v3
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
tests/UnitTests/TemplateSource/_Issues/549/MbSplitEncodingIssue549Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\"}")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore anything in here, but keep this directory | ||
* |
2 changes: 2 additions & 0 deletions
2
tests/UnitTests/TemplateSource/_Issues/549/templates_c/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore anything in here, but keep this directory | ||
* |