1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<?php
/**
* Smarty PHPunit tests for File resources
*
* @author Uwe Tews
*/
/**
* class for file resource tests
*/
class CustomResourceAmbiguousTest extends PHPUnit_Smarty
{
public $_resource = null;
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();
}
protected function relative($path)
{
$path = str_replace(__DIR__, '.', $path);
if (DIRECTORY_SEPARATOR == "\\") {
$path = str_replace("\\", "/", $path);
}
return $path;
}
public function testNone()
{
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
// $this->smarty->setAllowAmbiguousResources(true);
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertFalse($tpl->getSource()->exists);
}
public function testCase1()
{
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->getSource()->getContent());
}
public function testCase2()
{
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->getSource()->getContent());
}
public function testCaseSwitching()
{
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
$this->smarty->registerResource('ambiguous', $resource_handler);
$this->smarty->setDefaultResourceType('ambiguous');
// $this->smarty->setAllowAmbiguousResources(true);
$resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->getSource()->getContent());
$resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->getSource()->getContent());
}
}
|