diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 370c6aaa..02e6f321 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -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'); +} + diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index d97497c7..53d5cea4 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -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()); diff --git a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php index 4cb844ec..0b39a203 100644 --- a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php +++ b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php @@ -1,6 +1,6 @@ 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/'); } } + diff --git a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php index ff1709a0..d8437c50 100644 --- a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php +++ b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php @@ -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(); diff --git a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php index 9de60529..70ca7cea 100644 --- a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php +++ b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php @@ -1,12 +1,13 @@ markTestSkipped('mysql tests are disabled'); } if (self::$init) { @@ -34,3 +35,4 @@ class CacheResourceCustomMysqlTest extends CacheResourceTestCommon $this->initMysqlCache(); } } + diff --git a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php index 879f4f43..5ad16b0d 100644 --- a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php +++ b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php @@ -1,6 +1,6 @@ markTestSkipped('mysql Pdo tests are disabled'); } if (self::$init) { @@ -38,3 +38,4 @@ class CacheResourceCustomPDOTest extends CacheResourceTestCommon $this->initMysqlCache(); } } + diff --git a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php index 5230231f..b3ed7ec8 100644 --- a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php +++ b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php @@ -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(); } } + diff --git a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php index d7be7e6e..653930e6 100644 --- a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php +++ b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php @@ -1,6 +1,6 @@ markTestSkipped('mysql tests are disabled'); } if (self::$init) { @@ -37,3 +37,4 @@ class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon $this->initMysqlCache(); } } + diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php index e247c847..e061c5ab 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php @@ -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); - } -} +} \ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php index 0b91267f..2d071a29 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php @@ -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)); } +} - } diff --git a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php b/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php index a9557073..2808e3b2 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php @@ -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 diff --git a/tests/config.xml b/tests/config.xml deleted file mode 100644 index 79c89ff7..00000000 --- a/tests/config.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - true - - false - false - false - false - false - - - false - - - mysql:dbname=test;host=localhost - smarty - - - \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 7fdbe1a7..b721df6e 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -9,6 +9,19 @@ beStrictAboutOutputDuringTests="true" stopOnFailure="false"> + + + + + + + + + + + + +