summaryrefslogtreecommitdiff
path: root/tests/UnitTests/ResourceTests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/UnitTests/ResourceTests')
-rw-r--r--tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php59
-rw-r--r--tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php52
-rw-r--r--tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php52
-rw-r--r--tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php18
-rw-r--r--tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php19
-rw-r--r--tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php49
-rw-r--r--tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php16
-rw-r--r--tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php32
-rw-r--r--tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php114
-rw-r--r--tests/UnitTests/ResourceTests/File/FileResourceTest.php132
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php67
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore2
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php43
-rw-r--r--tests/UnitTests/ResourceTests/Php/PhpResourceTest.php301
-rw-r--r--tests/UnitTests/ResourceTests/Php/cache/.gitignore2
-rw-r--r--tests/UnitTests/ResourceTests/Php/templates/includephp.tpl1
-rw-r--r--tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php1
-rw-r--r--tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php1
-rw-r--r--tests/UnitTests/ResourceTests/Php/templates_c/.gitignore2
-rw-r--r--tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php34
-rw-r--r--tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php11
-rw-r--r--tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php11
-rw-r--r--tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php12
-rw-r--r--tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php13
-rw-r--r--tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php15
-rw-r--r--tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php35
-rw-r--r--tests/UnitTests/ResourceTests/String/StringResourceTest.php33
37 files changed, 268 insertions, 870 deletions
diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php
index 326dbfc2..610d8de3 100644
--- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php
+++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php
@@ -2,16 +2,12 @@
/**
* Smarty PHPunit tests for File resources
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for file resource tests
- *
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
*/
class CustomResourceAmbiguousTest extends PHPUnit_Smarty
{
@@ -46,76 +42,59 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
public function testNone()
{
- $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
+ $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
- $this->smarty->setAllowAmbiguousResources(true);
+// $this->smarty->setAllowAmbiguousResources(true);
$tpl = $this->smarty->createTemplate('foobar.tpl');
- $this->assertFalse($tpl->source->exists);
+ $this->assertFalse($tpl->getSource()->exists);
}
- /**
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
public function testCase1()
{
- $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
+ $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
- $this->smarty->setAllowAmbiguousResources(true);
+// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
- $this->assertTrue($tpl->source->exists);
- $this->assertEquals('case1', $tpl->source->getContent());
+ $this->assertTrue($tpl->getSource()->exists);
+ $this->assertEquals('case1', $tpl->getSource()->getContent());
}
- /**
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
public function testCase2()
{
- $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
+ $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
- $this->smarty->setAllowAmbiguousResources(true);
+// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
- $this->assertTrue($tpl->source->exists);
- $this->assertEquals('case2', $tpl->source->getContent());
+ $this->assertTrue($tpl->getSource()->exists);
+ $this->assertEquals('case2', $tpl->getSource()->getContent());
}
- /**
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
+
public function testCaseSwitching()
{
- $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
+ $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
- $this->smarty->setAllowAmbiguousResources(true);
+// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
- $this->assertTrue($tpl->source->exists);
- $this->assertEquals('case1', $tpl->source->getContent());
+ $this->assertTrue($tpl->getSource()->exists);
+ $this->assertEquals('case1', $tpl->getSource()->getContent());
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
- $this->assertTrue($tpl->source->exists);
- $this->assertEquals('case2', $tpl->source->getContent());
+ $this->assertTrue($tpl->getSource()->exists);
+ $this->assertEquals('case2', $tpl->getSource()->getContent());
}
}
diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php
index 934b8aa0..85ffadd5 100644
--- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php
+++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php
@@ -1,12 +1,18 @@
<?php
+use Smarty\Exception;
+use Smarty\Resource\FilePlugin;
+use Smarty\Smarty;
+use Smarty\Template;
+use Smarty\Template\Source;
+
/**
* Ambiguous Filename Custom Resource Example
*
- * @package Resource-examples
+
* @author Rodney Rehm
*/
-class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
+class Smarty_Resource_AmbiguousPlugin extends FilePlugin
{
protected $directory;
protected $segment;
@@ -23,36 +29,38 @@ class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
}
/**
- * 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
+ * @param Source $source source object
+ * @param Template $_template template object
*/
- public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
+ public function populate(Source $source, Template $_template = null)
{
$segment = '';
if ($this->segment) {
$segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR;
}
- $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->uid = sha1($segment . '#' . $source->getResourceName());
+ if ($_template->getSmarty()->getCompileCheck() && !isset($source->timestamp)) {
+ $source->timestamp = @filemtime($this->directory . $segment . $source->name);
$source->exists = !!$source->timestamp;
}
}
+
+ public function getContent(Source $source) {
+
+ $segment = '';
+ if ($this->segment) {
+ $segment = rtrim($this->segment, "/\\") . DIRECTORY_SEPARATOR;
+ }
+
+ if ($source->exists) {
+ return file_get_contents($this->directory . $segment . $source->name);
+ }
+ throw new Exception(
+ 'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
+ " {$source->type} '{$source->name}'"
+ );
+ }
}
diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php
index 5e81a8c3..0cbbfce0 100644
--- a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php
+++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php
@@ -2,16 +2,18 @@
/**
* Smarty PHPUnit tests demo resource plugin extendsall
*
- * @package PHPunit
+
* @author Uwe Tews
*/
+require_once __DIR__ . '/../../../__shared/resources/resource.extendsall.php';
+
/**
* class for demo resource plugin extendsall tests
*
- * @runTestsInSeparateProcess
+ *
* @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
*/
class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
{
@@ -27,13 +29,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsall()
{
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3',
'./templates_4',));
@@ -44,15 +43,12 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall
* changed tepmplate_setting
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsall2()
{
- $this->smarty->setMergeCompiledIncludes(true);
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
+ $this->smarty->setMergeCompiledIncludes(true);
$this->smarty->setTemplateDir(array('./templates_3', './templates_4',));
$expected = "templates_3templates_3templates_3templates_4";
@@ -61,7 +57,7 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
public function testResourcePluginExtendsallOne()
{
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3',
'./templates_4',));
@@ -71,13 +67,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication()
{
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
@@ -86,13 +79,10 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication2()
{
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
@@ -101,14 +91,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication3()
{
$this->smarty->setMergeCompiledIncludes(true);
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
@@ -117,14 +104,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication4()
{
$this->smarty->setMergeCompiledIncludes(true);
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
@@ -133,14 +117,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication5()
{
$this->smarty->setMergeCompiledIncludes(true);
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
@@ -149,14 +130,11 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
/**
* test extendsall special application
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testResourcePluginExtendsallSpecialApplication6()
{
$this->smarty->setMergeCompiledIncludes(true);
- $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
+ $this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
$this->smarty->setDefaultResourceType('extendsall');
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php
deleted file mode 100644
index f64ab457..00000000
--- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqlstest.php
+++ /dev/null
@@ -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');
- }
-}
-
diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php
deleted file mode 100644
index 2b05da9d..00000000
--- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/PHPunitplugins/resource.mysqltest.php
+++ /dev/null
@@ -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');
- }
-}
-
diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php
index 6309eff9..16d85489 100644
--- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php
+++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php
@@ -2,20 +2,20 @@
/**
* Smarty PHPunit tests resource plugins
*
- * @package PHPunit
+
* @author Uwe Tews
*/
if (MysqlResourceEnable == true) {
/**
* class for resource plugins tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class ResourceMysqlPluginTest extends PHPUnit_Smarty
{
- public function setUp()
+ public function setUp(): void
{
if (MysqlResourceEnable != true) {
$this->markTestSkipped('Msqlresource tests are disabled');
@@ -39,10 +39,6 @@ if (MysqlResourceEnable == true) {
/**
* test resource plugin rendering of a custom resource
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testResourcePluginMysql()
{
@@ -51,10 +47,6 @@ if (MysqlResourceEnable == true) {
/**
* test must compile
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testMustCompile()
{
@@ -62,12 +54,9 @@ if (MysqlResourceEnable == true) {
$this->assertFalse($tpl->mustCompile());
}
- /**
+ /**
* test must compile
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
+ * @group slow
*/
public function testMustCompile2()
{
@@ -79,10 +68,6 @@ if (MysqlResourceEnable == true) {
/**
* test resource plugin rendering of a custom resource
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testResourcePluginMysql2()
{
@@ -91,10 +76,6 @@ if (MysqlResourceEnable == true) {
/**
* test clear compiled
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testClearCompiled()
{
@@ -103,10 +84,6 @@ if (MysqlResourceEnable == true) {
/**
* test must compile
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testMustCompile3()
{
@@ -121,7 +98,7 @@ if (MysqlResourceEnable == true) {
{
//$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);
+ $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
}
public function testResourcePluginMysqlCompiledFilepathCache()
@@ -131,20 +108,16 @@ if (MysqlResourceEnable == true) {
$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->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
$this->smarty->caching = false;
}
/**
* test unknown template
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testUnknownTemplate() {
- $this->expectException('SmartyException');
- $this->expectExceptionMessage('Unable to load template \'mysqlstest:foo.tpl\'');
+ $this->expectException(\Smarty\Exception::class);
+ $this->expectExceptionMessage('Unable to load \'mysqlstest:foo.tpl\'');
$this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl'));
}
}
diff --git a/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php b/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php
index 64c7174b..f2073507 100644
--- a/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php
+++ b/tests/UnitTests/ResourceTests/DefaultHandler/DefaultTemplateHandlerTest.php
@@ -2,16 +2,16 @@
/**
* Smarty PHPunit tests deault template handler
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for block plugin tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class DefaultTemplateHandlerTest extends PHPUnit_Smarty
{
@@ -36,7 +36,7 @@ class DefaultTemplateHandlerTest extends PHPUnit_Smarty
$this->smarty->fetch('foo.tpl');
}
catch (Exception $e) {
- $this->assertStringContainsString('Unable to load template', $e->getMessage());
+ $this->assertStringContainsString('Unable to load', $e->getMessage());
return;
}
@@ -93,7 +93,7 @@ class DefaultTemplateHandlerTest extends PHPUnit_Smarty
}
}
-function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
+function my_template_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty)
{
$output = "Recsource $resource_name of type $resource_type not found";
$template_source = $output;
@@ -102,12 +102,12 @@ function my_template_handler($resource_type, $resource_name, &$template_source,
return true;
}
-function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
+function my_template_handler_file($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty)
{
return $smarty->getTemplateDir(0) . 'helloworld.tpl';
}
-function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
+function my_false($resource_type, $resource_name, &$template_source, &$template_timestamp, \Smarty\Smarty $smarty)
{
return false;
}
diff --git a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php
index d8cd146d..f4bad162 100644
--- a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php
+++ b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php
@@ -2,16 +2,16 @@
/**
* Smarty PHPunit tests for eval resources
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for eval resource tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class EvalResourceTest extends PHPUnit_Smarty
{
@@ -31,7 +31,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testTemplateEvalExists1()
{
$tpl = $this->smarty->createTemplate('eval:{$foo}');
- $this->assertTrue($tpl->source->exists);
+ $this->assertTrue($tpl->getSource()->exists);
}
public function testTemplateEvalExists2()
@@ -39,22 +39,16 @@ class EvalResourceTest extends PHPUnit_Smarty
$this->assertTrue($this->smarty->templateExists('eval:{$foo}'));
}
- /**
- * test getTemplateFilepath
- */
- public function testGetTemplateFilepath()
+ public function testGetTemplateResourceName()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertEquals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', $tpl->source->filepath);
+ $this->assertEquals('hello world', $tpl->getSource()->getResourceName());
}
- /**
- * test getTemplateTimestamp
- */
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertTrue($tpl->source->getTimeStamp());
+ $this->assertTrue($tpl->getSource()->getTimeStamp());
}
/**
@@ -63,7 +57,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('eval:hello world{$foo}');
- $this->assertEquals('hello world{$foo}', $tpl->source->getContent());
+ $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
}
/**
@@ -81,7 +75,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertFalse($tpl->source->handler->uncompiled);
+ $this->markTestIncomplete();
}
/**
@@ -90,7 +84,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertTrue($tpl->source->handler->recompiled);
+ $this->assertTrue($tpl->getSource()->handler->recompiled);
}
/**
@@ -108,7 +102,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertFalse($tpl->compiled->filepath);
+ $this->assertNull($tpl->getCompiled()->filepath);
}
/**
@@ -117,7 +111,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
- $this->assertFalse($tpl->compiled->getTimeStamp());
+ $this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**
diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php
index e3816d12..2ef17719 100644
--- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php
+++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php
@@ -2,16 +2,14 @@
/**
* Smarty PHPunit tests for Extendsresource
*
- * @package PHPunit
+
* @author Uwe Tews
*/
+use Smarty\Template;
+
/**
* class for extends resource tests
- *
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
*/
class ExtendsResourceTest extends PHPUnit_Smarty
{
@@ -27,15 +25,13 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->cleanDirs();
}
- public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
+ public function compiledPrefilter($text, Template $tpl)
{
return str_replace('#', $tpl->getTemplateVars('test'), $text);
}
/**
* test child/parent template chain with prepend
- * @runInSeparateProcess
- * @preserveGlobalState disabled
* @dataProvider data
*/
public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
@@ -45,16 +41,20 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
- $this->smarty->compile_id = 1;
+ $this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
- $this->assertStringContainsString("prepend - Default Title", $result, $testName . ' - content');
- $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
+ $this->assertStringContainsString(
+ "prepend - Default Title", $result, $testName . ' - content');
+ $this->assertStringContainsString(
+ "test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}",
+ $result,
+ $testName . ' - fetch() failure'
+ );
}
+
/**
* test child/parent template chain with apppend
- * @run InSeparateProcess
- * @preserveGlobalState disabled
* @dataProvider data
*/
public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
@@ -64,7 +64,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
- $this->smarty->compile_id = 1;
+ $this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl');
$this->assertStringContainsString("Default Title - append", $result, $testName . ' - content');
@@ -73,8 +73,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test child/parent template chain with apppend
- * @runInSeparateProcess
- * @preserveGlobalState disabled
* @dataProvider data
*/
public function testCompileBlockAssignInChild_040($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
@@ -84,7 +82,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
- $this->smarty->compile_id = 1;
+ $this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:040_parent.tpl|040_child.tpl');
$this->assertStringContainsString("var-bar-var", $result, $testName . ' - content');
@@ -101,7 +99,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
- $this->smarty->compile_id = 1;
+ $this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:050_parent.tpl|050_child.tpl|050_grandchild.tpl');
$this->assertStringContainsString("var-bar-var", $result, $testName . ' - content');
@@ -110,8 +108,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test1
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testCompileBlockGrandChildMustCompile_021_1()
{
@@ -125,8 +121,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test1
- * @runInSeparateProcess
- * @preserveGlobalState disabled
*/
public function testCompileBlockGrandChildMustCompile_021_12()
{
@@ -140,8 +134,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test2
- * @runInSeparateProcess
- * @preserveGlobalState disabled
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_2()
@@ -158,9 +150,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
}
/**
* test grandchild/child/parent dependency test2
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testCompileBlockGrandChildMustCompile_021_22()
{
@@ -174,9 +163,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test3
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
+ * @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_3()
{
@@ -192,9 +179,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
}
/**
* test grandchild/child/parent dependency test3
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testCompileBlockGrandChildMustCompile_021_32()
{
@@ -208,8 +192,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test4
- * @runInSeparateProcess
- * @preserveGlobalState disabled
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_4()
@@ -226,9 +208,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
}
/**
* test grandchild/child/parent dependency test4
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
*/
public function testCompileBlockGrandChildMustCompile_021_42()
{
@@ -242,9 +221,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test relative includes in {block}
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
* @dataProvider data
*/
public function testCompileBlockRelativeIncludes_033($caching, $merge, $testNumber, $compileTestNumber,
@@ -276,7 +252,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
*/
array(false, false, 1, 1, 1, 'no caching, no merge - new'),
array(false, false, 2, 1, 2, 'no caching, no merge - exits'),
- array(true, false, 3, 3, 3, 'caching, no merge - new'), // 2
+ array(true, false, 3, 3, 3, 'caching, no merge - new'),
array(true, false, 4, 3, 3, 'caching, no merge - exits'),
array(false, true, 5, 5, 5, 'no caching, merge - new'),
array(false, true, 6, 5, 6, 'no caching, merge - exits'),
@@ -284,60 +260,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty
array(true, true, 8, 7, 7, 'caching, merge - exits'),
);
}
- /**
- * test relative includes in {block}
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- * @dataProvider data2
- */
- public function testCompileBlockExtendsRecursion_034($extends_recursion, $merge, $testNumber, $compileTestNumber,
- $renderTestNumber, $testName)
- {
- if (!property_exists($this->smarty, 'extends_recursion')) {
- $this->markTestSkipped('no extends_recursion');
- } else {
- $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
- $this->smarty->assign('test', $testNumber);
- $this->smarty->setExtendsRecursion($extends_recursion);
- $this->smarty->setMergeCompiledIncludes($merge);
- $cid = 0;
- if ($merge) {
- $cid = 1;
- }
- if ($extends_recursion) {
- $cid += 2;
- }
- $this->smarty->setCompileId($cid);
- $result = $this->smarty->fetch('extends:034_parent.tpl|034_grandchild.tpl');
- $this->assertStringContainsString('grandchild - grandchild', $result, $testName . ' - grand');
- $this->assertStringContainsString('parent - parent', $result, $testName . ' - grand');
- $this->assertStringContainsString($extends_recursion ? 'child - child' : 'child - parent', $result,
- $testName . ' - grand');
- $this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}",
- $result, $testName . ' - fetch() failure');
- }
- }
- public function data2(){
- return array(
- /*
- * extends_recursion
- * merging
- * test nr
- * result compile nr
- * result render nr
- * text
- */
- array(false, false, 1, 1, 1, 'no EXTENDS; no merge - new'),
- array(false, false, 2, 1, 2, 'no EXTENDS; no merge - exits'),
- array(true, false, 3, 3, 3, 'EXTENDS; no merge - new'),
- array(true, false, 4, 3, 4, 'EXTENDS; no merge - exits'),
- array(false, true, 5, 5, 5, 'no EXTENDS; merge - new'),
- array(false, true, 6, 5, 6, 'no EXTENDS; merge - exits'),
- array(true, true, 7, 7, 7, 'EXTENDS; merge - new'),
- array(true, true, 8, 7, 8, 'EXTENDS; merge - exits'),
- );
- }
}
diff --git a/tests/UnitTests/ResourceTests/File/FileResourceTest.php b/tests/UnitTests/ResourceTests/File/FileResourceTest.php
index c4e8c069..44201d4b 100644
--- a/tests/UnitTests/ResourceTests/File/FileResourceTest.php
+++ b/tests/UnitTests/ResourceTests/File/FileResourceTest.php
@@ -2,16 +2,18 @@
/**
* Smarty PHPunit tests for File resources
*
- * @package PHPunit
+
* @author Uwe Tews
*/
+use Smarty\Exception;
+
/**
* class for file resource tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class FileResourceTest extends PHPUnit_Smarty
{
@@ -36,16 +38,16 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
*/
- public function testGetTemplateFilepath()
+ public function testGetTemplateResourceName()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertEquals($this->normalizePath("./templates/helloworld.tpl"), $tpl->source->filepath);
+ $this->assertEquals('helloworld.tpl', $tpl->getSource()->getResourceName());
}
public function testTemplateFileExists1()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertTrue($tpl->source->exists);
+ $this->assertTrue($tpl->getSource()->exists);
}
public function testTemplateFileExists2()
@@ -56,7 +58,7 @@ class FileResourceTest extends PHPUnit_Smarty
public function testTemplateFileNotExists1()
{
$tpl = $this->smarty->createTemplate('notthere.tpl');
- $this->assertFalse($tpl->source->exists);
+ $this->assertFalse($tpl->getSource()->exists);
}
public function testTemplateFileNotExists2()
@@ -69,7 +71,7 @@ class FileResourceTest extends PHPUnit_Smarty
*/
public function testTemplateFileNotExists3()
{
- $this->expectException('SmartyException');
+ $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to');
$this->expectExceptionMessage('notthere.tpl');
$this->smarty->fetch('notthere.tpl');
@@ -78,34 +80,26 @@ class FileResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertTrue(is_integer($tpl->source->getTimeStamp()));
- $this->assertEquals(10, strlen($tpl->source->getTimeStamp()));
+ $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
+ $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
}
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertEquals('hello world', $tpl->source->getContent());
+ $this->assertEquals('hello world', $tpl->getSource()->getContent());
}
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertFalse($tpl->source->handler->uncompiled);
+ $this->markTestIncomplete();
}
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertFalse($tpl->source->handler->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
- );
+ $this->assertFalse($tpl->getSource()->handler->recompiled);
}
/**
@@ -115,8 +109,8 @@ class FileResourceTest extends PHPUnit_Smarty
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
// create dummy compiled file
- file_put_contents($tpl->compiled->filepath, '<?php ?>');
- touch($tpl->compiled->filepath, $tpl->source->getTimeStamp());
+ file_put_contents($tpl->getCompiled()->filepath, '<?php ?>');
+ touch($tpl->getCompiled()->filepath, $tpl->getSource()->getTimeStamp());
}
/**
@@ -125,9 +119,9 @@ class FileResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
- $this->assertTrue(is_integer($tpl->compiled->getTimeStamp()));
- $this->assertEquals(10, strlen($tpl->compiled->getTimeStamp()));
- $this->assertEquals($tpl->compiled->getTimeStamp(), $tpl->source->getTimeStamp());
+ $this->assertTrue(is_integer($tpl->getCompiled()->getTimeStamp()));
+ $this->assertEquals(10, strlen($tpl->getCompiled()->getTimeStamp()));
+ $this->assertEquals($tpl->getCompiled()->getTimeStamp(), $tpl->getSource()->getTimeStamp());
}
public function testMustCompileExisting()
@@ -143,18 +137,18 @@ class FileResourceTest extends PHPUnit_Smarty
$this->assertTrue($tpl->mustCompile());
}
- /**
- * @doesNotPerformAssertions
- */
- public function testMustCompileTouchedSourcePrepare()
- {
- // touch to prepare next test
- sleep(2);
- $tpl = $this->smarty->createTemplate('helloworld.tpl');
- touch($tpl->source->filepath);
- }
- public function testMustCompileTouchedSource()
+ /**
+ * @group slow
+ */
+ public function testMustCompileTouchedSource()
{
+ // touch to prepare next test
+ sleep(2);
+ $this->smarty->createTemplate('helloworld.tpl');
+ touch(__DIR__ . '/templates/helloworld.tpl');
+
+ $this->setUp();
+
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->mustCompile());
// clean up for next tests
@@ -165,29 +159,26 @@ class FileResourceTest extends PHPUnit_Smarty
{
$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
- );
+ $this->assertTrue(file_exists($tpl->getCompiled()->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;
+ $this->smarty->caching = true;
+ $this->smarty->cache_lifetime = 1000;
+ $tpl = $this->smarty->createTemplate('helloworld.tpl');
+ $tpl->fetch();
+ $timestamp = $tpl->getCached()->timestamp;
+
+
+ $this->smarty = new \Smarty\Smarty();
+ $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));
+ $this->assertTrue(is_integer($tpl->getCached()->timestamp));
+ $this->assertEquals($timestamp, $tpl->getCached()->timestamp);
}
@@ -206,7 +197,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
- * @preserveGlobalState disabled
+ *
*
*/
public function testRelativeIncludeSub()
@@ -215,26 +206,23 @@ class FileResourceTest extends PHPUnit_Smarty
$this->assertStringContainsString('hello world', $result);
}
/**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
* test relative include fail
*/
public function testRelativeIncludeFail()
{
- $this->expectException('SmartyException');
+ $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to');
$this->smarty->fetch('relative_sub.tpl');
}
/**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
* test relative include fail other dir
*/
public function testRelativeIncludeFailOtherDir()
{
- $this->expectException('SmartyException');
+ $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('./hello.tpl');
$this->smarty->addTemplateDir('./templates_2');
$this->smarty->fetch('relative_notexist.tpl');
@@ -242,8 +230,8 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
*/
public function testRelativeFetch()
@@ -258,8 +246,8 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
*/
public function testRelativeFetch2()
@@ -274,8 +262,8 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
*/
public function testRelativeFetchCwd()
@@ -295,8 +283,8 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
*/
public function testRelativeFetchCwd2()
@@ -331,7 +319,7 @@ class FileResourceTest extends PHPUnit_Smarty
return;
}
- catch (SmartyException $e) {
+ catch (Exception $e) {
// this was expected to fail
}
} else {
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php b/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php
deleted file mode 100644
index 1447ef09..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/FileIncludePathTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-/**
- * Smarty PHPunit tests for File resources
- *
- * @package PHPunit
- * @author Rodney Rehm
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
- */
-class FileIncludePathTest extends PHPUnit_Smarty
-{
- public function setUp(): void
- {
- $this->setUpSmarty(__DIR__);
- $this->smarty->use_include_path = true;
- $this->smarty->setTemplateDir(array('./templates', './templates_2', './include'));
- $this->smarty->enableSecurity();
- $ds = DIRECTORY_SEPARATOR;
- set_include_path($this->smarty->_realpath(__DIR__ . "{$ds}..{$ds}..{$ds}..{$ds}Include_Path{$ds}Tpl{$ds}", true) . PATH_SEPARATOR . get_include_path());
- }
-
- /**
- * Tears down the fixture
- * This method is called after a test is executed.
- *
- */
- protected function tearDown(): void
- {
- ini_restore('include_path');
- $this->smarty->disableSecurity();
- parent::tearDown();
- }
- public function testInit()
- {
- $this->cleanDirs();
- }
- public function testInclude1()
- {
- $this->assertStringContainsString('include_test1', $this->smarty->fetch('test1.tpl'));
- }
- public function testInclude2()
- {
- $this->assertStringContainsString('include_test2', $this->smarty->fetch('test2.tpl'));
- }
- public function testInclude3()
- {
- $this->assertStringContainsString('include_test3', $this->smarty->fetch('test3.tpl'));
- }
- public function testInclude31()
- {
- $this->smarty->use_include_path = false;
- $this->smarty->security_policy->secure_dir = getcwd();
- $this->assertStringContainsString('include_test3', $this->smarty->fetch('test3.tpl'));
- }
- public function testInclude4()
- {
- $this->assertStringContainsString('include_test4', $this->smarty->fetch('test4.tpl'));
- }
- public function testInclude5()
- {
- $this->smarty->setTemplateDir(array('./'));
- $this->assertStringContainsString('include path root', $this->smarty->fetch('test5.tpl'));
- }
-
- }
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore b/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/cache/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl
deleted file mode 100644
index 61298afb..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/include_test3.tpl
+++ /dev/null
@@ -1 +0,0 @@
-include_test3
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl
deleted file mode 100644
index f10e14ab..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/dirname.tpl
+++ /dev/null
@@ -1 +0,0 @@
-templates \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl
deleted file mode 100644
index dcc96887..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test1.tpl
+++ /dev/null
@@ -1 +0,0 @@
-{include 'include_test1.tpl'} \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl
deleted file mode 100644
index b5d41850..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test2.tpl
+++ /dev/null
@@ -1 +0,0 @@
-{include 'include_test2.tpl'} \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl
deleted file mode 100644
index 5d5690be..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates/test3.tpl
+++ /dev/null
@@ -1 +0,0 @@
-{include 'include_test3.tpl'} \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl
deleted file mode 100644
index b6e9ce55..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/dirname.tpl
+++ /dev/null
@@ -1 +0,0 @@
-templates_2 \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl
deleted file mode 100644
index c8d49087..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_2/include_test1.tpl
+++ /dev/null
@@ -1 +0,0 @@
-include_test1
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl
deleted file mode 100644
index 404b4397..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_3/dirname.tpl
+++ /dev/null
@@ -1 +0,0 @@
-templates_3 \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl b/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl
deleted file mode 100644
index b744ef31..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_4/dirname.tpl
+++ /dev/null
@@ -1 +0,0 @@
-templates_4 \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore b/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/ResourceTests/FileIncludePath/templates_c/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php
index 5f8ed76f..9065c10d 100644
--- a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php
+++ b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php
@@ -3,11 +3,11 @@
/**
* Smarty PHPunit tests for File resources
*
- * @package PHPunit
+
* @author Rodney Rehm
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class FileResourceIndexedTest extends PHPUnit_Smarty
{
@@ -25,30 +25,6 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
$this->cleanDirs();
}
- public function testGetTemplateFilepath()
- {
- $tpl = $this->smarty->createTemplate('dirname.tpl');
- $this->assertEquals($this->normalizePath("./templates/dirname.tpl"), $tpl->source->filepath);
- }
-
- public function testGetTemplateFilepathNumber()
- {
- $tpl = $this->smarty->createTemplate('[1]dirname.tpl');
- $this->assertEquals($this->normalizePath('./templates_2/dirname.tpl'), $tpl->source->filepath);
- }
-
- public function testGetTemplateFilepathNumeric()
- {
- $tpl = $this->smarty->createTemplate('[10]dirname.tpl');
- $this->assertEquals($this->normalizePath('./templates_3/dirname.tpl'), $tpl->source->filepath);
- }
-
- public function testGetTemplateFilepathName()
- {
- $tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
- $this->assertEquals($this->normalizePath('./templates_4/dirname.tpl'), $tpl->source->filepath);
- }
-
public function testFetch()
{
$tpl = $this->smarty->createTemplate('dirname.tpl');
@@ -101,15 +77,18 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
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);
+ $tpl2 = $this->smarty->createTemplate('dirname.tpl');
+
+ $this->assertNotEquals($tpl->getCompiled()->filepath, $tpl2->getCompiled()->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);
+ $tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
+ $tpl2 = $this->smarty->createTemplate('dirname.tpl');
+
+ $this->assertNotEquals($tpl->getCached()->filepath, $tpl2->getCached()->filepath);
}
}
diff --git a/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php b/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php
deleted file mode 100644
index fdb62085..00000000
--- a/tests/UnitTests/ResourceTests/Php/PhpResourceTest.php
+++ /dev/null
@@ -1,301 +0,0 @@
-<?php
-/**
- * Smarty PHPunit tests for PHP resources
- *
- * @package PHPunit
- * @author Uwe Tews
- */
-
-/**
- * class for PHP resource tests
- *
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
- */
-class PhpResourceTest extends PHPUnit_Smarty
-{
- public function setUp(): void
- {
- $this->setUpSmarty(__DIR__);
- }
-
- public function testInit()
- {
- $this->cleanDirs();
- }
-
- protected function relative($path)
- {
- $path = str_replace(str_replace("\\", "/", __DIR__), '.', str_replace("\\", "/", $path));
-
- return $path;
- }
-
- /**
- * test getTemplateFilepath
- */
- public function testGetTemplateFilepath()
- {
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertEquals($this->normalizePath("./templates/phphelloworld.php"), $tpl->source->filepath);
- }
-
- /**
- * test getTemplateTimestamp
- */
- public function testGetTemplateTimestamp()
- {
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertTrue(is_integer($tpl->source->getTimeStamp()));
- $this->assertEquals(10, strlen($tpl->source->getTimeStamp()));
- }
-
- /**
- * test getTemplateSource
- *-/
- * public function testGetTemplateSource()
- * {
- * $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- * $this->assertStringContainsString('php hello world', $tpl->source->getContent());
- * }
- * /**
- * test usesCompiler
- */
- public function testUsesCompiler()
- {
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertTrue($tpl->source->handler->uncompiled);
- }
-
- /**
- * test isEvaluated
- */
- public function testIsEvaluated()
- {
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertFalse($tpl->source->handler->recompiled);
- }
-
- /**
- * test mustCompile
- */
- public function testMustCompile()
- {
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertFalse($tpl->mustCompile());
- }
-
- /**
- * test getCachedFilepath
- */
- public function testGetCachedFilepath()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $expected = $this->buildCachedPath($tpl, false, null, null, 'phphelloworld.php', 'php',
- $this->smarty->getTemplateDir(0), 'file');
- $this->assertEquals($expected, $tpl->cached->filepath);
- }
-
- /**
- * test create cache file used by the following tests
- */
- public function testCreateCacheFile()
- {
- // create dummy cache file
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertStringContainsString('php hello world', $this->smarty->fetch($tpl));
- }
-
- /**
- * test getCachedTimestamp caching enabled
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
- public function testGetCachedTimestamp()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertTrue(is_integer($tpl->cached->timestamp));
- $this->assertEquals(10, strlen($tpl->cached->timestamp));
- }
-
- /**
- * test isCached
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
- public function testIsCached()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 10000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertTrue($tpl->isCached());
- }
-
- /**
- * test isCached caching disabled
- */
- public function testIsCachedCachingDisabled()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertFalse($tpl->isCached());
- }
-
- /**
- * test isCached on touched source
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- * @doesNotPerformAssertions
- */
- public function testIsCachedTouchedSourcePrepare()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- sleep(2);
- touch($tpl->source->filepath);
- }
-
- /**
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
- public function testIsCachedTouchedSource()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertFalse($tpl->isCached());
- }
-
- /**
- * test is cache file is written
- */
- public function testWriteCachedContent()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $this->cleanCacheDir();
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->smarty->fetch($tpl);
- $this->assertTrue(file_exists($tpl->cached->filepath));
- }
-
- /**
- * test getRenderedTemplate
- */
- public function testGetRenderedTemplate()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertStringContainsString('php hello world', $tpl->fetch());
- }
-
- /**
- * test $smarty->is_cached
- * @doesNotPerformAssertions
- */
- public function testSmartyIsCachedPrepare()
- {
- // clean up for next tests
- $this->cleanCacheDir();
- $this->smarty->setAllowPhpTemplates(true);
- // prepare files for next test
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->smarty->fetch($tpl);
- }
-
- /**
- *
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- *
- */
- public function testSmartyIsCached()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertTrue($this->smarty->isCached($tpl));
- }
-
- /**
- * test $smarty->is_cached caching disabled
- */
- public function testSmartyIsCachedCachingDisabled()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $tpl = $this->smarty->createTemplate('php:phphelloworld.php');
- $this->assertFalse($this->smarty->isCached($tpl));
- }
-
- public function testGetTemplateFilepathName()
- {
- $this->smarty->addTemplateDir('./templates_2', 'foo');
- $tpl = $this->smarty->createTemplate('php:[foo]helloworld.php');
- $this->assertEquals('./templates_2/helloworld.php', $this->relative($tpl->source->filepath));
- }
-
- public function testGetCachedFilepathName()
- {
- $this->smarty->addTemplateDir('./templates_2', 'foo');
- $this->smarty->caching = true;
- $this->smarty->cache_lifetime = 1000;
- $tpl = $this->smarty->createTemplate('php:[foo]helloworld.php');
- $path = $tpl->cached->filepath;
- $expected = $this->buildCachedPath($tpl, false, null, null, 'helloworld.php', 'php',
- $this->smarty->getTemplateDir('foo'), 'file');
- $this->assertEquals($expected, $path);
- }
-
- /**
- * test {include} php resource
- */
- public function testIncludePhpTemplate()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->assertStringContainsString('php hello world', $this->smarty->fetch('includephp.tpl'));
- }
-
- /**
- * test {include} php resource caching
- */
- public function testIncludePhpTemplateCaching()
- {
- $this->smarty->caching = true;
- $this->smarty->setAllowPhpTemplates(true);
- $this->assertStringContainsString('php hello world', $this->smarty->fetch('includephp.tpl'));
- }
-
- /**
- * test clearCompiledTemplate()
- */
- public function testClearCompiled()
- {
- $this->smarty->setAllowPhpTemplates(true);
- $this->assertEquals(0, $this->smarty->clearCompiledTemplate('php:phphelloworld.php'));
- }
-
-}
diff --git a/tests/UnitTests/ResourceTests/Php/cache/.gitignore b/tests/UnitTests/ResourceTests/Php/cache/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/ResourceTests/Php/cache/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl b/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl
deleted file mode 100644
index 5baa76d2..00000000
--- a/tests/UnitTests/ResourceTests/Php/templates/includephp.tpl
+++ /dev/null
@@ -1 +0,0 @@
-{include 'php:phphelloworld.php'} \ No newline at end of file
diff --git a/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php b/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php
deleted file mode 100644
index 6fe5b4ba..00000000
--- a/tests/UnitTests/ResourceTests/Php/templates/phphelloworld.php
+++ /dev/null
@@ -1 +0,0 @@
-php hello world
diff --git a/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php b/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php
deleted file mode 100644
index 6fe5b4ba..00000000
--- a/tests/UnitTests/ResourceTests/Php/templates_2/helloworld.php
+++ /dev/null
@@ -1 +0,0 @@
-php hello world
diff --git a/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore b/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore
deleted file mode 100644
index d88cc144..00000000
--- a/tests/UnitTests/ResourceTests/Php/templates_c/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Ignore anything in here, but keep this directory
-*
diff --git a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php
index 1f62bc4c..407aa461 100644
--- a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php
+++ b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php
@@ -2,16 +2,18 @@
/**
* Smarty PHPunit tests register->resource
*
- * @package PHPunit
+
* @author Uwe Tews
*/
+use Smarty\Resource\CustomPlugin;
+
/**
* class for register->resource tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class RegisteredResourceTest extends PHPUnit_Smarty
{
@@ -20,7 +22,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
{
$this->setUpSmarty(__DIR__);
- $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1());
+ $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1Plugin());
}
@@ -47,8 +49,8 @@ class RegisteredResourceTest extends PHPUnit_Smarty
public function testResourcePluginTimestamp()
{
$tpl = $this->smarty->createTemplate('rr:test');
- $this->assertTrue(is_integer($tpl->source->getTimeStamp()));
- $this->assertEquals(10, strlen($tpl->source->getTimeStamp()));
+ $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
+ $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
}
/**
@@ -56,11 +58,11 @@ class RegisteredResourceTest extends PHPUnit_Smarty
*/
public function testResourceCompileIdChange()
{
- $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2());
- $this->smarty->compile_id = 'a';
+ $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2Plugin());
+ $this->smarty->setCompileId('a');
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
- $this->smarty->compile_id = 'b';
+ $this->smarty->setCompileId('b');
$this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some'));
$this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some'));
}
@@ -69,7 +71,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
*
*/
public function testSmartyTemplate() {
- $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3());
+ $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3Plugin());
$this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo'));
}
/**
@@ -77,12 +79,12 @@ class RegisteredResourceTest extends PHPUnit_Smarty
*
*/
public function testSmartyCurrentDir() {
- $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4());
+ $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4Plugin());
$this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar'));
}
}
-class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom {
+class RegisteredResourceTest_Resource1Plugin extends CustomPlugin {
protected function fetch($name, &$source, &$mtime) {
$source = '{$x="hello world"}{$x}';
@@ -91,7 +93,7 @@ class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom {
}
-class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom {
+class RegisteredResourceTest_Resource2Plugin extends CustomPlugin {
protected function fetch($name, &$source, &$mtime) {
@@ -112,7 +114,7 @@ class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom {
}
-class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom {
+class RegisteredResourceTest_Resource3Plugin extends CustomPlugin {
protected function fetch($name, &$source, &$mtime) {
$source = 'template = {$smarty.template}';
@@ -121,7 +123,7 @@ class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom {
}
-class RegisteredResourceTest_Resource4 extends Smarty_Resource_Custom {
+class RegisteredResourceTest_Resource4Plugin extends CustomPlugin {
protected function fetch($name, &$source, &$mtime) {
$source = 'current_dir = {$smarty.current_dir}';
diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php
index 668b83da..59315504 100644
--- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php
+++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php
@@ -10,16 +10,19 @@
* -------------------------------------------------------------
*/
-class Smarty_Resource_Db extends Smarty_Resource_Recompiled {
+use Smarty\Resource\RecompiledPlugin;
+use Smarty\Template;
+use Smarty\Template\Source;
- public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
- $source->filepath = 'db:';
+class Smarty_Resource_Db extends RecompiledPlugin {
+
+ public function populate(Source $source, Template $_template = null) {
$source->uid = sha1($source->resource);
$source->timestamp = 1000000000;
$source->exists = true;
}
- public function getContent(Smarty_Template_Source $source) {
+ public function getContent(Source $source) {
return '{$x="hello world"}{$x}';
}
}
diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php
index 3eefce7c..a4f65402 100644
--- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php
+++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php
@@ -10,17 +10,20 @@
* -------------------------------------------------------------
*/
-class Smarty_Resource_Db2 extends Smarty_Resource_Recompiled
+use Smarty\Resource\RecompiledPlugin;
+use Smarty\Template;
+use Smarty\Template\Source;
+
+class Smarty_Resource_Db2 extends RecompiledPlugin
{
- public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
+ public function populate(Source $source, Template $_template = null)
{
- $source->filepath = 'db2:';
$source->uid = sha1($source->resource);
$source->timestamp = 0;
$source->exists = true;
}
- public function getContent(Smarty_Template_Source $source)
+ public function getContent(Source $source)
{
return '{$x="hello world"}{$x}';
}
diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php
index 0b07233b..455255e2 100644
--- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php
+++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php
@@ -10,22 +10,24 @@
* -------------------------------------------------------------
*/
-class Smarty_Resource_Db3 extends Smarty_Resource
+use Smarty\Template;
+use Smarty\Template\Source;
+
+class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
{
- public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
+ public function populate(Source $source, Template $_template = null)
{
- $source->filepath = 'db3:';
$source->uid = sha1($source->resource);
$source->timestamp = 0;
$source->exists = true;
}
- public function getContent(Smarty_Template_Source $source)
+ public function getContent(Source $source)
{
return '{$x="hello world"}{$x}';
}
- public function getCompiledFilepath(Smarty_Internal_Template $_template)
+ public function getCompiledFilepath(Template $_template)
{
return false;
}
diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php
index 611d3e43..571df0d8 100644
--- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php
+++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php
@@ -10,19 +10,22 @@
* -------------------------------------------------------------
*/
-class Smarty_Resource_Db4 extends Smarty_Resource
+use Smarty\Template;
+use Smarty\Template\Config;
+use Smarty\Template\Source;
+
+class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
{
- public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
+ public function populate(Source $source, Template $_template = null)
{
- $source->filepath = 'db4:';
$source->uid = sha1($source->resource);
$source->timestamp = 0;
$source->exists = true;
}
- public function getContent(Smarty_Template_Source $source)
+ public function getContent(Source $source)
{
- if ($source->is_config) {
+ if ($source instanceof Config) {
return "foo = 'bar'\n";
}
diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php
index 9aa46718..5b1b3854 100644
--- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php
+++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php
@@ -2,16 +2,16 @@
/**
* Smarty PHPunit tests resource plugins
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for resource plugins tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class ResourcePluginTest extends PHPUnit_Smarty
{
@@ -49,7 +49,6 @@ class ResourcePluginTest extends PHPUnit_Smarty
public function testResourcePluginRegisteredInstance()
{
$this->smarty->addPluginsDir("./PHPunitplugins/");
- $this->smarty->loadPlugin('Smarty_Resource_Db2');
$this->smarty->registerResource('db2a', new Smarty_Resource_Db2('db2a'));
$this->assertEquals('hello world', $this->smarty->fetch('db2a:test'));
}
@@ -63,7 +62,7 @@ class ResourcePluginTest extends PHPUnit_Smarty
$tpl = $this->smarty->createTemplate('db2:test.tpl');
$expected = realpath('./templates_c/' . sha1('db2:test.tpl') . '.db2.test.tpl.php');
$this->assertFalse(!!$expected);
- $this->assertFalse($tpl->compiled->filepath);
+ $this->assertNull($tpl->getCompiled()->filepath);
}
/**
@@ -73,8 +72,8 @@ class ResourcePluginTest extends PHPUnit_Smarty
{
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('db:test');
- $this->assertTrue(is_integer($tpl->source->getTimeStamp()));
- $this->assertEquals(10, strlen($tpl->source->getTimeStamp()));
+ $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
+ $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
}
}
diff --git a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php
index e5eedcc1..e2a8ff70 100644
--- a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php
+++ b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php
@@ -2,16 +2,16 @@
/**
* Smarty PHPunit tests for stream resources
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for stream resource tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class StreamResourceTest extends PHPUnit_Smarty
{
@@ -27,7 +27,6 @@ class StreamResourceTest extends PHPUnit_Smarty
fclose($fp);
}
-
public function testInit()
{
$this->cleanDirs();
@@ -41,10 +40,10 @@ class StreamResourceTest extends PHPUnit_Smarty
/**
* test getTemplateFilepath
*/
- public function testGetTemplateFilepath()
+ public function testGetFullResourceName()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertEquals('global://mytest', $tpl->source->filepath);
+ $this->assertEquals('global:mytest', $tpl->getSource()->getFullResourceName());
}
/**
@@ -53,7 +52,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertTrue($tpl->source->getTimeStamp());
+ $this->assertTrue($tpl->getSource()->getTimeStamp());
}
/**
@@ -62,7 +61,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('global:mytest', null, null, $this->smarty);
- $this->assertEquals('hello world {$foo}', $tpl->source->getContent());
+ $this->assertEquals('hello world {$foo}', $tpl->getSource()->getContent());
}
/**
@@ -71,7 +70,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertFalse($tpl->source->handler->uncompiled);
+ $this->markTestIncomplete();
}
/**
@@ -80,7 +79,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertTrue($tpl->source->handler->recompiled);
+ $this->assertTrue($tpl->getSource()->handler->recompiled);
}
/**
@@ -98,7 +97,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertFalse($tpl->compiled->filepath);
+ $this->assertNull($tpl->getCompiled()->filepath);
}
/**
@@ -107,7 +106,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertFalse($tpl->compiled->getTimeStamp());
+ $this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**
@@ -116,7 +115,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testTemplateStreamExists1()
{
$tpl = $this->smarty->createTemplate('global:mytest');
- $this->assertTrue($tpl->source->exists);
+ $this->assertTrue($tpl->getSource()->exists);
}
public function testTemplateStreamExists2()
@@ -130,7 +129,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testTemplateStreamNotExists1()
{
$tpl = $this->smarty->createTemplate('global:notthere');
- $this->assertFalse($tpl->source->exists);
+ $this->assertFalse($tpl->getSource()->exists);
}
public function testTemplateStramNotExists2()
@@ -138,15 +137,15 @@ class StreamResourceTest extends PHPUnit_Smarty
$this->assertFalse($this->smarty->templateExists('global:notthere'));
}
/**
- * @runInSeparateProcess
- * @preserveGlobalState disabled
+ *
+ *
*
* test not existing template
*/
public function testTemplateStramNotExists3()
{
- $this->expectException('SmartyException');
+ $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('\'global:notthere\'');
$this->smarty->fetch('global:notthere');
}
diff --git a/tests/UnitTests/ResourceTests/String/StringResourceTest.php b/tests/UnitTests/ResourceTests/String/StringResourceTest.php
index 35be632f..a048d8b8 100644
--- a/tests/UnitTests/ResourceTests/String/StringResourceTest.php
+++ b/tests/UnitTests/ResourceTests/String/StringResourceTest.php
@@ -2,16 +2,16 @@
/**
* Smarty PHPunit tests for string resources
*
- * @package PHPunit
+
* @author Uwe Tews
*/
/**
* class for string resource tests
*
- * @runTestsInSeparateProcess
- * @preserveGlobalState disabled
- * @backupStaticAttributes enabled
+ *
+ *
+ *
*/
class StringResourceTest extends PHPUnit_Smarty
{
@@ -42,7 +42,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testTemplateStringExists1()
{
$tpl = $this->smarty->createTemplate('string:{$foo}');
- $this->assertTrue($tpl->source->exists);
+ $this->assertTrue($tpl->getSource()->exists);
}
public function testTemplateStringExists2()
@@ -56,7 +56,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateFilepath()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertEquals($this->buildSourcePath($tpl), $tpl->source->filepath);
+ $this->assertEquals('hello world', $tpl->getSource()->getResourceName());
}
/**
@@ -65,7 +65,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertTrue($tpl->source->getTimeStamp());
+ $this->assertTrue($tpl->getSource()->getTimeStamp());
}
/**
@@ -74,7 +74,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('string:hello world{$foo}');
- $this->assertEquals('hello world{$foo}', $tpl->source->getContent());
+ $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
}
/**
@@ -83,7 +83,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertFalse($tpl->source->handler->uncompiled);
+ $this->markTestIncomplete();
}
/**
@@ -92,7 +92,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertFalse($tpl->source->handler->recompiled);
+ $this->assertFalse($tpl->getSource()->handler->recompiled);
}
/**
@@ -105,21 +105,12 @@ class StringResourceTest extends PHPUnit_Smarty
}
/**
- * test getCompiledFilepath
- */
- public function testGetCompiledFilepath()
- {
- $tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'hello world', 'string', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
- }
-
- /**
* test getCompiledTimestamp
*/
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertFalse($tpl->compiled->getTimeStamp());
+ $this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**
@@ -137,7 +128,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetCachedTimestamp()
{
$tpl = $this->smarty->createTemplate('string:hello world');
- $this->assertFalse($tpl->cached->timestamp);
+ $this->assertFalse($tpl->getCached()->timestamp);
}
/**