Files

101 lines
3.2 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Smarty PHPunit tests for File resources
*
2023-08-08 00:04:14 +02:00
* @author Uwe Tews
*/
/**
* class for file resource tests
*/
class CustomResourceAmbiguousTest extends PHPUnit_Smarty
{
public $_resource = null;
2021-10-13 12:15:17 +02:00
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
require_once __DIR__ . '/PHPunitplugins/resource.ambiguous.php';
// empty the template dir
$this->smarty->setTemplateDir(array());
// kill cache for unit test
// Smarty::$_resource_cache = array();
}
public function testInit()
{
$this->cleanDirs();
}
protected function relative($path)
{
$path = str_replace(__DIR__, '.', $path);
if (DIRECTORY_SEPARATOR == "\\") {
$path = str_replace("\\", "/", $path);
}
return $path;
}
public function testNone()
{
2023-08-08 00:04:14 +02:00
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
2023-08-08 00:04:14 +02:00
// $this->smarty->setAllowAmbiguousResources(true);
$tpl = $this->smarty->createTemplate('foobar.tpl');
2023-08-08 00:04:14 +02:00
$this->assertFalse($tpl->getSource()->exists);
}
public function testCase1()
{
2023-08-08 00:04:14 +02:00
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
2023-08-08 00:04:14 +02:00
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
2023-08-08 00:04:14 +02:00
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->getSource()->getContent());
}
public function testCase2()
{
2023-08-08 00:04:14 +02:00
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
2023-08-08 00:04:14 +02:00
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
2023-08-08 00:04:14 +02:00
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->getSource()->getContent());
}
2023-08-08 00:04:14 +02:00
public function testCaseSwitching()
{
2023-08-08 00:04:14 +02:00
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
2023-08-08 00:04:14 +02:00
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
2023-08-08 00:04:14 +02:00
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->getSource()->getContent());
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
2023-08-08 00:04:14 +02:00
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->getSource()->getContent());
}
}