mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
Update
This commit is contained in:
@@ -7,13 +7,14 @@
|
||||
* 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';
|
||||
if (is_file(__DIR__ . '/../smarty/libs/Autoloader.php')) {
|
||||
require_once __DIR__ . '/../smarty/libs/Autoloader.php';
|
||||
} elseif (is_file(__DIR__ . '/../libs/Autoloader.php')) {
|
||||
require_once __DIR__ . '/../libs/Autoloader.php';
|
||||
} else {
|
||||
throw new Exception('can not locate Smarty distribution');
|
||||
}
|
||||
Smarty_Autoloader::register(true);
|
||||
if (!defined('SMARTY_COMPOSER_INSTALL')) {
|
||||
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
|
||||
if (file_exists($file)) {
|
||||
@@ -26,7 +27,11 @@ if (!defined('SMARTY_COMPOSER_INSTALL')) {
|
||||
if (!class_exists('PHPUnit_Framework_TestCase')) {
|
||||
require_once SMARTY_COMPOSER_INSTALL;
|
||||
}
|
||||
|
||||
require_once 'PHPUnit_Smarty.php';
|
||||
ini_set('date.timezone', 'UTC');
|
||||
if (!ini_get('date.timezone')) {
|
||||
ini_set('date.timezone', 'UTC');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -82,16 +82,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
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.
|
||||
@@ -133,7 +124,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
if (!is_dir($dir . '/configs')) {
|
||||
mkdir($dir . '/configs');
|
||||
}
|
||||
if (self::$config['individualFolders'] != 'true') {
|
||||
if (individualFolders != 'true') {
|
||||
$dir = __DIR__;
|
||||
}
|
||||
if (!is_dir($dir . '/templates_c')) {
|
||||
@@ -150,7 +141,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
// instance Smarty class
|
||||
if ($this->loadSmarty) {
|
||||
$this->smarty = new Smarty;
|
||||
if (self::$config['individualFolders'] != 'true') {
|
||||
if (individualFolders != 'true') {
|
||||
$this->smarty->setCompileDir(__DIR__ . '/templates_c');
|
||||
$this->smarty->setCacheDir(__DIR__ . '/cache');
|
||||
}
|
||||
@@ -158,7 +149,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
// instance SmartyBC class
|
||||
if ($this->loadSmartyBC) {
|
||||
$this->smartyBC = new SmartyBC;
|
||||
if (self::$config['individualFolders'] != 'true') {
|
||||
if (individualFolders != 'true') {
|
||||
$this->smartyBC->setCompileDir(__DIR__ . '/templates_c');
|
||||
$this->smartyBC->setCacheDir(__DIR__ . '/cache');
|
||||
}
|
||||
@@ -173,7 +164,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
if (PHPUnit_Smarty::$pdo == null) {
|
||||
try {
|
||||
PHPUnit_Smarty::$pdo = new PDO(self::$config['mysql']['DB_DSN'], self::$config['mysql']['DB_USER'], self::$config['mysql']['DB_PASSWD']);
|
||||
PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD);
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests for cache resource file
|
||||
* Smarty PHPunit tests for cache resource Apc
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
@@ -15,9 +15,9 @@ include_once __DIR__ . '/../Memcache/CacheResourceCustomMemcacheTest.php';
|
||||
*/
|
||||
class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest
|
||||
{
|
||||
public function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$config['cacheResource']['ApcEnable'] != 'true') {
|
||||
if (ApcCacheEnable != true) {
|
||||
$this->markTestSkipped('Apc tests are disabled');
|
||||
} else {
|
||||
if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) {
|
||||
@@ -30,3 +30,4 @@ class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest
|
||||
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$config['cacheResource']['MemcacheEnable'] != 'true') {
|
||||
if (MemCacheEnable != true) {
|
||||
$this->markTestSkipped('Memcache tests are disabled');
|
||||
} else {
|
||||
if (!class_exists('Memcache')) {
|
||||
@@ -34,7 +34,6 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
|
||||
$this->smarty->setCachingType('memcachetest');
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
|
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests for cache resource file
|
||||
* Smarty PHPunit tests for cache resource mysql
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
|
||||
|
||||
/**
|
||||
* class for cache resource file tests
|
||||
*
|
||||
@@ -17,7 +18,7 @@ class CacheResourceCustomMysqlTest extends CacheResourceTestCommon
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
|
||||
if (MysqlCacheEnable != true) {
|
||||
$this->markTestSkipped('mysql tests are disabled');
|
||||
}
|
||||
if (self::$init) {
|
||||
@@ -34,3 +35,4 @@ class CacheResourceCustomMysqlTest extends CacheResourceTestCommon
|
||||
$this->initMysqlCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests for cache resource file
|
||||
* Smarty PHPunit tests for cache resource Pdo
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
@@ -18,7 +18,7 @@ class CacheResourceCustomPDOTest extends CacheResourceTestCommon
|
||||
|
||||
public function setUp($dir = null, $clear = true)
|
||||
{
|
||||
if (self::$config['cacheResource']['PdoEnable'] != 'true') {
|
||||
if (PdoCacheEnable != true) {
|
||||
$this->markTestSkipped('mysql Pdo tests are disabled');
|
||||
}
|
||||
if (self::$init) {
|
||||
@@ -38,3 +38,4 @@ class CacheResourceCustomPDOTest extends CacheResourceTestCommon
|
||||
$this->initMysqlCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon
|
||||
|
||||
public function setUp($dir = null, $clear = true)
|
||||
{
|
||||
if (self::$config['cacheResource']['PdoGzipEnable'] != 'true') {
|
||||
if (PdoGzipCacheEnable != truw) {
|
||||
$this->markTestSkipped('mysql Pdo Gzip tests are disabled');
|
||||
}
|
||||
if (self::$init) {
|
||||
@@ -38,3 +38,4 @@ class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon
|
||||
$this->initMysqlCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests for cache resource file
|
||||
* Smarty PHPunit tests for cache resource registered
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
@@ -16,7 +16,7 @@ class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
|
||||
if (MysqlCacheEnable != true) {
|
||||
$this->markTestSkipped('mysql tests are disabled');
|
||||
}
|
||||
if (self::$init) {
|
||||
@@ -37,3 +37,4 @@ class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon
|
||||
$this->initMysqlCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,89 +5,83 @@
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for resource plugins tests
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ResourceMysqlPluginTest extends PHPUnit_Smarty
|
||||
{
|
||||
public function setUp()
|
||||
if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
|
||||
/**
|
||||
* class for resource plugins tests
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ResourceMysqlPluginTest extends PHPUnit_Smarty
|
||||
{
|
||||
if (self::$config['resource']['MysqlEnable'] != 'true') {
|
||||
$this->markTestSkipped('mysql tests are disabled');
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$init) {
|
||||
$this->getConnection();
|
||||
}
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
if (self::$init) {
|
||||
$this->getConnection();
|
||||
|
||||
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}' )");
|
||||
}
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
}
|
||||
|
||||
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 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 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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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 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
|
||||
);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,20 +15,20 @@ class ResourcePluginTest extends PHPUnit_Smarty
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
|
||||
if (MysqlResourceEnable != true) {
|
||||
$this->markTestSkipped('mysql tests are disabled');
|
||||
}
|
||||
if (self::$init) {
|
||||
$this->getConnection();
|
||||
}
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
/**
|
||||
* test resource plugin rendering
|
||||
*/
|
||||
@@ -58,7 +58,6 @@ class ResourcePluginTest extends PHPUnit_Smarty
|
||||
$this->assertEquals('hello world', $this->smarty->fetch('db2a:test'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test resource plugin non-existent compiled cache of a recompiling resource
|
||||
*/
|
||||
@@ -71,7 +70,6 @@ class ResourcePluginTest extends PHPUnit_Smarty
|
||||
$this->assertFalse($tpl->compiled->filepath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test resource plugin timestamp
|
||||
*/
|
||||
@@ -82,5 +80,5 @@ class ResourcePluginTest extends PHPUnit_Smarty
|
||||
$this->assertTrue(is_integer($tpl->source->timestamp));
|
||||
$this->assertEquals(10, strlen($tpl->source->timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -292,8 +292,8 @@ public function testPHP_REMOVE_php()
|
||||
*/
|
||||
public function testPHP_Tag_Literal()
|
||||
{
|
||||
$content = $this->smartyBC->fetch("string:aa { php} echo 'hallo'; {/php} ae");
|
||||
$this->assertEquals('aa { php} echo \'hallo\'; {/php} ae', $content);
|
||||
$content = $this->smartyBC->fetch("string:aa { php} echo 'hallo'; { /php} ae");
|
||||
$this->assertEquals('aa { php} echo \'hallo\'; { /php} ae', $content);
|
||||
}
|
||||
/**
|
||||
* test unmatched {php} tag
|
||||
|
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<config>
|
||||
<individualFolders>true</individualFolders>
|
||||
<cacheResource>
|
||||
<MemcacheEnable>false</MemcacheEnable>
|
||||
<ApcEnable>false</ApcEnable>
|
||||
<MysqlEnable>false</MysqlEnable>
|
||||
<PdoEnable>false</PdoEnable>
|
||||
<PdoGzipEnable>false</PdoGzipEnable>
|
||||
</cacheResource>
|
||||
<resource>
|
||||
<MysqlEnable>false</MysqlEnable>
|
||||
</resource>
|
||||
<mysql>
|
||||
<DB_DSN>mysql:dbname=test;host=localhost</DB_DSN>
|
||||
<DB_USER>smarty</DB_USER>
|
||||
<DB_PASSWD></DB_PASSWD>
|
||||
</mysql>
|
||||
</config>
|
@@ -9,6 +9,19 @@
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
stopOnFailure="false">
|
||||
|
||||
<php>
|
||||
<const name="individualFolders" value="true"/>
|
||||
<const name="MemCacheEnable" value="false"/>
|
||||
<const name="ApcCacheEnable" value="false"/>
|
||||
<const name="MysqlCacheEnable" value="false"/>
|
||||
<const name="PdoCacheEnable" value="false"/>
|
||||
<const name="PdoGzipCacheEnable" value="false"/>
|
||||
<const name="MysqlResourceEnable" value="false"/>
|
||||
<const name="DB_DSN" value="mysql:dbname=test;host=localhost"/>
|
||||
<const name="DB_USER" value="smarty"/>
|
||||
<const name="DB_PASSWD" value=""/>
|
||||
</php>
|
||||
|
||||
<filter>
|
||||
<testsuites>
|
||||
<testsuite name="Smarty Test Suite">
|
||||
|
Reference in New Issue
Block a user