-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'support/4.3' into warn_when_using_unregistered_function
- Loading branch information
Showing
22 changed files
with
344 additions
and
11 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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Upgrading from an older version | ||
|
||
## Upgrading from v3 to v4 | ||
|
||
Smarty 4 is mostly identical to Smarty 3. Most notably, it adds support for PHP8 and drops support for PHP7.0 and below. | ||
Additionally, some deprecated features that have long been discouraged have been dropped from the language. | ||
|
||
### Muting PHP8 warnings | ||
If you simultaneously upgrade Smarty to v4 van PHP to v8, you may notice your error logs filling up with warnings about undefined or null template vars | ||
due to a change in how PHP handles these. This may be helpful to spot errors, but if you find this annoying, you can use | ||
`$smarty->muteUndefinedOrNullWarnings()` to make Smarty convert these warnings into notices. | ||
|
||
### ASP tags | ||
You can no longer user ASP-style tags like `<% %>` and `<%= %>` in your templates. | ||
Replace them with `{...}` tags. | ||
|
||
### SmartyBC | ||
Check your codebase for `SmartyBC`. | ||
We have dropped deprecated API calls that where only accessible through the SmartyBC class. | ||
|
||
### No more embedded PHP | ||
We have completely dropped support for `{php}` and `{include_php}` tags and embedded PHP in templates. | ||
Check your templates for this, and rewrite any embedded PHP blocks, by moving logic to your PHP files or by | ||
creating a [plugin function](./programmers/plugins/plugins-functions.md). | ||
|
||
### Other changes | ||
|
||
Search your code for the following changes: | ||
|
||
- `SMARTY_RESOURCE_CHAR_SET` and `SMARTY_RESOURCE_DATE_FORMAT` constants have been removed | ||
- `Smarty::muteExpectedErrors` and `Smarty::unmuteExpectedErrors` API methods have been removed | ||
- `Smarty::getVariable` method has been removed. Use [Smarty::getTemplateVars](programmers/api-functions/api-get-template-vars.md) instead. | ||
- [Smarty::registerResource](programmers/api-functions/api-register-resource.md) no longer accepts an array of callback functions | ||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* Smarty plugin | ||
* | ||
* @package Smarty | ||
* @subpackage PluginsModifier | ||
*/ | ||
|
||
function smarty_modifier_implode($values, $separator = '') | ||
{ | ||
if (is_array($separator)) { | ||
return implode((string) ($values ?? ''), (array) $separator); | ||
} | ||
return implode((string) ($separator ?? ''), (array) $values); | ||
} |
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,11 @@ | ||
<?php | ||
|
||
/** | ||
* Smarty plugin | ||
* | ||
* @package Smarty | ||
* @subpackage PluginsModifierCompiler | ||
*/ | ||
function smarty_modifiercompiler_json_encode($params) { | ||
return 'json_encode(' . $params[0] . (isset($params[1]) ? ', (int) ' . $params[1] : '') . ')'; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
/** | ||
* Smarty plugin | ||
* | ||
* @package Smarty | ||
* @subpackage PluginsModifierCompiler | ||
*/ | ||
function smarty_modifiercompiler_substr($params) { | ||
return 'substr((string) ' . $params[0] . ', (int) ' . $params[1] . | ||
(isset($params[2]) ? ', (int) ' . $params[2] : '') . ')'; | ||
} |
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
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
44 changes: 44 additions & 0 deletions
44
tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierImplodeTest.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,44 @@ | ||
<?php | ||
/** | ||
* Smarty PHPunit tests of modifier | ||
*/ | ||
|
||
/** | ||
* class for modifier tests | ||
* | ||
* @runTestsInSeparateProcess | ||
* @preserveGlobalState disabled | ||
* @backupStaticAttributes enabled | ||
*/ | ||
class PluginModifierImplodeTest extends PHPUnit_Smarty | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->setUpSmarty(__DIR__); | ||
} | ||
|
||
public function testDefault() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{""|implode:$v}'); | ||
$tpl->assign("v", ["1", "2"]); | ||
$this->assertEquals("12", $this->smarty->fetch($tpl)); | ||
} | ||
public function testWithSeparator() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{","|implode:$v}'); | ||
$tpl->assign("v", ["a", "b"]); | ||
$this->assertEquals("a,b", $this->smarty->fetch($tpl)); | ||
} | ||
public function testInConditional() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{if implode("", $v) == "abc"}good{else}bad{/if}'); | ||
$tpl->assign("v", ['a','b','c']); | ||
$this->assertEquals("good", $this->smarty->fetch($tpl)); | ||
} | ||
public function testInConditionalWithSeparator() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{if implode("-", $v) == "a-b-c"}good{else}bad{/if}'); | ||
$tpl->assign("v", ['a','b','c']); | ||
$this->assertEquals("good", $this->smarty->fetch($tpl)); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierJsonEncodeTest.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,76 @@ | ||
<?php | ||
/** | ||
* Smarty PHPunit tests of modifier | ||
*/ | ||
|
||
/** | ||
* class for modifier tests | ||
* | ||
* @runTestsInSeparateProcess | ||
* @preserveGlobalState disabled | ||
* @backupStaticAttributes enabled | ||
*/ | ||
class PluginModifierJsonEncodeTest extends PHPUnit_Smarty | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->setUpSmarty(__DIR__); | ||
} | ||
|
||
/** | ||
* @dataProvider dataForDefault | ||
*/ | ||
public function testDefault($value, $expected) | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{$v|json_encode}'); | ||
$tpl->assign("v", $value); | ||
$this->assertEquals($expected, $this->smarty->fetch($tpl)); | ||
} | ||
|
||
/** | ||
* @dataProvider dataForDefault | ||
*/ | ||
public function testDefaultAsFunction($value, $expected) | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{json_encode($v)}'); | ||
$tpl->assign("v", $value); | ||
$this->assertEquals($expected, $this->smarty->fetch($tpl)); | ||
} | ||
|
||
public function dataForDefault() { | ||
return [ | ||
["abc", '"abc"'], | ||
[["abc"], '["abc"]'], | ||
[["abc",["a"=>2]], '["abc",{"a":2}]'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataForForceObject | ||
*/ | ||
public function testForceObject($value, $expected) | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{$v|json_encode:16}'); | ||
$tpl->assign("v", $value); | ||
$this->assertEquals($expected, $this->smarty->fetch($tpl)); | ||
} | ||
|
||
/** | ||
* @dataProvider dataForForceObject | ||
*/ | ||
public function testForceObjectAsFunction($value, $expected) | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{json_encode($v,16)}'); | ||
$tpl->assign("v", $value); | ||
$this->assertEquals($expected, $this->smarty->fetch($tpl)); | ||
} | ||
|
||
public function dataForForceObject() { | ||
return [ | ||
["abc", '"abc"'], | ||
[["abc"], '{"0":"abc"}'], | ||
[["abc",["a"=>2]], '{"0":"abc","1":{"a":2}}'], | ||
]; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierSubstrTest.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,48 @@ | ||
<?php | ||
/** | ||
* Smarty PHPunit tests of modifier | ||
*/ | ||
|
||
/** | ||
* class for modifier tests | ||
* | ||
* @runTestsInSeparateProcess | ||
* @preserveGlobalState disabled | ||
* @backupStaticAttributes enabled | ||
*/ | ||
class PluginModifierSubstrTest extends PHPUnit_Smarty | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->setUpSmarty(__DIR__); | ||
} | ||
|
||
public function testDefault() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{$v|substr:1}'); | ||
$tpl->assign("v", "abc"); | ||
$this->assertEquals("bc", $this->smarty->fetch($tpl)); | ||
} | ||
|
||
public function testTwoArguments() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{$v|substr:1:1}'); | ||
$tpl->assign("v", "abc"); | ||
$this->assertEquals("b", $this->smarty->fetch($tpl)); | ||
} | ||
|
||
public function testNegativeOffset() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{$v|substr:-1}'); | ||
$tpl->assign("v", "abc"); | ||
$this->assertEquals("c", $this->smarty->fetch($tpl)); | ||
} | ||
|
||
public function testInConditional() | ||
{ | ||
$tpl = $this->smarty->createTemplate('string:{if substr($v, -1) == "c"}good{else}bad{/if}'); | ||
$tpl->assign("v", "abc"); | ||
$this->assertEquals("good", $this->smarty->fetch($tpl)); | ||
} | ||
|
||
} |
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,10 @@ | ||
FROM php:8.3-cli | ||
|
||
## Basic utilities | ||
RUN apt-get update -yqq && apt-get install -y curl apt-utils git zip unzip | ||
|
||
## Composer | ||
COPY ./utilities/testrunners/shared/install-composer.sh /root/install-composer.sh | ||
WORKDIR /root | ||
RUN sh ./install-composer.sh | ||
RUN mv ./composer.phar /usr/local/bin/composer |
Oops, something went wrong.