mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 09:24:28 +02:00
Cleaned up the unit test
This commit is contained in:
@@ -231,79 +231,70 @@ class PhpFunctionTest extends PHPUnit_Smarty
|
|||||||
return 'hi ' . $value;
|
return 'hi ' . $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that each function that will still be supported in Smarty 5 does NOT throw an E_USER_DEPRECATED notice.
|
|
||||||
* @dataProvider dataSupportedInSmarty5
|
|
||||||
*/
|
|
||||||
public function testSupportedInSmarty5($strTemplateSource, $expected) {
|
|
||||||
$this->cleanDirs();
|
|
||||||
$this->smarty->setErrorReporting(E_ALL);
|
|
||||||
$this->smarty->assign('a', 'a');
|
|
||||||
$this->smarty->assign('ar', [1,2]);
|
|
||||||
$this->smarty->assign('f', 3.14);
|
|
||||||
$output = $this->smarty->fetch('string:' . $strTemplateSource);
|
|
||||||
$this->assertEquals($expected, $output);
|
|
||||||
$this->assertStringNotContainsString('Deprecated', $output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataSupportedInSmarty5()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
['{if empty($a)}{else}b{/if}', 'b'],
|
|
||||||
['{json_encode($a)}', '"a"'],
|
|
||||||
['{nl2br($a)}', 'a'],
|
|
||||||
['{$a|nl2br}', 'a'],
|
|
||||||
['{round($f, 1)}', '3.1'],
|
|
||||||
['{$f|round}', '3'],
|
|
||||||
['{str_repeat($a, 2)}', 'aa'],
|
|
||||||
['{$a|str_repeat:3}', 'aaa'],
|
|
||||||
['{$a|strip_tags}', 'a'],
|
|
||||||
['{$a|strlen}', '1'],
|
|
||||||
['{$a|substr:-1}', 'a'],
|
|
||||||
['{$f|substr:-1}', '4'],
|
|
||||||
['{$ar|count}', '2'],
|
|
||||||
['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314'],
|
|
||||||
['{"-"|implode:$ar}', '1-2'],
|
|
||||||
['{"-"|join:$ar}', '1-2'],
|
|
||||||
['{$f|wordwrap:2:"k":true}', "3.k14"],
|
|
||||||
['{$f|number_format:1:","}', "3,1"],
|
|
||||||
['{if in_array(1, $ar)}yes{/if}', "yes"],
|
|
||||||
['{if is_array($ar)}yes{/if}', "yes"],
|
|
||||||
['{if time() gt 0}yes{/if}', "yes"],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that each function that will not be supported in Smarty 5 does throw an E_USER_DEPRECATED notice.
|
* Tests that each function that will not be supported in Smarty 5 does throw an E_USER_DEPRECATED notice.
|
||||||
* @dataProvider dataNotSupportedInSmarty5
|
* @dataProvider dataDeprecationNoticesForSmarty5
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public function testNotSupportedInSmarty5($strTemplateSource) {
|
public function testDeprecationNoticesForSmarty5($strTemplateSource, $expected = '', $shouldTriggerDeprecationNotice = false) {
|
||||||
$this->cleanDirs();
|
|
||||||
$this->smarty->setErrorReporting(E_ALL);
|
// this overrides the error reporting level set in \PHPUnit_Smarty::setUpSmarty
|
||||||
|
$previousErrorReporting = $this->smarty->error_reporting;
|
||||||
|
$this->smarty->setErrorReporting($previousErrorReporting | E_USER_DEPRECATED);
|
||||||
|
|
||||||
$this->smarty->assign('a', 'a');
|
$this->smarty->assign('a', 'a');
|
||||||
$this->smarty->assign('ar', [1,2]);
|
$this->smarty->assign('ar', [1,2]);
|
||||||
$this->smarty->assign('f', 3.14);
|
$this->smarty->assign('f', 3.14);
|
||||||
|
|
||||||
|
$errorMessage = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->smarty->fetch('string:' . $strTemplateSource);
|
$output = $this->smarty->fetch('string:' . $strTemplateSource);
|
||||||
$this->assertTrue(false); // we should not reach this
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->assertStringContainsString('Using unregistered function', $e->getMessage());
|
$errorMessage = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($shouldTriggerDeprecationNotice) {
|
||||||
|
$this->assertStringContainsString('Using unregistered function', $errorMessage);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals($expected, $output);
|
||||||
|
$this->assertEquals('', $errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->smarty->setErrorReporting($previousErrorReporting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataNotSupportedInSmarty5()
|
public function dataDeprecationNoticesForSmarty5()
|
||||||
{
|
{
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['{if array_chunk($ar, 2)}x{else}y{/if}'],
|
|
||||||
['{$a|addslashes}'],
|
['{if empty($a)}{else}b{/if}', 'b', false],
|
||||||
['{$a|sha1}'],
|
['{json_encode($a)}', '"a"', false],
|
||||||
['{$a|get_parent_class}'],
|
['{nl2br($a)}', 'a', false],
|
||||||
|
['{$a|nl2br}', 'a', false],
|
||||||
|
['{round($f, 1)}', '3.1', false],
|
||||||
|
['{$f|round}', '3', false],
|
||||||
|
['{str_repeat($a, 2)}', 'aa', false],
|
||||||
|
['{$a|str_repeat:3}', 'aaa', false],
|
||||||
|
['{$a|strip_tags}', 'a', false],
|
||||||
|
['{$a|strlen}', '1', false],
|
||||||
|
['{$a|substr:-1}', 'a', false],
|
||||||
|
['{$f|substr:-1}', '4', false],
|
||||||
|
['{$ar|count}', '2', false],
|
||||||
|
['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314', false],
|
||||||
|
['{"-"|implode:$ar}', '1-2', false],
|
||||||
|
['{"-"|join:$ar}', '1-2', false],
|
||||||
|
['{$f|wordwrap:2:"k":true}', "3.k14", false],
|
||||||
|
['{$f|number_format:1:","}', "3,1", false],
|
||||||
|
['{if in_array(1, $ar)}yes{/if}', "yes", false],
|
||||||
|
['{if is_array($ar)}yes{/if}', "yes", false],
|
||||||
|
['{if time() gt 0}yes{/if}', "yes", false],
|
||||||
|
|
||||||
|
['{if array_chunk($ar, 2)}x{else}y{/if}', '', true],
|
||||||
|
['{$a|addslashes}', '', true],
|
||||||
|
['{$a|sha1}', '', true],
|
||||||
|
['{$a|get_parent_class}', '', true],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user