mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 02:14:26 +02:00
Fixed unit tests for removed deprecated code in previous commit
This commit is contained in:
@@ -1,121 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Smarty PHPunit tests of filter
|
|
||||||
*
|
|
||||||
* @package PHPunit
|
|
||||||
* @author Rodney Rehm
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class for filter tests
|
|
||||||
*
|
|
||||||
* @runTestsInSeparateProcess
|
|
||||||
* @preserveGlobalState disabled
|
|
||||||
* @backupStaticAttributes enabled
|
|
||||||
*/
|
|
||||||
class MuteExpectedErrorsTest extends PHPUnit_Smarty
|
|
||||||
{
|
|
||||||
protected $_errors = array();
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->setUpSmarty(dirname(__FILE__));
|
|
||||||
set_error_handler(array($this, 'error_handler'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void {
|
|
||||||
restore_error_handler();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInit()
|
|
||||||
{
|
|
||||||
$this->cleanDirs();
|
|
||||||
}
|
|
||||||
public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = array())
|
|
||||||
{
|
|
||||||
$this->_errors[] = $errfile . ' line ' . $errline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMuted()
|
|
||||||
{
|
|
||||||
|
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
|
|
||||||
$this->smarty->clearCache('default.tpl');
|
|
||||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
|
||||||
$this->smarty->fetch('default.tpl');
|
|
||||||
|
|
||||||
$this->assertEquals($this->_errors, array());
|
|
||||||
|
|
||||||
@filemtime('ckxladanwijicajscaslyxck');
|
|
||||||
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
|
|
||||||
$this->assertEquals($this->_errors, $error);
|
|
||||||
|
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @rrunInSeparateProcess
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function testUnmuted()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->smarty->clearCache('default.tpl');
|
|
||||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
|
||||||
$this->smarty->fetch('default.tpl');
|
|
||||||
|
|
||||||
$this->assertEquals($this->_errors, array());
|
|
||||||
|
|
||||||
@filemtime('ckxladanwijicajscaslyxck');
|
|
||||||
$this->assertEquals(1, count($this->_errors));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @runInSeparateProcess
|
|
||||||
* @preserveGlobalState disabled
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function testMutedCaching()
|
|
||||||
{
|
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
|
|
||||||
$this->smarty->caching = true;
|
|
||||||
$this->smarty->clearCache('default.tpl');
|
|
||||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
|
||||||
$this->smarty->fetch('default.tpl');
|
|
||||||
|
|
||||||
$this->assertEquals($this->_errors, array());
|
|
||||||
|
|
||||||
@filemtime('ckxladanwijicajscaslyxck');
|
|
||||||
$error = array(__FILE__ . ' line ' . (__LINE__ - 1));
|
|
||||||
$this->assertEquals($error, $this->_errors);
|
|
||||||
|
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @runInSeparateProcess
|
|
||||||
* @preserveGlobalState disabled
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function testUnmutedCaching()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->smarty->caching = true;
|
|
||||||
$this->smarty->clearCache('default.tpl');
|
|
||||||
$this->smarty->clearCompiledTemplate('default.tpl');
|
|
||||||
$this->smarty->fetch('default.tpl');
|
|
||||||
|
|
||||||
$this->assertEquals($this->_errors, array());
|
|
||||||
|
|
||||||
@filemtime('ckxladanwijicajscaslyxck');
|
|
||||||
$this->assertEquals(1, count($this->_errors));
|
|
||||||
|
|
||||||
restore_error_handler();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,2 +0,0 @@
|
|||||||
# Ignore anything in here, but keep this directory
|
|
||||||
*
|
|
@@ -1 +0,0 @@
|
|||||||
{$foo|default:""} /* should compile something with @silence error suppression */
|
|
@@ -1,2 +0,0 @@
|
|||||||
# Ignore anything in here, but keep this directory
|
|
||||||
*
|
|
@@ -20,10 +20,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
|||||||
{
|
{
|
||||||
$this->setUpSmarty(dirname(__FILE__));
|
$this->setUpSmarty(dirname(__FILE__));
|
||||||
|
|
||||||
$this->smarty->registerResource("rr", array("rr_get_template",
|
$this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1());
|
||||||
"rr_get_timestamp",
|
|
||||||
"rr_get_secure",
|
|
||||||
"rr_get_trusted"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +56,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testResourceCompileIdChange()
|
public function testResourceCompileIdChange()
|
||||||
{
|
{
|
||||||
$this->smarty->registerResource('myresource', array('getSource', 'getTimestamp', 'getSecure', 'getTrusted'));
|
$this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2());
|
||||||
$this->smarty->compile_id = 'a';
|
$this->smarty->compile_id = 'a';
|
||||||
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
||||||
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
||||||
@@ -72,7 +69,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testSmartyTemplate() {
|
public function testSmartyTemplate() {
|
||||||
$this->smarty->registerResource('mytpl', array('getTemplate', 'getTimestamp', 'getSecure', 'getTrusted'));
|
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3());
|
||||||
$this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo'));
|
$this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo'));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -80,55 +77,24 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testSmartyCurrentDir() {
|
public function testSmartyCurrentDir() {
|
||||||
$this->smarty->registerResource('mytpl', array('getCurrentDir', 'getTimestamp', 'getSecure', 'getTrusted'));
|
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4());
|
||||||
$this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar'));
|
$this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom {
|
||||||
|
|
||||||
/**
|
protected function fetch($name, &$source, &$mtime) {
|
||||||
* resource functions
|
$source = '{$x="hello world"}{$x}';
|
||||||
*/
|
$mtime = 1000000000;
|
||||||
function rr_get_template($tpl_name, &$tpl_source, $smarty_obj)
|
|
||||||
{
|
|
||||||
// populating $tpl_source
|
|
||||||
$tpl_source = '{$x="hello world"}{$x}';
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function rr_get_timestamp($tpl_name, &$tpl_timestamp, $smarty_obj)
|
|
||||||
{
|
|
||||||
// $tpl_timestamp.
|
|
||||||
$tpl_timestamp = (int) floor(time() / 100) * 100;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function rr_get_secure($tpl_name, $smarty_obj)
|
class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom {
|
||||||
{
|
|
||||||
// assume all templates are secure
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function rr_get_trusted($tpl_name, $smarty_obj)
|
protected function fetch($name, &$source, &$mtime) {
|
||||||
{
|
|
||||||
// not used for templates
|
|
||||||
}
|
|
||||||
|
|
||||||
// resource functions for compile_id change test
|
|
||||||
|
|
||||||
function getSecure($name, $smarty)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTrusted($name, $smarty)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSource($name, &$source, $smarty)
|
|
||||||
{
|
|
||||||
// we update a counter, so that we return a new source for every call
|
// we update a counter, so that we return a new source for every call
|
||||||
static $counter = 0;
|
static $counter = 0;
|
||||||
$counter ++;
|
$counter ++;
|
||||||
@@ -136,27 +102,30 @@ function getSource($name, &$source, $smarty)
|
|||||||
// construct a new source
|
// construct a new source
|
||||||
$source = "this is template $counter";
|
$source = "this is template $counter";
|
||||||
|
|
||||||
return true;
|
$mtime = 1000000000;
|
||||||
}
|
}
|
||||||
function getTemplate($name, &$source, $smarty)
|
|
||||||
|
protected function fetchTimestamp($name)
|
||||||
{
|
{
|
||||||
// construct a new source
|
return 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom {
|
||||||
|
|
||||||
|
protected function fetch($name, &$source, &$mtime) {
|
||||||
$source = 'template = {$smarty.template}';
|
$source = 'template = {$smarty.template}';
|
||||||
|
$mtime = 1000000000;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
function getCurrentDir($name, &$source, $smarty)
|
|
||||||
{
|
}
|
||||||
// construct a new source
|
|
||||||
|
class RegisteredResourceTest_Resource4 extends Smarty_Resource_Custom {
|
||||||
|
|
||||||
|
protected function fetch($name, &$source, &$mtime) {
|
||||||
$source = 'current_dir = {$smarty.current_dir}';
|
$source = 'current_dir = {$smarty.current_dir}';
|
||||||
|
$mtime = 1000000000;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimestamp($name, &$timestamp, $smarty)
|
|
||||||
{
|
|
||||||
// always pretend the template is brand new
|
|
||||||
$timestamp = (int) floor(time() / 100) * 100;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Smarty plugin
|
* Smarty plugin
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
@@ -8,30 +9,21 @@
|
|||||||
* Purpose: Fetches templates from a database
|
* Purpose: Fetches templates from a database
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_resource_db_source($tpl_name, &$tpl_source, $smarty)
|
|
||||||
{
|
|
||||||
// do database call here to fetch your template,
|
|
||||||
// populating $tpl_source
|
|
||||||
$tpl_source = '{$x="hello world"}{$x}';
|
|
||||||
|
|
||||||
return true;
|
class Smarty_Resource_Db extends Smarty_Resource_Recompiled {
|
||||||
|
|
||||||
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||||
|
$source->filepath = 'db:';
|
||||||
|
$source->uid = sha1($source->resource);
|
||||||
|
$source->timestamp = 0;
|
||||||
|
$source->exists = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, $smarty)
|
public function populateTimestamp(Smarty_Template_Source $source): int {
|
||||||
{
|
return 1000000000;
|
||||||
// $tpl_timestamp.
|
|
||||||
$tpl_timestamp = (int) floor(time() / 100) * 100;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_resource_db_secure($tpl_name, $smarty)
|
public function getContent(Smarty_Template_Source $source) {
|
||||||
{
|
return '{$x="hello world"}{$x}';
|
||||||
// assume all templates are secure
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_resource_db_trusted($tpl_name, $smarty)
|
|
||||||
{
|
|
||||||
// not used for templates
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user