Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 66d8a5d

Browse files
committed
Update
1 parent 1b7bf53 commit 66d8a5d

File tree

13 files changed

+122
-135
lines changed

13 files changed

+122
-135
lines changed

Bootstrap.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
* Smarty PHPUnit Bootstrap
88
*/
99
// Locate SmartyBC class and load it
10-
if (is_file(__DIR__ . '/../smarty/libs/SmartyBC.class.php')) {
11-
require_once __DIR__ . '/../smarty/libs/SmartyBC.class.php';
12-
} elseif (is_file(__DIR__ . '/../libs/SmartyBC.class.php')) {
13-
require_once __DIR__ . '/../libs/SmartyBC.class.php';
10+
if (is_file(__DIR__ . '/../smarty/libs/Autoloader.php')) {
11+
require_once __DIR__ . '/../smarty/libs/Autoloader.php';
12+
} elseif (is_file(__DIR__ . '/../libs/Autoloader.php')) {
13+
require_once __DIR__ . '/../libs/Autoloader.php';
1414
} else {
1515
throw new Exception('can not locate Smarty distribution');
1616
}
17+
Smarty_Autoloader::register(true);
1718
if (!defined('SMARTY_COMPOSER_INSTALL')) {
1819
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
1920
if (file_exists($file)) {
@@ -26,7 +27,11 @@
2627
if (!class_exists('PHPUnit_Framework_TestCase')) {
2728
require_once SMARTY_COMPOSER_INSTALL;
2829
}
30+
2931
require_once 'PHPUnit_Smarty.php';
30-
ini_set('date.timezone', 'UTC');
32+
if (!ini_get('date.timezone')) {
33+
ini_set('date.timezone', 'UTC');
34+
}
35+
3136

3237

PHPUnit_Smarty.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,7 @@ public static function setUpBeforeClass()
8282
{
8383
error_reporting(E_ALL | E_STRICT);
8484
self::$init = true;
85-
//self::$pdo = null;
86-
if (self::$config == null) {
87-
$xml = simplexml_load_file(__DIR__ . '/config.xml');
88-
$json_string = json_encode($xml);
89-
self::$config = json_decode($json_string, true);
90-
if (empty(self::$config['mysql']['DB_PASSWD'])) {
91-
self::$config['mysql']['DB_PASSWD'] = null;
92-
}
93-
}
94-
}
85+
}
9586

9687
/**
9788
* This method is called after the last test of this test class is run.
@@ -133,7 +124,7 @@ public function setUpSmarty($dir = null)
133124
if (!is_dir($dir . '/configs')) {
134125
mkdir($dir . '/configs');
135126
}
136-
if (self::$config['individualFolders'] != 'true') {
127+
if (individualFolders != 'true') {
137128
$dir = __DIR__;
138129
}
139130
if (!is_dir($dir . '/templates_c')) {
@@ -150,15 +141,15 @@ public function setUpSmarty($dir = null)
150141
// instance Smarty class
151142
if ($this->loadSmarty) {
152143
$this->smarty = new Smarty;
153-
if (self::$config['individualFolders'] != 'true') {
144+
if (individualFolders != 'true') {
154145
$this->smarty->setCompileDir(__DIR__ . '/templates_c');
155146
$this->smarty->setCacheDir(__DIR__ . '/cache');
156147
}
157148
}
158149
// instance SmartyBC class
159150
if ($this->loadSmartyBC) {
160151
$this->smartyBC = new SmartyBC;
161-
if (self::$config['individualFolders'] != 'true') {
152+
if (individualFolders != 'true') {
162153
$this->smartyBC->setCompileDir(__DIR__ . '/templates_c');
163154
$this->smartyBC->setCacheDir(__DIR__ . '/cache');
164155
}
@@ -173,7 +164,7 @@ final public function getConnection()
173164
{
174165
if (PHPUnit_Smarty::$pdo == null) {
175166
try {
176-
PHPUnit_Smarty::$pdo = new PDO(self::$config['mysql']['DB_DSN'], self::$config['mysql']['DB_USER'], self::$config['mysql']['DB_PASSWD']);
167+
PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD);
177168
}
178169
catch (PDOException $e) {
179170
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());

UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Smarty PHPunit tests for cache resource file
3+
* Smarty PHPunit tests for cache resource Apc
44
*
55
* @package PHPunit
66
* @author Uwe Tews
@@ -15,9 +15,9 @@
1515
*/
1616
class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest
1717
{
18-
public function setUp()
18+
public function setUp()
1919
{
20-
if (self::$config['cacheResource']['ApcEnable'] != 'true') {
20+
if (ApcCacheEnable != true) {
2121
$this->markTestSkipped('Apc tests are disabled');
2222
} else {
2323
if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) {
@@ -30,3 +30,4 @@ public function setUp()
3030
$this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/');
3131
}
3232
}
33+

UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
2222
*/
2323
public function setUp()
2424
{
25-
if (self::$config['cacheResource']['MemcacheEnable'] != 'true') {
25+
if (MemCacheEnable != true) {
2626
$this->markTestSkipped('Memcache tests are disabled');
2727
} else {
2828
if (!class_exists('Memcache')) {
@@ -34,7 +34,6 @@ public function setUp()
3434
$this->smarty->setCachingType('memcachetest');
3535
}
3636

37-
3837
public function testInit()
3938
{
4039
$this->cleanDirs();

UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22
/**
3-
* Smarty PHPunit tests for cache resource file
3+
* Smarty PHPunit tests for cache resource mysql
44
*
55
* @package PHPunit
66
* @author Uwe Tews
77
*/
88

99
include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php';
10+
1011
/**
1112
* class for cache resource file tests
1213
*
@@ -17,7 +18,7 @@ class CacheResourceCustomMysqlTest extends CacheResourceTestCommon
1718

1819
public function setUp()
1920
{
20-
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
21+
if (MysqlCacheEnable != true) {
2122
$this->markTestSkipped('mysql tests are disabled');
2223
}
2324
if (self::$init) {
@@ -34,3 +35,4 @@ public function testInit()
3435
$this->initMysqlCache();
3536
}
3637
}
38+

UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Smarty PHPunit tests for cache resource file
3+
* Smarty PHPunit tests for cache resource Pdo
44
*
55
* @package PHPunit
66
* @author Uwe Tews
@@ -18,7 +18,7 @@ class CacheResourceCustomPDOTest extends CacheResourceTestCommon
1818

1919
public function setUp($dir = null, $clear = true)
2020
{
21-
if (self::$config['cacheResource']['PdoEnable'] != 'true') {
21+
if (PdoCacheEnable != true) {
2222
$this->markTestSkipped('mysql Pdo tests are disabled');
2323
}
2424
if (self::$init) {
@@ -38,3 +38,4 @@ public function testInit()
3838
$this->initMysqlCache();
3939
}
4040
}
41+

UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon
1818

1919
public function setUp($dir = null, $clear = true)
2020
{
21-
if (self::$config['cacheResource']['PdoGzipEnable'] != 'true') {
21+
if (PdoGzipCacheEnable != truw) {
2222
$this->markTestSkipped('mysql Pdo Gzip tests are disabled');
2323
}
2424
if (self::$init) {
@@ -38,3 +38,4 @@ public function testInit()
3838
$this->initMysqlCache();
3939
}
4040
}
41+

UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Smarty PHPunit tests for cache resource file
3+
* Smarty PHPunit tests for cache resource registered
44
*
55
* @package PHPunit
66
* @author Uwe Tews
@@ -16,7 +16,7 @@ class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon
1616
{
1717
public function setUp()
1818
{
19-
if (self::$config['cacheResource']['MysqlEnable'] != 'true') {
19+
if (MysqlCacheEnable != true) {
2020
$this->markTestSkipped('mysql tests are disabled');
2121
}
2222
if (self::$init) {
@@ -37,3 +37,4 @@ public function testInit()
3737
$this->initMysqlCache();
3838
}
3939
}
40+

UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,83 @@
55
* @package PHPunit
66
* @author Uwe Tews
77
*/
8-
9-
/**
10-
* class for resource plugins tests
11-
*
12-
* @backupStaticAttributes enabled
13-
*/
14-
class ResourceMysqlPluginTest extends PHPUnit_Smarty
15-
{
16-
public function setUp()
8+
if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
9+
/**
10+
* class for resource plugins tests
11+
*
12+
* @backupStaticAttributes enabled
13+
*/
14+
class ResourceMysqlPluginTest extends PHPUnit_Smarty
1715
{
18-
if (self::$config['resource']['MysqlEnable'] != 'true') {
19-
$this->markTestSkipped('mysql tests are disabled');
16+
public function setUp()
17+
{
18+
if (self::$init) {
19+
$this->getConnection();
20+
}
21+
$this->setUpSmarty(__DIR__);
2022
}
21-
if (self::$init) {
22-
$this->getConnection();
23-
}
24-
$this->setUpSmarty(__DIR__);
25-
}
2623

24+
public function testInit()
25+
{
26+
$this->cleanDirs();
27+
$this->initMysqlResource();
28+
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '2010-12-25 22:00:00', '{\$x = \'hello world\'}{\$x}' )");
29+
}
2730

28-
public function testInit()
29-
{
30-
$this->cleanDirs();
31-
$this->initMysqlResource();
32-
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '2010-12-25 22:00:00', '{\$x = \'hello world\'}{\$x}' )");
33-
}
31+
/**
32+
* test resource plugin rendering of a custom resource
33+
*/
34+
public function testResourcePluginMysql()
35+
{
36+
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
37+
$this->smarty->addPluginsDir("./PHPunitplugins/");
38+
$this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl'));
39+
}
3440

35-
/**
36-
* test resource plugin rendering of a custom resource
37-
*/
38-
public function testResourcePluginMysql()
39-
{
40-
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
41-
$this->smarty->addPluginsDir("./PHPunitplugins/");
42-
$this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl'));
43-
}
41+
/**
42+
* test resource plugin timestamp of a custom resource
43+
*/
44+
public function testResourcePluginMysqlTimestamp()
45+
{
46+
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
47+
$this->smarty->addPluginsDir("./PHPunitplugins/");
48+
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
49+
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
50+
}
4451

45-
/**
46-
* test resource plugin timestamp of a custom resource
47-
*/
48-
public function testResourcePluginMysqlTimestamp()
49-
{
50-
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
51-
$this->smarty->addPluginsDir("./PHPunitplugins/");
52-
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
53-
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
54-
}
52+
/**
53+
* test resource plugin compiledFilepath of a custom resource
54+
*/
55+
public function testResourcePluginMysqlCompiledFilepath()
56+
{
57+
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
58+
$this->smarty->addPluginsDir("./PHPunitplugins/");
59+
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
60+
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
61+
}
5562

56-
/**
57-
* test resource plugin compiledFilepath of a custom resource
58-
*/
59-
public function testResourcePluginMysqlCompiledFilepath()
60-
{
61-
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
62-
$this->smarty->addPluginsDir("./PHPunitplugins/");
63-
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
64-
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0))
65-
, $tpl->compiled->filepath
66-
);
67-
}
63+
public function testResourcePluginMysqlCompiledFilepathCache()
64+
{
65+
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
66+
$this->smarty->addPluginsDir("./PHPunitplugins/");
67+
$this->smarty->caching = true;
68+
$this->smarty->cache_lifetime = 1000;
69+
$this->smarty->setForceCompile(true);
70+
$this->smarty->fetch('mysqltest:test.tpl');
71+
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
72+
$this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
73+
$this->smarty->caching = false;
74+
}
6875

69-
public function testResourcePluginMysqlCompiledFilepathCache()
70-
{
71-
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
72-
$this->smarty->addPluginsDir("./PHPunitplugins/");
73-
$this->smarty->caching = true;
74-
$this->smarty->cache_lifetime = 1000;
75-
$this->smarty->setForceCompile(true);
76-
$this->smarty->fetch('mysqltest:test.tpl');
77-
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
78-
$this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0))
79-
, $tpl->compiled->filepath
80-
);
81-
$this->smarty->caching = false;
82-
}
83-
/**
84-
* test resource plugin timestamp of a custom resource with only fetch() implemented
85-
*/
86-
public function testResourcePluginMysqlTimestampWithoutFetchTimestamp()
87-
{
88-
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
89-
$this->smarty->addPluginsDir("./PHPunitplugins/");
90-
$tpl = $this->smarty->createTemplate('mysqlstest:test.tpl');
91-
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
76+
/**
77+
* test resource plugin timestamp of a custom resource with only fetch() implemented
78+
*/
79+
public function testResourcePluginMysqlTimestampWithoutFetchTimestamp()
80+
{
81+
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
82+
$this->smarty->addPluginsDir("./PHPunitplugins/");
83+
$tpl = $this->smarty->createTemplate('mysqlstest:test.tpl');
84+
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->timestamp);
85+
}
9286
}
93-
}
87+
}

0 commit comments

Comments
 (0)