summaryrefslogtreecommitdiff
path: root/tests/UnitTests/ResourceTests/Custom
diff options
context:
space:
mode:
Diffstat (limited to 'tests/UnitTests/ResourceTests/Custom')
-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
6 files changed, 75 insertions, 174 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'));
}
}