Fix strip_tags modifier for falsy input. (#893)

Fixes #890
This commit is contained in:
Simon Wisselink
2023-08-04 22:40:19 +02:00
committed by GitHub
parent 1d9cda2be3
commit a3cbdc46fb
3 changed files with 50 additions and 1 deletions
@@ -0,0 +1,46 @@
<?php
/**
* Smarty PHPunit tests of modifier
*/
namespace UnitTests\TemplateSource\TagTests\PluginModifier;
use PHPUnit_Smarty;
/**
* class for modifier tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginModifierStripTagsTest extends PHPUnit_Smarty {
public function setUp(): void {
$this->setUpSmarty(__DIR__);
}
public function testDefault() {
$tpl = $this->smarty->createTemplate('string:{$x|strip_tags}');
$tpl->assign('x', '<b>hi</b>');
$this->assertEquals(" hi ", $this->smarty->fetch($tpl));
}
public function testParam1() {
$tpl = $this->smarty->createTemplate('string:{$x|strip_tags:false}');
$tpl->assign('x', '<b>hi</b>');
$this->assertEquals("hi", $this->smarty->fetch($tpl));
}
public function testInputIsFalsy0() {
$tpl = $this->smarty->createTemplate('string:{$x|strip_tags}');
$tpl->assign('x', 0);
$this->assertEquals("0", $this->smarty->fetch($tpl));
}
public function testInputIsFalsy1() {
$tpl = $this->smarty->createTemplate('string:{$x|strip_tags}');
$tpl->assign('x', '');
$this->assertEquals("", $this->smarty->fetch($tpl));
}
}