Revert "3.1.11"

This reverts commit d3af847798ed757770a5a0d336fa04780a7ec2cd.
This commit is contained in:
Uwe Tews
2015-05-04 02:23:23 +02:00
parent 429229d6b6
commit 1834622d94
564 changed files with 1 additions and 24555 deletions

View File

@@ -1,32 +0,0 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
/*
* Smarty PHPUnit Bootstrap
*/
// Locate SmartyBC class and load it
if (is_file(__DIR__ . '/../smarty/libs/SmartyBC.class.php')) {
require_once __DIR__ . '/../smarty/libs/SmartyBC.class.php';
} elseif (is_file(__DIR__ . '/../libs/SmartyBC.class.php')) {
require_once __DIR__ . '/../libs/SmartyBC.class.php';
} else {
throw new Exception('can not locate Smarty distribution');
}
if (!defined('SMARTY_COMPOSER_INSTALL')) {
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
if (file_exists($file)) {
define('SMARTY_COMPOSER_INSTALL', $file);
break;
}
}
unset($file);
}
if (!class_exists('PHPUnit_Framework_TestCase')) {
require_once SMARTY_COMPOSER_INSTALL;
}
require_once 'PHPUnit_Smarty.php';
ini_set('date.timezone', 'UTC');

View File

@@ -1,606 +0,0 @@
<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
/**
* Smarty Test Case Fixture
*/
class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
{
/**
* Smarty object
*
* @var SmartyBC
*/
public $smartyBC = null;
/**
* SmartyBC object
*
* @var Smarty
*/
public $smarty = null;
/**
* Flag if test is using the Smarty object
*
* @var bool
*/
public $loadSmarty = true;
/**
* Flag if test is using the SmartyBC object
*
* @var bool
*/
public $loadSmartyBC = false;
/**
* Flag for initialization at first test
*
* @var bool
*/
public static $init = true;
/**
* Configuration data from config.xml
*
* @var array
*/
public static $config = null;
/**
* Saved current working directory
*
* @var null
*/
public static $cwd = null;
/**
* PDO object for Mysql tests
*
* @var PDO
*/
public static $pdo = null;
/**
* Default blacklist
*
* @var array
*/
protected $backupStaticAttributesBlacklist = array(
'PHPUnit_Smarty' => array('config', 'pdo', 'init'),
);
/**
* This method is called before the first test of this test class is run.
*
*/
public static function setUpBeforeClass()
{
error_reporting(E_ALL | E_STRICT);
self::$init = true;
self::$pdo = null;
if (self::$config == null) {
$xml = simplexml_load_file(__DIR__ . '/config.xml');
$json_string = json_encode($xml);
self::$config = json_decode($json_string, true);
if (empty(self::$config['mysql']['DB_PASSWD'])) {
self::$config['mysql']['DB_PASSWD'] = null;
}
}
}
/**
* This method is called after the last test of this test class is run.
*
*/
public static function tearDownAfterClass()
{
self::$pdo = null;
}
/**
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->backupStaticAttributesBlacklist[get_class($this)] = array('init', 'config', 'pdo');
}
/**
* Setup Smarty instance called for each test
*
* @param null $dir working directory
*/
public function setUpSmarty($dir = null)
{
// set up current working directory
chdir($dir);
self::$cwd = getcwd();
// create missing folders for test
if (self::$init) {
if (!is_dir($dir . '/templates')) {
mkdir($dir . '/templates');
}
if (!is_dir($dir . '/configs')) {
mkdir($dir . '/configs');
}
if (self::$config['individualFolders'] != 'true') {
$dir = __DIR__;
}
if (!is_dir($dir . '/templates_c')) {
mkdir($dir . '/templates_c');
chmod($dir . '/templates_c', 0775);
}
if (!is_dir($dir . '/cache')) {
mkdir($dir . '/cache');
chmod($dir . '/cache', 0775);
}
self::$init = false;
}
clearstatcache();
// instance Smarty class
if ($this->loadSmarty) {
$this->smarty = new Smarty;
if (self::$config['individualFolders'] != 'true') {
$this->smarty->setCompileDir(__DIR__ . '/templates_c');
$this->smarty->setCacheDir(__DIR__ . '/cache');
}
}
// instance SmartyBC class
if ($this->loadSmartyBC) {
$this->smartyBC = new SmartyBC;
if (self::$config['individualFolders'] != 'true') {
$this->smartyBC->setCompileDir(__DIR__ . '/templates_c');
$this->smartyBC->setCacheDir(__DIR__ . '/cache');
}
}
}
/**
* Create Mysql PDO object
*
*/
final public function getConnection()
{
if (self::$pdo == null) {
try {
self::$pdo = new PDO(self::$config['mysql']['DB_DSN'], self::$config['mysql']['DB_USER'], self::$config['mysql']['DB_PASSWD']);
}
catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$timezone = date_default_timezone_get();
self::$pdo->exec("SET time_zone = '{$timezone}';");
}
}
/**
* Create table for Mysql resource
*
*/
public function initMysqlResource()
{
$this->getConnection();
self::$pdo->exec("DROP TABLE `templates`");
self::$pdo->exec("CREATE TABLE IF NOT EXISTS `templates` (
`name` varchar(100) NOT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`source` text,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Create table for Mysql cache resource
*
*/
public function initMysqlCache()
{
$this->getConnection();
self::$pdo->exec("DROP TABLE `output_cache`");
self::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
`id` char(40) NOT NULL COMMENT 'sha1 hash',
`name` varchar(250) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`content` mediumblob NOT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`),
KEY `expire` (`expire`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Delete files in templates_c and cache folders
*
*/
public function cleanDirs()
{
$this->cleanCompileDir();
$this->cleanCacheDir();
}
/**
* Delete files in templates_c folder
*
*/
public function cleanCompileDir()
{
if (isset($this->smarty)) {
$this->cleanDir($this->smarty->getCompileDir());
} elseif (isset($this->smartyBC)) {
$this->cleanDir($this->smartyBC->getCompileDir());
}
}
/**
* Delete files in cache folder
*
*/
public function cleanCacheDir()
{
if (isset($this->smarty)) {
$this->cleanDir($this->smarty->getCacheDir());
} elseif (isset($this->smartyBC)) {
$this->cleanDir($this->smartyBC->getCacheDir());
}
}
/**
* Delete files and sub folders
*
* @param string $dir
*/
public function cleanDir($dir)
{
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
$file->isDir() ? rmdir($file) : unlink($file);
}
}
/**
* Get PDO object
*
* @return null|PDO
*/
final public function getPDO()
{
return self::$pdo;
}
/**
* Remove "\r" and replace "\t" with spaces
*
* @param string $in
*
* @return mixed
*/
public function normalizeString($in)
{
if (is_string($in)) {
$in = str_replace("\r", '', $in);
$in = str_replace("\t", ' ', $in);
}
return $in;
}
/**
* Return source path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
public function buildSourcePath($tpl, $name = null, $type = null, $dir = null)
{
$name = isset($name) ? $name : $tpl->source->name;
$type = isset($type) ? $type : $tpl->source->type;
$dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0);
switch ($type) {
case 'file':
case 'php':
return $this->normalizePath($dir . $name, true);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
return sha1($name);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Build template uid
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param null|string $value
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return string
* @throws \Exception
*/
public function buildUid($tpl, $value = null, $name = null, $type = null)
{
$type = isset($type) ? $type : $tpl->source->type;
$name = isset($name) ? $name : $tpl->source->name;
switch ($type) {
case 'file':
if ($tpl instanceof Smarty) {
return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name, true));
}
return sha1($tpl->source->filepath);
case 'php':
return sha1($tpl->source->filepath);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
return sha1($name);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Normalize file path
*
* @param string $path input path
* @param bool $ds if true use system directory separator
*
* @return string
*/
public function normalizePath($path, $ds = false)
{
$path = str_replace(array('\\', '/./'), '/', $path);
while ($path !== $new = preg_replace('#[^\.\/]+/\.\./#', '', $path)) {
$path = $new;
}
if (DS !== '/' && $ds) {
$path = str_replace('/', DS, $path);
}
return $path;
}
/**
* Return base name
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return null|string
*/
public function getBasename(Smarty_Internal_Template $tpl, $name = null, $type = null)
{
$name = isset($name) ? $name : $tpl->source->name;
$type = isset($type) ? $type : $tpl->source->type;
switch ($type) {
case 'file':
if (($_pos = strpos($name, ']')) !== false) {
$name = substr($name, $_pos + 1);
}
return basename($name);
case 'mysqltest':
case 'mysql':
return $name;
case 'string':
return '';
default:
return null;
}
}
/**
* Return compiled file path
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param bool $caching caching flag
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
public function buildCompiledPath(Smarty_Internal_Template $tpl, $sub = true, $caching = false, $compile_id = null, $name = null, $type = null, $dir = null)
{
$sep = DS;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_flag = '';
$_filepath = $uid . $_flag;
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath = substr($_filepath, 0, 2) . $sep
. substr($_filepath, 2, 2) . $sep
. substr($_filepath, 4, 2) . $sep
. $_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_compile_id)) {
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
}
// caching token
if ($caching) {
$_cache = '.cache';
} else {
$_cache = '';
}
$_compile_dir = $tpl->smarty->getCompileDir();
// set basename if not specified
$_basename = $this->getBasename($tpl, $name, $type);
if ($_basename === null) {
$_basename = basename(preg_replace('![^\w\/]+!', '_', $name));
}
// separate (optional) basename by dot
if ($_basename) {
$_basename = '.' . $_basename;
}
return $_compile_dir . $_filepath . '.' . $type . $_basename . $_cache . '.php';
}
/**
* Return cache file path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param null|string $cache_id optional cache id
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
* @param null|string $cacheType optional cache resource type
*
* @return string
* @throws \Exception
*/
public function buildCachedPath($tpl, $sub = true, $cache_id = null, $compile_id = null, $name = null, $type = null, $dir = null, $cacheType = null)
{
$cacheType = isset($cacheType) ? $cacheType : $tpl->smarty->caching_type;
switch ($cacheType) {
case 'file':$sep = DS;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_filepath = $uid;
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath = substr($_filepath, 0, 2) . $sep
. substr($_filepath, 2, 2) . $sep
. substr($_filepath, 4, 2) . $sep
. $_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
} else {
$_cache_id = '';
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
}
$smarty = isset($tpl->smarty) ? $tpl->smarty : $tpl;
$_cache_dir = $smarty->getCacheDir();
return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php';
case 'mysql':
case 'mysqltest':
case 'pdo':
case 'foobar':
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
return sha1($sp . $_cache_id . $_compile_id);
default:
throw new Exception("Unhandled cache resource type '{$cacheType}'");
}
}
/**
* Prefilter to remove \r from template source
*
* @param string $tpl_source
* @param $template
*
* @return mixed
*/
function remove_cr($tpl_source, $template)
{
return str_replace(array("\r\n", "\r"), "\n", $tpl_source);
}
/**
* Remove Smarty object from cached resources
*
*/
public function clearResourceCache()
{
if (class_exists('Smarty_Resource', false)) {
if (isset(Smarty_Resource::$sources) && !empty(Smarty_Resource::$sources)) {
foreach (Smarty_Resource::$sources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$sources = array();
}
if (isset(Smarty_Resource::$compileds) && !empty(Smarty_Resource::$compileds)) {
foreach (Smarty_Resource::$compileds as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$compileds = array();
}
if (isset(Smarty_Resource::$resources) && !empty(Smarty_Resource::$resources)) {
foreach (Smarty_Resource::$resources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_Resource::$resources = array();
}
}
if (class_exists('Smarty_CacheResource', false)) {
if (isset(Smarty_CacheResource::$resources) && !empty(Smarty_CacheResource::$resources)) {
foreach (Smarty_CacheResource::$resources as $obj) {
if (isset($obj->smarty)) {
$obj->smarty = null;
}
}
Smarty_CacheResource::$resources = array();
}
}
}
/**
* Tears down the fixture
* This method is called after a test is executed.
*
*/
protected function tearDown()
{
$this->clearResourceCache();
if (isset($this->smarty->smarty)) {
$this->smarty->smarty = null;
}
if (isset($this->smarty)) {
$this->smarty = null;
}
if (isset($this->smartyBC->smarty)) {
$this->smartyBC->smarty = null;
}
if (isset($this->smartyBC)) {
$this->smartyBC = null;
}
}
}

View File

@@ -1,17 +1 @@
#Smarty 3 template engine
##PHPUnit repository
For installing the PHPUnit test by composer use the following:
"require-dev": {
"smarty/smarty-phpunit": "3.1.12"
}
Replace 3.1.12 with the installed Smarty version number.
Starting with Smarty version 3.1.22 the "require-dev" section will be added
to the composer.json file of the Smarty distribution.
The tests for the custom template and cache resources Mysql, Memcache and APC can
be enabled in config.xml.
# phpunit

View File

@@ -1,144 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class HttpModifiedSinceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
*
*/
public function testDisabled()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(false);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledUncached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = false;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledCached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l1 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l2 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached2()
{
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() - 3600) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l3 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l4 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached3()
{
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() + 10) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l5 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l6 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('', $output);
$this->assertEquals('304 Not Modified', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
}

View File

@@ -1,18 +0,0 @@
<?php /*%%SmartyHeaderCode:249675546aba644cab1-14021185%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'4bf4a289c4129184fbd543f317e3a064a0574e1c' =>
array (
0 => '.\\templates\\helloworld.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '249675546aba644cab1-14021185',
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546aba64b87d7_02670632',
'cache_lifetime' => 20,
),true); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546aba64b87d7_02670632')) {function content_5546aba64b87d7_02670632($_smarty_tpl) {?>hello world<?php }} ?>

View File

@@ -1,22 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:42
compiled from ".\templates\helloworld.tpl" */ ?>
<?php /*%%SmartyHeaderCode:249675546aba644cab1-14021185%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'4bf4a289c4129184fbd543f317e3a064a0574e1c' =>
array (
0 => '.\\templates\\helloworld.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '249675546aba644cab1-14021185',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546aba6475b44_68121128',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546aba6475b44_68121128')) {function content_5546aba6475b44_68121128($_smarty_tpl) {?>hello world<?php }} ?>

View File

@@ -1,22 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:42
compiled from ".\templates\helloworld.tpl" */ ?>
<?php /*%%SmartyHeaderCode:227085546aba65d0dd6-58481784%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'4bf4a289c4129184fbd543f317e3a064a0574e1c' =>
array (
0 => '.\\templates\\helloworld.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '227085546aba65d0dd6-58481784',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546aba65d3d09_19505259',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546aba65d3d09_19505259')) {function content_5546aba65d3d09_19505259($_smarty_tpl) {?>hello world<?php }} ?>

View File

@@ -1,31 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
include_once __DIR__ . '/../Memcache/CacheResourceCustomMemcacheTest.php';
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest
{
public function setUp()
{
if (self::$config['cacheResource']['ApcEnable'] != 'true') {
$this->markTestSkipped('Apc tests are disabled');
} else {
if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) {
$this->markTestSkipped('APC cache not available');
}
}
$this->setUpSmarty(__DIR__);
parent::setUp();
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
}
}

View File

@@ -1,379 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceFileTest extends CacheResourceTestCommon
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
parent::setUp();
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test getCachedFilepath with configuration['useSubDirs'] enabled
*/
public function testGetCachedFilepathSubDirs()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl, true, null, null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
}
/**
* test cache->clear_all with cache_id and compile_id
*/
public function testClearCacheAllCacheIdCompileId()
{
$this->cleanCacheDir();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertEquals(1, $this->smarty->clearAllCache());
}
/**
* test cache->clear with cache_id and compile_id
*/
public function testClearCacheCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(false);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, 'foo|bar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId2()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId2Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId3()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(false);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId3Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->cleanCacheDir();
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId4()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId4Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId5()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheIdCompileId5Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
}
public function testClearCacheCacheFile()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(false);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
}
public function testClearCacheCacheFileSub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$this->cleanCacheDir();
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->writeCachedContent($tpl);
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
}
/**
* test cache->clear_all method
*/
public function testClearCacheAll()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
$this->assertEquals(1, $this->smarty->clearAllCache());
}
/**
* test cache->clear_all method not expired
*/
public function testClearCacheAllNotExpired()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
touch($this->smarty->getCacheDir() . 'dummy.php', time() - 1000);
clearstatcache();
$this->assertEquals(0, $this->smarty->clearAllCache(2000));
}
/**
* test cache->clear_all method expired
*/
public function testClearCacheAllExpired()
{
$this->cleanCacheDir();
file_put_contents($this->smarty->getCacheDir() . 'dummy.php', 'test');
touch($this->smarty->getCacheDir() . 'dummy.php', time() - 1000);
clearstatcache();
$this->assertEquals(1, $this->smarty->clearAllCache(500));
}
private function writeCachedContent($tpl)
{
$tpl->writeCachedContent("echo 'hello world';\n");
}
}

View File

@@ -1,23 +0,0 @@
<?php /*%%SmartyHeaderCode:38755546abaf14aab8-71469973%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430694828,
2 => 'file',
),
),
'nocache_hash' => '38755546abaf14aab8-71469973',
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => true,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abaf19e261_67778154',
'cache_lifetime' => 1000,
),true); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abaf19e261_67778154')) {function content_5546abaf19e261_67778154($_smarty_tpl) {?>cache resource test:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
compiled:8 rendered:8<?php }} ?>

View File

@@ -1,29 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:51
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:38755546abaf14aab8-71469973%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430694828,
2 => 'file',
),
),
'nocache_hash' => '38755546abaf14aab8-71469973',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => true,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abaf1600e0_49160488',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abaf1600e0_49160488')) {function content_5546abaf1600e0_49160488($_smarty_tpl) {?>cache resource test:<?php echo '/*%%SmartyNocache:38755546abaf14aab8-71469973%%*/<?php echo $_smarty_tpl->tpl_vars[\'test\']->value;?>
/*/%%SmartyNocache:38755546abaf14aab8-71469973%%*/';?>
compiled:8 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,28 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:46
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:164665546abaa8fcd21-71079491%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430694477,
2 => 'file',
),
),
'nocache_hash' => '164665546abaa8fcd21-71079491',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abaa910fa4_90350098',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abaa910fa4_90350098')) {function content_5546abaa910fa4_90350098($_smarty_tpl) {?>cache resource test:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
compiled:3 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,92 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource memcache
*
* @package PHPunit
* @author Uwe Tews
*/
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource memcache tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
{
/**
* Sets up the fixture
* This method is called before a test is executed.
*
*/
public function setUp()
{
if (self::$config['cacheResource']['MemcacheEnable'] != 'true') {
$this->markTestSkipped('Memcache tests are disabled');
} else {
if (!class_exists('Memcache')) {
$this->markTestSkipped('Memcache not available');
}
}
$this->setUpSmarty(__DIR__);
parent::setUp();
$this->smarty->setCachingType('memcachetest');
}
public function testInit()
{
$this->cleanDirs();
}
protected function doClearCacheAssertion($a, $b)
{
$this->assertEquals(- 1, $b);
}
public function testGetCachedFilepathSubDirs()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$sha1 = $tpl->source->uid . '#helloworld_tpl##';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$sha1 = $tpl->source->uid . '#helloworld_tpl##blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
}
}

View File

@@ -1,30 +0,0 @@
<?php /* Smarty version 3.1.22-dev/21, created on 2015-05-02 04:19:59
compiled from "C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/helloworld.tpl" */ ?>
<?php
/*%%SmartyHeaderCode:81345544506f0bfdf9_59326255%%*/
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'7bffc03815234166256088a02ecdb09997cab3ab' =>
array (
0 => 'C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/helloworld.tpl',
1 => 1430538151,
2 => 'file',
),
),
'nocache_hash' => '81345544506f0bfdf9_59326255',
'has_nocache_code' => false,
'version' => '3.1.22-dev/21',
'unifunc' => 'content_5544506f115195_19246751',
),false);
/*/%%SmartyHeaderCode%%*/
if ($_valid && !is_callable('content_5544506f115195_19246751')) {
function content_5544506f115195_19246751 ($_smarty_tpl) {
?>
<?php
$_smarty_tpl->properties['nocache_hash'] = '81345544506f0bfdf9_59326255';
?>
hello world<?php }
}
?>

View File

@@ -1,37 +0,0 @@
<?php /* Smarty version 3.1.22-dev/21, created on 2015-05-02 04:19:58
compiled from "C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/cacheresource.tpl" */ ?>
<?php
/*%%SmartyHeaderCode:283645544506ea82522_15247746%%*/
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'8116aff437278768935b896ec15aa941ca30b7dc' =>
array (
0 => 'C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/cacheresource.tpl',
1 => 1430540396,
2 => 'file',
),
),
'nocache_hash' => '283645544506ea82522_15247746',
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => true,
'version' => '3.1.22-dev/21',
'unifunc' => 'content_5544506ead8391_48098543',
),false);
/*/%%SmartyHeaderCode%%*/
if ($_valid && !is_callable('content_5544506ead8391_48098543')) {
function content_5544506ead8391_48098543 ($_smarty_tpl) {
?>
<?php
$_smarty_tpl->properties['nocache_hash'] = '283645544506ea82522_15247746';
?>
cache resource test:<?php echo '/*%%SmartyNocache:283645544506ea82522_15247746%%*/<?php echo $_smarty_tpl->tpl_vars[\'test\']->value;?>
/*/%%SmartyNocache:283645544506ea82522_15247746%%*/';?>
compiled:6 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }
}
?>

View File

@@ -1,36 +0,0 @@
<?php /* Smarty version 3.1.22-dev/21, created on 2015-05-02 04:19:55
compiled from "C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/cacheresource.tpl" */ ?>
<?php
/*%%SmartyHeaderCode:281785544506bed3ff2_49412264%%*/
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'8116aff437278768935b896ec15aa941ca30b7dc' =>
array (
0 => 'C:/wamp/www/Smarty3.1-test-2 - 3.1.11/vendor/smarty/smarty-phpunit/UnitTests/CacheResourceTests/Memcache/../_shared/templates/cacheresource.tpl',
1 => 1430540391,
2 => 'file',
),
),
'nocache_hash' => '281785544506bed3ff2_49412264',
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => false,
'version' => '3.1.22-dev/21',
'unifunc' => 'content_5544506c0039a3_11510686',
),false);
/*/%%SmartyHeaderCode%%*/
if ($_valid && !is_callable('content_5544506c0039a3_11510686')) {
function content_5544506c0039a3_11510686 ($_smarty_tpl) {
?>
<?php
$_smarty_tpl->properties['nocache_hash'] = '281785544506bed3ff2_49412264';
?>
cache resource test:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
compiled:3 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }
}
?>

View File

@@ -1,36 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceCustomMysqlTest extends CacheResourceTestCommon
{
public function setUp()
{
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(__DIR__);
parent::setUp();
$this->smarty->setCachingType('mysqltest');
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}

View File

@@ -1,29 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:09:53
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:1948555469cb1159e43-37348003%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430690990,
2 => 'file',
),
),
'nocache_hash' => '1948555469cb1159e43-37348003',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => true,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cb116d815_90024127',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cb116d815_90024127')) {function content_55469cb116d815_90024127($_smarty_tpl) {?>cache resource test:<?php echo '/*%%SmartyNocache:1948555469cb1159e43-37348003%%*/<?php echo $_smarty_tpl->tpl_vars[\'test\']->value;?>
/*/%%SmartyNocache:1948555469cb1159e43-37348003%%*/';?>
compiled:8 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,28 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:09:48
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:1970055469cac87b0d5-71028152%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430690981,
2 => 'file',
),
),
'nocache_hash' => '1970055469cac87b0d5-71028152',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cac88e2e9_35971948',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cac88e2e9_35971948')) {function content_55469cac88e2e9_35971948($_smarty_tpl) {?>cache resource test:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
compiled:3 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,39 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon
{
public function setUp()
{
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(__DIR__);
parent::setUp();
if (!class_exists('Smarty_CacheResource_Mysqltest', false)) {
require_once(__DIR__ . "/../_shared/PHPunitplugins/cacheresource.mysqltest.php");
}
$this->smarty->setCachingType('foobar');
$this->smarty->registerCacheResource('foobar', new Smarty_CacheResource_Mysqltest());
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlCache();
}
}

View File

@@ -1,29 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:10:00
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:1750455469cb8bee994-09305681%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430690998,
2 => 'file',
),
),
'nocache_hash' => '1750455469cb8bee994-09305681',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => true,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cb8c02288_10181435',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cb8c02288_10181435')) {function content_55469cb8c02288_10181435($_smarty_tpl) {?>cache resource test:<?php echo '/*%%SmartyNocache:1750455469cb8bee994-09305681%%*/<?php echo $_smarty_tpl->tpl_vars[\'test\']->value;?>
/*/%%SmartyNocache:1750455469cb8bee994-09305681%%*/';?>
compiled:8 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,28 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:09:56
compiled from "C:\wamp\www\Smarty3.1-test-2 - 3.1.11\vendor\smarty\smarty-phpunit-base\UnitTests\CacheResourceTests\_shared\templates\cacheresource.tpl" */ ?>
<?php /*%%SmartyHeaderCode:1648355469cb43e06e9-37147882%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'07151901299e1db6baaa501a7774ebe631e91b80' =>
array (
0 => 'C:\\wamp\\www\\Smarty3.1-test-2 - 3.1.11\\vendor\\smarty\\smarty-phpunit-base\\UnitTests\\CacheResourceTests\\_shared\\templates\\cacheresource.tpl',
1 => 1430690990,
2 => 'file',
),
),
'nocache_hash' => '1648355469cb43e06e9-37147882',
'function' =>
array (
),
'variables' =>
array (
'test' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cb43f3cd1_93445459',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cb43f3cd1_93445459')) {function content_55469cb43f3cd1_93445459($_smarty_tpl) {?>cache resource test:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
compiled:3 rendered:<?php echo $_smarty_tpl->tpl_vars['test']->value;?>
<?php }} ?>

View File

@@ -1,522 +0,0 @@
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceTestCommon extends PHPUnit_Smarty
{
public static $touchResource = null;
public function setUp()
{
$this->smarty->setTemplateDir(__DIR__ . '/../_shared/templates');
$this->smarty->addPluginsDir(__DIR__ . '/../_shared/PHPunitplugins');
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
}
protected function doClearCacheAssertion($a, $b)
{
$this->assertEquals($a, $b);
}
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
{
return str_replace('#', $tpl->getVariable('test'), $text);
}
/**
* test getCachedFilepath with configuration['useSubDirs'] enabled
*/
public function testGetCachedFilepathSubDirs()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl), $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar'), $tpl->cached->filepath);
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar'), $tpl->cached->filepath);
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar'), $tpl->cached->filepath);
}
/**
* test cache->clear_all with cache_id and compile_id
*/
public function testClearCacheAllCacheIdCompileId()
{
$this->smarty->clearAllCache();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
// Custom CacheResources may return -1 if they can't tell the number of deleted elements
$this->assertEquals(-1, $this->smarty->clearAllCache());
}
/**
* test cache->clear with cache_id and compile_id
*/
public function testClearCacheCacheIdCompileId()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world 1');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$tpl2->writeCachedContent('hello world 2');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world 3');
// test cached content
$this->assertEquals('hello world 1', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world 3', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId2()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId2Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar2', 'blar');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId3()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId3Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId4()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId4Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId5()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId5Sub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar2');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheFile()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$tpl3->writeCachedContent('hello world');
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
// test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
}
public function testClearCacheCacheFileSub()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->clearAllCache();
// create and cache templates
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->writeCachedContent('hello world');
$tpl2 = $this->smarty->createTemplate('helloworld.tpl', null, 'bar');
$tpl2->writeCachedContent('hello world');
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$tpl3->writeCachedContent('hello world');
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
// test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedPrepare()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 1);
// compile and cache
$this->assertEquals('cache resource test:1 compiled:1 rendered:1', $this->smarty->fetch('cacheresource.tpl'));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCached()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 2);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertTrue($tpl->isCached());
$this->assertEquals('cache resource test:2 compiled:1 rendered:1', $this->smarty->fetch($tpl));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedCachingDisabled()
{
$this->smarty->assign('test', 3);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertFalse($tpl->isCached());
$this->assertEquals('cache resource test:3 compiled:3 rendered:3', $this->smarty->fetch($tpl));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testForceCache()
{
$this->smarty->caching = true;
$this->smarty->setForceCache(true);
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 4);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertFalse($tpl->isCached(), 'isCached() must be false at forceCache');
$this->assertEquals('cache resource test:4 compiled:1 rendered:4', $this->smarty->fetch($tpl));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedAftertestForceCache()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 5);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertTrue($tpl->isCached(), 'isCached() must be true after forceCache');
$this->assertEquals('cache resource test:5 compiled:1 rendered:4', $this->smarty->fetch($tpl));
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedTouchedSource()
{
sleep(2);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 6);
$filepath = $this->buildSourcePath(null, 'cacheresource.tpl', 'file');
touch($filepath);
sleep(2);
clearstatcache();
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$isCached = $tpl->isCached();
$mustCompile = $tpl->mustCompile();
$this->assertFalse($isCached, 'isCached() must be false after touch of source');
$this->assertTrue($mustCompile, 'mustCompile() must be true after touch of source');
$this->assertEquals('cache resource test:6 compiled:6 rendered:6', $this->smarty->fetch($tpl), 'recompile failed');
$this->assertFalse($isCached, 'isCached() must be false after touch of source');
$this->assertTrue($mustCompile, 'mustCompile() must be true after touch of source');
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedAfterTouch()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 7);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertTrue($tpl->isCached(), 'isCached() must be true after recompilation');
$this->assertEquals('cache resource test:7 compiled:6 rendered:6', $this->smarty->fetch($tpl));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedForceCompile()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setForceCompile(true);
$this->smarty->assign('test', 8);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertFalse($tpl->isCached(), 'isCached() must be false at force compile');
$this->assertEquals('cache resource test:8 compiled:8 rendered:8', $this->smarty->fetch($tpl));
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testIsCachedAfterForceCompile()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->assign('test', 9);
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
$this->assertTrue($tpl->isCached(), 'isCached() must be true after recompilation');
$this->assertEquals('cache resource test:9 compiled:8 rendered:8', $this->smarty->fetch($tpl));
}
}

View File

@@ -1,25 +0,0 @@
<?php
require_once SMARTY_DIR . '../demo/plugins/cacheresource.apc.php';
class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
{
public function get(Smarty_Internal_Template $_template)
{
$this->contents = array();
$this->timestamps = array();
$t = $this->getContent($_template);
return $t ? $t : null;
}
public function __sleep()
{
return array();
}
public function __wakeup()
{
$this->__construct();
}
}

View File

@@ -1,25 +0,0 @@
<?php
require_once SMARTY_DIR . '../demo/plugins/cacheresource.memcache.php';
class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
{
public function get(Smarty_Internal_Template $_template)
{
$this->contents = array();
$this->timestamps = array();
$t = $this->getContent($_template);
return $t ? $t : null;
}
public function __sleep()
{
return array();
}
public function __wakeup()
{
$this->__construct();
}
}

View File

@@ -1,18 +0,0 @@
<?php
require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php';
class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
{
public function __construct() {
try {
$this->db = PHPUnit_Smarty::$pdo;
} catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');
$this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
VALUES (:id, :name, :cache_id, :compile_id, :content)');
}
}

View File

@@ -1,22 +0,0 @@
<?php
class Smarty_Resource_Filetest extends Smarty_Internal_Resource_File
{
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
parent::populate($source, $_template);
if ($source->exists) {
if (isset(CacheResourceTestCommon::$touchResource[$source->filepath])) {
$source->timestamp = CacheResourceTestCommon::$touchResource[$source->filepath];
}
}
}
}

View File

@@ -1 +0,0 @@
cache resource test:{$test nocache} compiled:# rendered:{$test}

View File

@@ -1,40 +0,0 @@
<?php
/**
* Smarty PHPunit tests compilation of compiler plugins
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for compiler plugin tests
*
* @backupStaticAttributes enabled
*/
class CompileCompilerPluginTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test compiler plugin tag in template file
*/
public function testCompilerPlugin()
{
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
$tpl = $this->smarty->createTemplate('compilerplugintest.tpl');
$this->assertEquals("Hello World", $this->smarty->fetch($tpl));
}
}
function mycompilerplugin($params, $compiler)
{
return '<?php echo \'Hello World\';?>';
}

View File

@@ -1,22 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:56
compiled from ".\templates\compilerplugintest.tpl" */ ?>
<?php /*%%SmartyHeaderCode:194885546abb47961d3-54943983%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'f6bec11575eec81ea7514450742fd638d38fbecf' =>
array (
0 => '.\\templates\\compilerplugintest.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '194885546abb47961d3-54943983',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb479bf71_83734070',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb479bf71_83734070')) {function content_5546abb479bf71_83734070($_smarty_tpl) {?><?php echo 'Hello World';?><?php }} ?>

View File

@@ -1,70 +0,0 @@
<?php
/**
* Smarty PHPunit tests of delimiter
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for delimiter tests
*
* @backupStaticAttributes enabled
*/
class DelimiterTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test <{ }> delimiter
*/
public function testDelimiter1()
{
$this->smarty->left_delimiter = '<{';
$this->smarty->right_delimiter = '}>';
$tpl = $this->smarty->createTemplate('eval:<{* comment *}><{if true}><{"hello world"}><{/if}>');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
/**
* test <-{ }-> delimiter
*/
public function testDelimiter2()
{
$this->smarty->left_delimiter = '<-{';
$this->smarty->right_delimiter = '}->';
$tpl = $this->smarty->createTemplate('eval:<-{* comment *}-><-{if true}-><-{"hello world"}-><-{/if}->');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
/**
* test <--{ }--> delimiter
*/
public function testDelimiter3()
{
$this->smarty->left_delimiter = '<--{';
$this->smarty->right_delimiter = '}-->';
$tpl = $this->smarty->createTemplate('eval:<--{* comment *}--><--{if true}--><--{"hello world"}--><--{/if}-->');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
/**
* test {{ }} delimiter
*/
public function testDelimiter4()
{
$this->smarty->left_delimiter = '{{';
$this->smarty->right_delimiter = '}}';
$tpl = $this->smarty->createTemplate('eval:{{* comment *}}{{if true}}{{"hello world"}}{{/if}}');
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
}
}

View File

@@ -1,379 +0,0 @@
<?php
/**
* Smarty PHPunit tests of config variables
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for config variable tests
*
* @b ackupStaticAttributes enabled
*/
class ConfigVarTest extends PHPUnit_Smarty
{
/**
* Sets up the fixture
* This method is called before a test is executed.
*
*/
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
/**
* empty templat_c and cache folders
*/
public function testInit()
{
$this->cleanDirs();
}
/**
* test number config variable
*/
public function testConfigNumber()
{
$this->smarty->configLoad('test.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test string config variable
*/
public function testConfigText()
{
$this->smarty->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch('eval:{#text#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test line string config variable
*/
public function testConfigLine()
{
$this->smarty->configLoad('test.conf');
$this->assertEquals("123 This is a line", $this->smarty->fetch('eval:{#line#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test config variables in global sections
*/
public function testConfigVariableGlobalSections()
{
$this->smarty->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty! Global Section1 Global Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test config variables loading section2
*/
public function testConfigVariableSection2()
{
$this->smarty->configLoad('test.conf', 'section2');
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test config variables loading section special char
*/
public function testConfigVariableSectionSpecialChar()
{
$this->smarty->configLoad('test.conf', '/');
$this->assertEquals("Welcome to Smarty! special char", $this->smarty->fetch('eval:{#title#} {#sec#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test config variables loading section foo/bar
*/
public function testConfigVariableSectionFooBar()
{
$this->smarty->configLoad('test.conf', 'foo/bar');
$this->assertEquals("Welcome to Smarty! section foo/bar", $this->smarty->fetch('eval:{#title#} {#sec#}'));
}
/**
* @run InSeparateProcess
* @preserveGlobalState disabled
*
* test config variables loaded in different scopes from different sections (Smarty and template)
*/
public function testConfigDifferentScope()
{
$this->smarty->configLoad('test.conf', 'section2');
$tpl = $this->smarty->createTemplate('eval:{#title#} {#sec1#} {#sec2#}');
$tpl->configLoad('test.conf', 'section1');
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{#title#} {#sec1#} {#sec2#}'));
$this->assertEquals("Welcome to Smarty! Hello Section1 Global Section2", $this->smarty->fetch($tpl));
}
/**
* test config variables of hidden sections
* shall display variables from hidden section
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigVariableHidden()
{
$this->smarty->config_read_hidden = true;
$this->smarty->configLoad('test.conf', 'hidden');
$this->assertEquals("Welcome to Smarty!Hidden Section", $this->smarty->fetch('eval:{#title#}{#hiddentext#}'));
}
/**
* test config variables of disabled hidden sections
* shall display not variables from hidden section
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigVariableHiddenDisable()
{
$this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE));
$this->smarty->config_read_hidden = false;
$this->smarty->configLoad('test.conf', 'hidden');
$this->assertEquals("Welcome to Smarty!", $this->smarty->fetch('eval:{#title#}{#hiddentext#}'));
}
/**
* test getConfigVars
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetSingleConfigVar()
{
$this->smarty->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty!", $this->smarty->getConfigVars('title'));
}
/**
* test getConfigVars return all variables
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetAllConfigVars()
{
$this->smarty->configLoad('test.conf');
$vars = $this->smarty->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertEquals("Welcome to Smarty!", $vars['title']);
$this->assertEquals("Global Section1", $vars['sec1']);
}
/**
* test clearConfig for single variable
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearSingleConfigVar()
{
$this->smarty->configLoad('test.conf');
$this->smarty->clearConfig('title');
$this->assertEquals("", $this->smarty->getConfigVars('title'));
}
/**
* test clearConfig for all variables
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearConfigAll()
{
$this->smarty->configLoad('test.conf');
$this->smarty->clearConfig();
$vars = $this->smarty->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertTrue(empty($vars));
}
/**
* test config vars on data object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigTextData()
{
$data = $this->smarty->createData();
$data->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch('eval:{#text#}', $data));
}
/**
* test getConfigVars on data object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetSingleConfigVarData()
{
$data = $this->smarty->createData();
$data->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty!", $data->getConfigVars('title'));
}
/**
* test getConfigVars return all variables on data object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetAllConfigVarsData()
{
$data = $this->smarty->createData();
$data->configLoad('test.conf');
$vars = $data->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertEquals("Welcome to Smarty!", $vars['title']);
$this->assertEquals("Global Section1", $vars['sec1']);
}
/**
* test clearConfig for single variable on data object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearSingleConfigVarData()
{
$data = $this->smarty->createData();
$data->configLoad('test.conf');
$data->clearConfig('title');
$this->assertEquals("", $data->getConfigVars('title'));
$this->assertEquals("Global Section1", $data->getConfigVars('sec1'));
}
/**
* test clearConfig for all variables on data object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearConfigAllData()
{
$data = $this->smarty->createData();
$data->configLoad('test.conf');
$data->clearConfig();
$vars = $data->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertTrue(empty($vars));
}
/**
* test config vars on template object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigTextTemplate()
{
$tpl = $this->smarty->createTemplate('eval:{#text#}');
$tpl->configLoad('test.conf');
$this->assertEquals("123bvc", $this->smarty->fetch($tpl));
}
/**
* test getConfigVars on template object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetSingleConfigVarTemplate()
{
$tpl = $this->smarty->createTemplate('eval:{#text#}');
$tpl->configLoad('test.conf');
$this->assertEquals("Welcome to Smarty!", $tpl->getConfigVars('title'));
}
/**
* test getConfigVars return all variables on template object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigGetAllConfigVarsTemplate()
{
$tpl = $this->smarty->createTemplate('eval:{#text#}');
$tpl->configLoad('test.conf');
$vars = $tpl->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertEquals("Welcome to Smarty!", $vars['title']);
$this->assertEquals("Global Section1", $vars['sec1']);
}
/**
* test clearConfig for single variable on template object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearSingleConfigVarTemplate()
{
$tpl = $this->smarty->createTemplate('eval:{#text#}');
$tpl->configLoad('test.conf');
$tpl->clearConfig('title');
$this->assertEquals("", $tpl->getConfigVars('title'));
$this->assertEquals("Global Section1", $tpl->getConfigVars('sec1'));
}
/**
* test clearConfig for all variables on template object
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigClearConfigAllTemplate()
{
$tpl = $this->smarty->createTemplate('eval:{#text#}');
$tpl->configLoad('test.conf');
$tpl->clearConfig();
$vars = $tpl->getConfigVars();
$this->assertTrue(is_array($vars));
$this->assertTrue(empty($vars));
}
/**
* test config variables loading from absolute file path
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*/
public function testConfigAbsolutePath()
{
$file = realpath($this->smarty->getConfigDir(0) . 'test.conf');
$this->smarty->configLoad($file);
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}'));
}
public function testConfigResourceDb4()
{
$this->smarty->addPluginsDir(dirname(__FILE__) . "/PHPunitplugins/");
$this->smarty->configLoad('db4:foo.conf');
$this->assertEquals("bar", $this->smarty->fetch('eval:{#foo#}'));
}
}

View File

@@ -1,143 +0,0 @@
<?php
/**
* Smarty PHPUnit tests default config handler
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for default config handler test
*
* @backupStaticAttributes enabled
*/
class DefaultConfigHandlerTest extends PHPUnit_Smarty
{
/**
* Sets up the fixture
* This method is called before a test is executed.
*
*/
public function setUp()
{
$this->setUpSmarty(__DIR__);
$this->smarty->setForceCompile(true);
}
/**
* @expectedException SmartyException
* @expectedExceptionMessage Unable to read
* @expectedExceptionMessage file 'foo.conf'
*
* test unknown config file
*/
public function testUnknownConfigFile()
{
$this->smarty->configLoad('foo.conf');
}
/**
* @expectedException SmartyException
* @expectedExceptionMessage Default config handler
* @expectedExceptionMessage not callable
*
* test register unknown default config handler
*
*/
public function testRegisterUnknownDefaultConfigHandler()
{
$this->smarty->registerDefaultConfigHandler('foo');
}
/**
* test default config handler replacement (config data)
*
* @throws \Exception
* @throws \SmartyException
*/
public function testDefaultConfigHandlerReplacement()
{
$this->smarty->registerDefaultConfigHandler('configHandlerData');
$this->smarty->configLoad('foo.conf');
$this->assertEquals("bar", $this->smarty->fetch('eval:{#foo#}'));
}
/**
* test default config handler replacement (other config file)
*
* @throws \Exception
* @throws \SmartyException
*/
public function testDefaultConfigHandlerReplacementByConfigFile()
{
$this->smarty->registerDefaultConfigHandler('configHandlerFile');
$this->smarty->configLoad('foo.conf');
$this->assertEquals("123.4", $this->smarty->fetch('eval:{#Number#}'));
}
/**
* @expectedException SmartyException
* @expectedExceptionMessage Unable to read
* @expectedExceptionMessage file 'foo.conf'
*
* test default config handler replacement (return false)
*
*/
public function testDefaultConfigHandlerReplacementReturningFalse()
{
$this->smarty->configLoad('foo.conf');
}
}
/**
* config handler returning config data
*
* @param $resource_type
* @param $resource_name
* @param $config_source
* @param $config_timestamp
* @param \Smarty $smarty
*
* @return bool
*/
function configHandlerData($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
{
$output = "foo = 'bar'\n";
$config_source = $output;
$config_timestamp = time();
return true;
}
/**
* config handler returning config file
*
* @param $resource_type
* @param $resource_name
* @param $config_source
* @param $config_timestamp
* @param \Smarty $smarty
*
* @return string
*/
function configHandlerFile($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
{
return $smarty->getConfigDir(0) . 'test.conf';
}
/**
* config handler returning false
*
* @param $resource_type
* @param $resource_name
* @param $config_source
* @param $config_timestamp
* @param \Smarty $smarty
*
* @return bool
*/
function configHandlerFalse($resource_type, $resource_name, &$config_source, &$config_timestamp, Smarty $smarty)
{
return false;
}

View File

@@ -1,27 +0,0 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: resource.db3.php
* Type: resource
* Name: db
* Purpose: Fetches templates from a database
* -------------------------------------------------------------
*/
class Smarty_Resource_Db4 extends Smarty_Resource
{
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = 'db4:';
$source->uid = sha1($source->resource);
$source->timestamp = 0;
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source)
{
return "foo = 'bar'\n";
}
}

View File

@@ -1,49 +0,0 @@
title = Welcome to Smarty!
overwrite = Overwrite1
overwrite = Overwrite2
booleanon = on
Intro = """This is a value that spans more
than one line. you must enclose
it in triple quotes."""
Number = 123.4
text = 123bvc
line = 123 This is a line
sec1 = Global Section1
sec2 = Global Section2
sec = Global char
[/]
sec = special char
[foo/bar]
sec = section foo/bar
[section1]
sec1 = Hello Section1
[section2]
sec2 = 'Hello Section2'
[.hidden]
hiddentext = Hidden Section
#Comment
# Comment with a space first line first
#Comment line starting with space
# Space before and after #
#The line below only contains a #
#
#
# title = This is not the correct title
#[section1]
#sec1 = Wrong text

View File

@@ -1,48 +0,0 @@
<?php $_config_vars = array (
'sections' =>
array (
'/' =>
array (
'vars' =>
array (
'sec' => 'special char',
),
),
'foo/bar' =>
array (
'vars' =>
array (
'sec' => 'section foo/bar',
),
),
'section1' =>
array (
'vars' =>
array (
'sec1' => 'Hello Section1',
),
),
'section2' =>
array (
'vars' =>
array (
'sec2' => 'Hello Section2',
),
),
),
'vars' =>
array (
'title' => 'Welcome to Smarty!',
'overwrite' => 'Overwrite2',
'booleanon' => true,
'Intro' => 'This is a value that spans more
than one line. you must enclose
it in triple quotes.',
'Number' => 123.40000000000001,
'text' => '123bvc',
'line' => '123 This is a line',
'sec1' => 'Global Section1',
'sec2' => 'Global Section2',
'sec' => 'Global char',
),
); ?>

View File

@@ -1,48 +0,0 @@
<?php $_config_vars = array (
'sections' =>
array (
'/' =>
array (
'vars' =>
array (
'sec' => 'special char',
),
),
'foo/bar' =>
array (
'vars' =>
array (
'sec' => 'section foo/bar',
),
),
'section1' =>
array (
'vars' =>
array (
'sec1' => 'Hello Section1',
),
),
'section2' =>
array (
'vars' =>
array (
'sec2' => 'Hello Section2',
),
),
),
'vars' =>
array (
'title' => 'Welcome to Smarty!',
'overwrite' => 'Overwrite2',
'booleanon' => true,
'Intro' => 'This is a value that spans more
than one line. you must enclose
it in triple quotes.',
'Number' => 123.40000000000001,
'text' => '123bvc',
'line' => '123 This is a line',
'sec1' => 'Global Section1',
'sec2' => 'Global Section2',
'sec' => 'Global char',
),
); ?>

View File

@@ -1,55 +0,0 @@
<?php $_config_vars = array (
'sections' =>
array (
'/' =>
array (
'vars' =>
array (
'sec' => 'special char',
),
),
'foo/bar' =>
array (
'vars' =>
array (
'sec' => 'section foo/bar',
),
),
'section1' =>
array (
'vars' =>
array (
'sec1' => 'Hello Section1',
),
),
'section2' =>
array (
'vars' =>
array (
'sec2' => 'Hello Section2',
),
),
'hidden' =>
array (
'vars' =>
array (
'hiddentext' => 'Hidden Section',
),
),
),
'vars' =>
array (
'title' => 'Welcome to Smarty!',
'overwrite' => 'Overwrite2',
'booleanon' => true,
'Intro' => 'This is a value that spans more
than one line. you must enclose
it in triple quotes.',
'Number' => 123.40000000000001,
'text' => '123bvc',
'line' => '123 This is a line',
'sec1' => 'Global Section1',
'sec2' => 'Global Section2',
'sec' => 'Global char',
),
); ?>

View File

@@ -1,48 +0,0 @@
<?php $_config_vars = array (
'sections' =>
array (
'/' =>
array (
'vars' =>
array (
'sec' => 'special char',
),
),
'foo/bar' =>
array (
'vars' =>
array (
'sec' => 'section foo/bar',
),
),
'section1' =>
array (
'vars' =>
array (
'sec1' => 'Hello Section1',
),
),
'section2' =>
array (
'vars' =>
array (
'sec2' => 'Hello Section2',
),
),
),
'vars' =>
array (
'title' => 'Welcome to Smarty!',
'overwrite' => 'Overwrite2',
'booleanon' => true,
'Intro' => 'This is a value that spans more
than one line. you must enclose
it in triple quotes.',
'Number' => 123.40000000000001,
'text' => '123bvc',
'line' => '123 This is a line',
'sec1' => 'Global Section1',
'sec2' => 'Global Section2',
'sec' => 'Global char',
),
); ?>

View File

@@ -1,119 +0,0 @@
<?php
/**
* Smarty PHPunit tests for File resources
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for file resource tests
*
* @backupStaticAttributes enabled
*/
class CustomResourceAmbiguousTest extends PHPUnit_Smarty
{
public $_resource = null;
public function setUp()
{
$this->setUpSmarty(__DIR__);
require_once dirname(__FILE__) . '/PHPunitplugins/resource.ambiguous.php';
// empty the template dir
$this->smarty->setTemplateDir(array());
// kill cache for unit test
// Smarty::$_resource_cache = array();
}
public function testInit()
{
$this->cleanDirs();
}
protected function relative($path)
{
$path = str_replace(dirname(__FILE__), '.', $path);
if (DS == "\\") {
$path = str_replace("\\", "/", $path);
}
return $path;
}
public function testNone()
{
$resource_handler = new Smarty_Resource_Ambiguous(dirname(__FILE__) . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
$this->smarty->setAllowAmbiguousResources(true);
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertFalse($tpl->source->exists);
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testCase1()
{
$resource_handler = new Smarty_Resource_Ambiguous(dirname(__FILE__) . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
$this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists);
$this->assertEquals('case1', $tpl->source->content);
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testCase2()
{
$resource_handler = new Smarty_Resource_Ambiguous(dirname(__FILE__) . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
$this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists);
$this->assertEquals('case2', $tpl->source->content);
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testCaseSwitching()
{
$resource_handler = new Smarty_Resource_Ambiguous(dirname(__FILE__) . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
$this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists);
$this->assertEquals('case1', $tpl->source->content);
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists);
$this->assertEquals('case2', $tpl->source->content);
}
}

View File

@@ -1,58 +0,0 @@
<?php
/**
* Ambiguous Filename Custom Resource Example
*
* @package Resource-examples
* @author Rodney Rehm
*/
class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
{
protected $directory;
protected $segment;
public function __construct($directory)
{
$this->directory = rtrim($directory, "/\\") . DS;
// parent::__construct();
}
public function setSegment($segment)
{
$this->segment = $segment;
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
return get_class($this) . '#' . $this->segment . '#' . $resource_name;
}
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$segment = '';
if ($this->segment) {
$segment = rtrim($this->segment, "/\\") . DS;
}
$source->filepath = $this->directory . $segment . $source->name;
$source->uid = sha1($source->filepath);
if ($_template->smarty->getCompileCheck() && !isset($source->timestamp)) {
$source->timestamp = @filemtime($source->filepath);
$source->exists = !!$source->timestamp;
}
}
}

View File

@@ -1,54 +0,0 @@
<?php
/**
* Smarty PHPUnit tests demo resource plugin extendaall
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for demo resource plugin extendaall tests
*
* @backupStaticAttributes enabled
*/
class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
public function testResourcePluginExtendsall()
{
$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->setTemplateDir(array(
'root' => './templates',
'./templates_2',
'./templates_3',
'./templates_4',
));
$expected = "templates\n\n templates_3\n templates\n\ntemplates_4";
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl'));
}
public function testResourcePluginExtendsallOne()
{
$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->setTemplateDir(array(
'root' => './templates',
'./templates_2',
'./templates_3',
'./templates_4',
));
$expected = "templates\ntemplates";
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall2.tpl'));
}
}

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}

View File

@@ -1,5 +0,0 @@
{block name="alpha"}templates_3{/block}
{block name="bravo"}
{block name="bravo_1"}templates_3{/block}
{block name="bravo_2"}templates_3{/block}
{/block}

View File

@@ -1,3 +0,0 @@
{block name="alpha"}templates_4{/block}
{block name="bravo"}templates_4{/block}
{block name="charlie"}templates_4{/block}

View File

@@ -1,39 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:57
compiled from "./templates_4\extendsall.tpl" */ ?>
<?php /*%%SmartyHeaderCode:121225546abb5f2b671-01503806%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'5b1d3e07bc47be8f4a5f5cd1f8ae111ad1a7ca0f' =>
array (
0 => './templates_4\\extendsall.tpl',
1 => 1430683105,
2 => 'file',
),
'ba13e09c248af4844bba79ebf73b0ef0f5f120ce' =>
array (
0 => './templates_3\\extendsall.tpl',
1 => 1430683105,
2 => 'file',
),
'5f64d1ca3a7c49dfbbcc0277dcc3d271b7d10cbb' =>
array (
0 => './templates_4\\extendsall.tpl',
1 => 1430683105,
2 => 'file',
),
),
'nocache_hash' => '121225546abb5f2b671-01503806',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb60404f5_42810634',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb60404f5_42810634')) {function content_5546abb60404f5_42810634($_smarty_tpl) {?>templates
templates_3
templates
templates_4<?php }} ?>

View File

@@ -1,23 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:58
compiled from "./templates\extendsall2.tpl" */ ?>
<?php /*%%SmartyHeaderCode:264065546abb6194953-69169065%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'704aecf038c94f81baafdca1f23a7507816c73ea' =>
array (
0 => './templates\\extendsall2.tpl',
1 => 1430683105,
2 => 'file',
),
),
'nocache_hash' => '264065546abb6194953-69169065',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb61b0363_70152869',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb61b0363_70152869')) {function content_5546abb61b0363_70152869($_smarty_tpl) {?>templates
templates<?php }} ?>

View File

@@ -1,18 +0,0 @@
<?php
require_once SMARTY_DIR . '../demo/plugins/resource.mysqls.php';
class Smarty_Resource_Mysqlstest extends Smarty_Resource_Mysqls
{
public function __construct()
{
try {
$this->db = PHPUnit_Smarty::$pdo;
}
catch
(PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
}
}

View File

@@ -1,19 +0,0 @@
<?php
require_once SMARTY_DIR . '../demo/plugins/resource.mysql.php';
class Smarty_Resource_Mysqltest extends Smarty_Resource_Mysql
{
public function __construct()
{
try {
$this->db = PHPUnit_Smarty::$pdo;
}
catch
(PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');
}
}

View File

@@ -1,93 +0,0 @@
<?php
/**
* Smarty PHPunit tests resource plugins
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for resource plugins tests
*
* @backupStaticAttributes enabled
*/
class ResourceMysqlPluginTest extends PHPUnit_Smarty
{
public function setUp()
{
if (self::$config['resource']['MysqlEnable'] != 'true') {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
$this->initMysqlResource();
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '2010-12-25 22:00:00', '{\$x = \'hello world\'}{\$x}' )");
}
/**
* test resource plugin rendering of a custom resource
*/
public function testResourcePluginMysql()
{
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl'));
}
/**
* test resource plugin timestamp of a custom resource
*/
public function testResourcePluginMysqlTimestamp()
{
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
}
/**
* test resource plugin compiledFilepath of a custom resource
*/
public function testResourcePluginMysqlCompiledFilepath()
{
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0))
, $tpl->compiled->filepath
);
}
public function testResourcePluginMysqlCompiledFilepathCache()
{
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$this->smarty->setForceCompile(true);
$this->smarty->fetch('mysqltest:test.tpl');
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0))
, $tpl->compiled->filepath
);
$this->smarty->caching = false;
}
/**
* test resource plugin timestamp of a custom resource with only fetch() implemented
*/
public function testResourcePluginMysqlTimestampWithoutFetchTimestamp()
{
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqlstest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
}
}

View File

@@ -1,22 +0,0 @@
<?php /*%%SmartyHeaderCode:742155469cbb454da8-38747488%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'647cc67112410df246da12386c05d0ef094a40d8' =>
array (
0 => 'mysqltest:test.tpl',
1 => 1293314400,
2 => 'mysqltest',
),
),
'nocache_hash' => '742155469cbb454da8-38747488',
'variables' =>
array (
'x' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cbb49e663_35561983',
'cache_lifetime' => 1000,
),true); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cbb49e663_35561983')) {function content_55469cbb49e663_35561983($_smarty_tpl) {?>hello world<?php }} ?>

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}

View File

@@ -1,27 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:10:03
compiled from "mysqltest:test.tpl" */ ?>
<?php /*%%SmartyHeaderCode:742155469cbb454da8-38747488%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'647cc67112410df246da12386c05d0ef094a40d8' =>
array (
0 => 'mysqltest:test.tpl',
1 => 1293314400,
2 => 'mysqltest',
),
),
'nocache_hash' => '742155469cbb454da8-38747488',
'function' =>
array (
),
'variables' =>
array (
'x' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cbb461b78_51901024',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cbb461b78_51901024')) {function content_55469cbb461b78_51901024($_smarty_tpl) {?><?php $_smarty_tpl->tpl_vars['x'] = new Smarty_variable('hello world', null, 0);?><?php echo $_smarty_tpl->tpl_vars['x']->value;?>
<?php }} ?>

View File

@@ -1,27 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 22:10:03
compiled from "mysqltest:test.tpl" */ ?>
<?php /*%%SmartyHeaderCode:2184455469cbb0540a1-97220652%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'647cc67112410df246da12386c05d0ef094a40d8' =>
array (
0 => 'mysqltest:test.tpl',
1 => 1293314400,
2 => 'mysqltest',
),
),
'nocache_hash' => '2184455469cbb0540a1-97220652',
'function' =>
array (
),
'variables' =>
array (
'x' => 0,
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_55469cbb060f64_51786358',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_55469cbb060f64_51786358')) {function content_55469cbb060f64_51786358($_smarty_tpl) {?><?php $_smarty_tpl->tpl_vars['x'] = new Smarty_variable('hello world', null, 0);?><?php echo $_smarty_tpl->tpl_vars['x']->value;?>
<?php }} ?>

View File

@@ -1,111 +0,0 @@
<?php
/**
* Smarty PHPunit tests deault template handler
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for block plugin tests
*
* @backupStaticAttributes enabled
*/
class DefaultTemplateHandlerTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
$this->smarty->setForceCompile(true);
$this->smarty->disableSecurity();
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test error on unknow template
*/
public function testUnknownTemplate()
{
try {
$this->smarty->fetch('foo.tpl');
}
catch (Exception $e) {
$this->assertContains('Unable to load template', $e->getMessage());
return;
}
$this->fail('Exception for none existing template has not been raised.');
}
/**
* test error on registration on none existent handler function.
*/
public function testRegisterNoneExistentHandlerFunction()
{
try {
$this->smarty->registerDefaultTemplateHandler('foo');
}
catch (Exception $e) {
$this->assertContains("Default template handler", $e->getMessage());
$this->assertContains("not callable", $e->getMessage());
return;
}
$this->fail('Exception for none callable function has not been raised.');
}
/**
* test replacement by default template handler
*/
/**
* public function testDefaultTemplateHandlerReplacement()
* {
* $this->smarty->register->defaultTemplateHandler('my_template_handler');
* $this->assertEquals("Recsource foo.tpl of type file not found", $this->smarty->fetch('foo.tpl'));
* }
*/
public function testDefaultTemplateHandlerReplacementByTemplateFile()
{
$this->smarty->registerDefaultTemplateHandler('my_template_handler_file');
$this->assertEquals("hello world", $this->smarty->fetch('foo.tpl'));
}
/**
* test default template handler returning fals
*/
public function testDefaultTemplateHandlerReturningFalse()
{
$this->smarty->registerDefaultTemplateHandler('my_false');
try {
$this->smarty->fetch('foo.tpl');
}
catch (Exception $e) {
$this->assertContains('Unable to load template', $e->getMessage());
return;
}
$this->fail('Exception for none existing template has not been raised.');
}
}
function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
{
$output = "Recsource $resource_name of type $resource_type not found";
$template_source = $output;
$template_timestamp = time();
return true;
}
function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
{
return $smarty->getTemplateDir(0) . 'helloworld.tpl';
}
function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
{
return false;
}

View File

@@ -1,22 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:13:58
compiled from ".\templates\helloworld.tpl" */ ?>
<?php /*%%SmartyHeaderCode:121355546abb6c7c4c4-10717602%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'4bf4a289c4129184fbd543f317e3a064a0574e1c' =>
array (
0 => '.\\templates\\helloworld.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '121355546abb6c7c4c4-10717602',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb6c7f703_63773537',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb6c7f703_63773537')) {function content_5546abb6c7f703_63773537($_smarty_tpl) {?>hello world<?php }} ?>

View File

@@ -1,177 +0,0 @@
<?php
/**
* Smarty PHPunit tests for eval resources
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for eval resource tests
*
* @backupStaticAttributes enabled
*/
class EvalResourceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test template eval exits
*/
public function testTemplateEvalExists1()
{
$tpl = $this->smarty->createTemplate('eval:{$foo}');
$this->assertTrue($tpl->source->exists);
}
public function testTemplateEvalExists2()
{
$this->assertTrue($this->smarty->templateExists('eval:{$foo}'));
}
/**
* test getTemplateFilepath
*/
public function testGetTemplateFilepath()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', $tpl->source->filepath);
}
/**
* test getTemplateTimestamp
*/
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->source->timestamp);
}
/**
* test getTemplateSource
*/
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('eval:hello world{$foo}');
$this->assertEquals('hello world{$foo}', $tpl->source->content);
}
/**
* test empty templates
*/
public function testEmptyTemplate()
{
$tpl = $this->smarty->createTemplate('eval:');
$this->assertEquals('', $this->smarty->fetch($tpl));
}
/**
* test usesCompiler
*/
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->source->uncompiled);
}
/**
* test isEvaluated
*/
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->source->recompiled);
}
/**
* test mustCompile
*/
public function testMustCompile()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->mustCompile());
}
/**
* test getCompiledFilepath
*/
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->compiled->filepath);
}
/**
* test getCompiledTimestamp
*/
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->compiled->timestamp);
}
/**
* test isCached
*/
public function testIsCached()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->isCached());
}
/**
* test getRenderedTemplate
*/
public function testGetRenderedTemplate()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $tpl->fetch());
}
/**
* test that no complied template and cache file was produced
*/
public function testNoFiles()
{
$this->cleanDir($this->smarty->getCacheDir());
$this->cleanDir($this->smarty->getCompileDir());
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertEquals(0, $this->smarty->clearAllCache());
$this->assertEquals(0, $this->smarty->clearCompiledTemplate());
}
/**
* test $smarty->is_cached
*/
public function testSmartyIsCached()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertFalse($this->smarty->isCached($tpl));
}
public function testUrlencodeTemplate()
{
$tpl = $this->smarty->createTemplate('eval:urlencode:%7B%22foobar%22%7Cescape%7D');
$this->assertEquals('foobar', $tpl->fetch());
}
public function testBase64Template()
{
$tpl = $this->smarty->createTemplate('eval:base64:eyJmb29iYXIifGVzY2FwZX0=');
$this->assertEquals('foobar', $tpl->fetch());
}
}

View File

@@ -1,45 +0,0 @@
<?php
/**
* Smarty PHPunit tests for Extendsresource
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for extends resource tests
*
* @backupStaticAttributes enabled
*/
class ExtendsResourceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test child/parent template chain with prepend
*/
public function testCompileBlockChildPrepend_003()
{
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
$this->assertContains("prepend - Default Title", $result);
}
/**
* test child/parent template chain with apppend
*/
public function testCompileBlockChildAppend_004()
{
$this->smarty->merge_compiled_includes = true;
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl');
$this->assertContains("Default Title - append", $result);
}
}

View File

@@ -1 +0,0 @@
{block name='title' prepend}prepend - {/block}

View File

@@ -1 +0,0 @@
{block name='title'}Default Title{/block}

View File

@@ -1 +0,0 @@
{block name='title' append} - append{/block}

View File

@@ -1 +0,0 @@
{block name='title'}Default Title{/block}

View File

@@ -1 +0,0 @@
{$foo = 'bar'}

View File

@@ -1 +0,0 @@
{block name='test'}-{$foo}-{/block}

View File

@@ -1,29 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:14:00
compiled from ".\templates\004_child_append.tpl" */ ?>
<?php /*%%SmartyHeaderCode:78525546abb8588163-27944917%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'093723716d45b9734fff13b39adbea12d4b1e66c' =>
array (
0 => '.\\templates\\004_child_append.tpl',
1 => 1430530503,
2 => 'file',
),
'5b5366fff7af250c5e13f5417a80f239e6136245' =>
array (
0 => '.\\templates\\004_parent.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '78525546abb8588163-27944917',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb8599302_42137844',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb8599302_42137844')) {function content_5546abb8599302_42137844($_smarty_tpl) {?>Default Title - append
<?php }} ?>

View File

@@ -1,29 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:14:00
compiled from ".\templates\003_child_prepend.tpl" */ ?>
<?php /*%%SmartyHeaderCode:135665546abb842dcc1-36121526%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'350daf6514df40eb20d421e643b9d0c09ce7a093' =>
array (
0 => '.\\templates\\003_child_prepend.tpl',
1 => 1430530503,
2 => 'file',
),
'3c64479b35e85d197e9347ba83cf20417f49dd5f' =>
array (
0 => '.\\templates\\003_parent.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '135665546abb842dcc1-36121526',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abb843f995_89978082',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abb843f995_89978082')) {function content_5546abb843f995_89978082($_smarty_tpl) {?>prepend - Default Title
<?php }} ?>

View File

@@ -1,277 +0,0 @@
<?php
/**
* Smarty PHPunit tests for File resources
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for file resource tests
*
* @backupStaticAttributes enabled
*/
class FileResourceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
protected function relative($path)
{
$path = str_replace(str_replace("\\", "/", dirname(__FILE__)), '.', str_replace("\\", "/", $path));
return $path;
}
/**
*
*/
public function testGetTemplateFilepath()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals("./templates/helloworld.tpl", str_replace('\\', '/', $tpl->source->filepath));
}
public function testTemplateFileExists1()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->source->exists);
}
public function testTemplateFileExists2()
{
$this->assertTrue($this->smarty->templateExists('helloworld.tpl'));
}
public function testTemplateFileNotExists1()
{
$tpl = $this->smarty->createTemplate('notthere.tpl');
$this->assertFalse($tpl->source->exists);
}
public function testTemplateFileNotExists2()
{
$this->assertFalse($this->smarty->templateExists('notthere.tpl'));
}
public function testTemplateFileNotExists3()
{
try {
$result = $this->smarty->fetch('notthere.tpl');
}
catch (Exception $e) {
$this->assertContains('Unable to load template file \'notthere.tpl\'', $e->getMessage());
return;
}
$this->fail('Exception for not existing template is missing');
}
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->source->timestamp));
$this->assertEquals(10, strlen($tpl->source->timestamp));
}
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals('hello world', $tpl->source->content);
}
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->source->uncompiled);
}
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->source->recompiled);
}
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0))
, $tpl->compiled->filepath
);
}
public function testGetCompiledTimestampPrepare()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
// create dummy compiled file
file_put_contents($tpl->compiled->filepath, '<?php ?>');
touch($tpl->compiled->filepath, $tpl->source->timestamp);
}
/**
*
*/
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->compiled->timestamp));
$this->assertEquals(10, strlen($tpl->compiled->timestamp));
$this->assertEquals($tpl->compiled->timestamp, $tpl->source->timestamp);
}
public function testMustCompileExisting()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->mustCompile());
}
public function testMustCompileAtForceCompile()
{
$this->smarty->setForceCompile(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->mustCompile());
}
public function testMustCompileTouchedSourcePrepare()
{
// touch to prepare next test
sleep(2);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
touch($tpl->source->filepath);
}
public function testMustCompileTouchedSource()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->mustCompile());
// clean up for next tests
$this->cleanDir($this->smarty->getCompileDir());
}
public function testCompileTemplateFile()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->compileTemplateSource();
$this->assertTrue(file_exists($tpl->compiled->filepath));
}
public function testGetCachedFilepath()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath
);
}
public function testGetCachedTimestamp()
{
// create dummy cache file for the following test
file_put_contents($this->buildCachedPath($this->smarty, false, null, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0), 'file')
, '<?php ?>');
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->cached->timestamp));
$this->assertEquals(10, strlen($tpl->cached->timestamp));
}
public function testGetRenderedTemplate()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals('hello world', $tpl->fetch());
}
public function testRelativeInclude()
{
$result = $this->smarty->fetch('relative.tpl');
$this->assertContains('hello world', $result);
}
/**
*
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testRelativeIncludeSub()
{
$result = $this->smarty->fetch('sub/relative.tpl');
$this->assertContains('hello world', $result);
}
public function testRelativeIncludeFail()
{
try {
$this->smarty->fetch('relative_sub.tpl');
}
catch (Exception $e) {
$this->assertContains(htmlentities("Unable to load template"), $e->getMessage());
return;
}
$this->fail('Exception for unknown relative filepath has not been raised.');
}
public function testRelativeIncludeFailOtherDir()
{
$this->smarty->addTemplateDir('./templates_2');
try {
$this->smarty->fetch('relative_notexist.tpl');
}
catch (Exception $e) {
$this->assertContains("Unable to load template", $e->getMessage());
return;
}
$this->fail('Exception for unknown relative filepath has not been raised.');
}
protected function _relativeMap($map, $cwd = null)
{
foreach ($map as $file => $result) {
$this->cleanDir($this->smarty->getCompileDir());
$this->cleanDir($this->smarty->getCacheDir());
if ($result === null) {
try {
$this->smarty->fetch($file);
if ($cwd !== null) {
chdir($cwd);
}
$this->fail('Exception expected for ' . $file);
return;
}
catch (SmartyException $e) {
// this was expected to fail
}
} else {
try {
$_res = $this->smarty->fetch($file);
$this->assertEquals(str_replace("\r", '', $result), $_res, $file);
}
catch (Exception $e) {
if ($cwd !== null) {
chdir($cwd);
}
throw $e;
}
}
}
if ($cwd !== null) {
chdir($cwd);
}
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* Smarty PHPunit tests for File resources
*
* @package PHPunit
* @author Rodney Rehm
* @backupStaticAttributes enabled
*/
class IndexedFileResourceTest extends PHPUnit_Smarty
{
public function setUp()
{
$this->setUpSmarty(__DIR__);
$path = str_replace(array("\\", "/"), DS, dirname(__FILE__));
$this->smarty->addTemplateDir($path . DS. 'templates_2');
// note that 10 is a string!
$this->smarty->addTemplateDir($path . DS. 'templates_3', '10');
$this->smarty->addTemplateDir($path . DS . 'templates_4', 'foo');
}
protected function relative($path)
{
$path = str_replace(str_replace("\\", "/", dirname(__FILE__)), '.', str_replace("\\", "/", $path));
return $path;
}
public function testGetTemplateFilepath()
{
$tpl = $this->smarty->createTemplate('dirname.tpl');
$this->assertEquals("./templates/dirname.tpl", $this->relative($tpl->source->filepath));
}
public function testGetTemplateFilepathNumber()
{
$tpl = $this->smarty->createTemplate('[1]dirname.tpl');
$this->assertEquals('./templates_2/dirname.tpl', $this->relative($tpl->source->filepath));
}
public function testGetTemplateFilepathNumeric()
{
$tpl = $this->smarty->createTemplate('[10]dirname.tpl');
$this->assertEquals('./templates_3/dirname.tpl', $this->relative($tpl->source->filepath));
}
public function testGetTemplateFilepathName()
{
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals('./templates_4/dirname.tpl', $this->relative($tpl->source->filepath));
}
public function testFetch()
{
$tpl = $this->smarty->createTemplate('dirname.tpl');
$this->assertEquals('templates', $this->smarty->fetch($tpl));
}
public function testFetchNumber()
{
$tpl = $this->smarty->createTemplate('[1]dirname.tpl');
$this->assertEquals('templates_2', $this->smarty->fetch($tpl));
}
public function testFetchNumeric()
{
$tpl = $this->smarty->createTemplate('[10]dirname.tpl');
$this->assertEquals('templates_3', $this->smarty->fetch($tpl));
}
public function testFetchName()
{
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals('templates_4', $this->smarty->fetch($tpl));
}
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo')), $tpl->compiled->filepath);
}
public function testGetCachedFilepath()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo'))
, $tpl->cached->filepath);
}
}

View File

@@ -1 +0,0 @@
templates

View File

@@ -1 +0,0 @@
hello world

View File

@@ -1 +0,0 @@
{include file="./helloworld.tpl"}

View File

@@ -1 +0,0 @@
{include file="./hello.tpl"}

View File

@@ -1 +0,0 @@
{include file="../helloworld.tpl"}

View File

@@ -1 +0,0 @@
{include file="../helloworld.tpl"}

View File

@@ -1 +0,0 @@
templates_2

View File

@@ -1 +0,0 @@
hello world

View File

@@ -1 +0,0 @@
php hello world

View File

@@ -1 +0,0 @@
templates_3

View File

@@ -1,5 +0,0 @@
{block name="alpha"}templates_3{/block}
{block name="bravo"}
{block name="bravo_1"}templates_3{/block}
{block name="bravo_2"}templates_3{/block}
{/block}

View File

@@ -1 +0,0 @@
templates_4

View File

@@ -1,3 +0,0 @@
{block name="alpha"}templates_4{/block}
{block name="bravo"}templates_4{/block}
{block name="charlie"}templates_4{/block}

View File

@@ -1,23 +0,0 @@
<?php /* Smarty version Smarty-3.1-DEV, created on 2015-05-03 23:14:04
compiled from ".\templates\relative.tpl" */ ?>
<?php /*%%SmartyHeaderCode:101075546abbc03a7f5-10722784%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'05f195272651ee4ba13643c121341fbda20de0ac' =>
array (
0 => '.\\templates\\relative.tpl',
1 => 1430530503,
2 => 'file',
),
),
'nocache_hash' => '101075546abbc03a7f5-10722784',
'function' =>
array (
),
'has_nocache_code' => false,
'version' => 'Smarty-3.1-DEV',
'unifunc' => 'content_5546abbc048182_09925190',
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5546abbc048182_09925190')) {function content_5546abbc048182_09925190($_smarty_tpl) {?><?php echo $_smarty_tpl->getSubTemplate ("./helloworld.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null, array(), 0);?>
<?php }} ?>

Some files were not shown because too many files have changed in this diff Show More