1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests for the template manifest. |
4
|
|
|
* |
5
|
|
|
* @package framework |
6
|
|
|
* @subpackage tests |
7
|
|
|
*/ |
8
|
|
|
class TemplateManifestTest extends SapphireTest { |
9
|
|
|
|
10
|
|
|
protected $base; |
11
|
|
|
protected $manifest; |
12
|
|
|
protected $manifestTests; |
13
|
|
|
|
14
|
|
|
public function setUp() { |
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$this->base = dirname(__FILE__) . '/fixtures/templatemanifest'; |
18
|
|
|
$this->manifest = new SS_TemplateManifest($this->base, 'myproject'); |
19
|
|
|
$this->manifestTests = new SS_TemplateManifest($this->base, 'myproject', true); |
20
|
|
|
|
21
|
|
|
$this->manifest->regenerate(false); |
22
|
|
|
$this->manifestTests->regenerate(false); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testGetTemplates() { |
26
|
|
|
$expect = array( |
27
|
|
|
'root' => array( |
28
|
|
|
'main' => "{$this->base}/module/Root.ss" |
29
|
|
|
), |
30
|
|
|
'page' => array( |
31
|
|
|
'main' => "{$this->base}/module/templates/Page.ss", |
32
|
|
|
'Layout' => "{$this->base}/module/templates/Layout/Page.ss", |
33
|
|
|
'themes' => array('theme' => array( |
34
|
|
|
'main' => "{$this->base}/themes/theme/templates/Page.ss", |
35
|
|
|
'Layout' => "{$this->base}/themes/theme/templates/Layout/Page.ss" |
36
|
|
|
)) |
37
|
|
|
), |
38
|
|
|
'custompage' => array( |
39
|
|
|
'Layout' => "{$this->base}/module/templates/Layout/CustomPage.ss" |
40
|
|
|
), |
41
|
|
|
'customtemplate' => array( |
42
|
|
|
'main' => "{$this->base}/module/templates/CustomTemplate.ss", |
43
|
|
|
'myproject' => array( |
44
|
|
|
'main' => "{$this->base}/myproject/templates/CustomTemplate.ss" |
45
|
|
|
) |
46
|
|
|
), |
47
|
|
|
'subfolder' => array( |
48
|
|
|
'main' => "{$this->base}/module/subfolder/templates/Subfolder.ss" |
49
|
|
|
), |
50
|
|
|
'customthemepage' => array ( |
51
|
|
|
'Layout' => "{$this->base}/module/templates/Layout/CustomThemePage.ss", |
52
|
|
|
'themes' => |
53
|
|
|
array( |
54
|
|
|
'theme' => array('main' => "{$this->base}/themes/theme/templates/CustomThemePage.ss",) |
55
|
|
|
) |
56
|
|
|
), |
57
|
|
|
'mynamespace\myclass' => array( |
58
|
|
|
'main' => "{$this->base}/module/templates/MyNamespace/MyClass.ss", |
59
|
|
|
'Layout' => "{$this->base}/module/templates/MyNamespace/Layout/MyClass.ss", |
60
|
|
|
'themes' => array( |
61
|
|
|
'theme' => array( |
62
|
|
|
'main' => "{$this->base}/themes/theme/templates/MyNamespace/MyClass.ss", |
63
|
|
|
) |
64
|
|
|
), |
65
|
|
|
), |
66
|
|
|
'mynamespace\mysubnamespace\mysubclass' => array( |
67
|
|
|
'main' => "{$this->base}/module/templates/MyNamespace/MySubnamespace/MySubclass.ss", |
68
|
|
|
), |
69
|
|
|
'myclass' => array( |
70
|
|
|
'main' => "{$this->base}/module/templates/MyNamespace/MyClass.ss", |
71
|
|
|
'Layout' => "{$this->base}/module/templates/MyNamespace/Layout/MyClass.ss", |
72
|
|
|
'themes' => array( |
73
|
|
|
'theme' => array( |
74
|
|
|
'main' => "{$this->base}/themes/theme/templates/MyNamespace/MyClass.ss", |
75
|
|
|
) |
76
|
|
|
), |
77
|
|
|
), |
78
|
|
|
'mysubclass' => array( |
79
|
|
|
'main' => "{$this->base}/module/templates/MyNamespace/MySubnamespace/MySubclass.ss", |
80
|
|
|
), |
81
|
|
|
'include' => array('themes' => array( |
82
|
|
|
'theme' => array( |
83
|
|
|
'Includes' => "{$this->base}/themes/theme/templates/Includes/Include.ss" |
84
|
|
|
) |
85
|
|
|
)) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$expectTests = $expect; |
89
|
|
|
$expectTests['test'] = array( |
90
|
|
|
'main' => "{$this->base}/module/tests/templates/Test.ss" |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$manifest = $this->manifest->getTemplates(); |
94
|
|
|
$manifestTests = $this->manifestTests->getTemplates(); |
95
|
|
|
|
96
|
|
|
ksort($expect); |
97
|
|
|
ksort($expectTests); |
98
|
|
|
ksort($manifest); |
99
|
|
|
ksort($manifestTests); |
100
|
|
|
|
101
|
|
|
$this->assertEquals( |
102
|
|
|
$expect, $manifest, |
103
|
|
|
'All templates are correctly loaded in the manifest.' |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$this->assertEquals( |
107
|
|
|
$expectTests, $manifestTests, |
108
|
|
|
'The test manifest is the same, but includes test templates.' |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testGetTemplate() { |
113
|
|
|
$expectPage = array( |
114
|
|
|
'main' => "{$this->base}/module/templates/Page.ss", |
115
|
|
|
'Layout' => "{$this->base}/module/templates/Layout/Page.ss", |
116
|
|
|
'themes' => array('theme' => array( |
117
|
|
|
'main' => "{$this->base}/themes/theme/templates/Page.ss", |
118
|
|
|
'Layout' => "{$this->base}/themes/theme/templates/Layout/Page.ss" |
119
|
|
|
)) |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$expectTests = array( |
123
|
|
|
'main' => "{$this->base}/module/tests/templates/Test.ss" |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
$this->assertEquals($expectPage, $this->manifest->getTemplate('Page')); |
127
|
|
|
$this->assertEquals($expectPage, $this->manifest->getTemplate('PAGE')); |
128
|
|
|
$this->assertEquals($expectPage, $this->manifestTests->getTemplate('Page')); |
129
|
|
|
$this->assertEquals($expectPage, $this->manifestTests->getTemplate('PAGE')); |
130
|
|
|
|
131
|
|
|
$this->assertEquals(array(), $this->manifest->getTemplate('Test')); |
132
|
|
|
$this->assertEquals($expectTests, $this->manifestTests->getTemplate('Test')); |
133
|
|
|
|
134
|
|
|
$this->assertEquals(array( |
135
|
|
|
'main' => "{$this->base}/module/templates/CustomTemplate.ss", |
136
|
|
|
'myproject' => array( |
137
|
|
|
'main' => "{$this->base}/myproject/templates/CustomTemplate.ss" |
138
|
|
|
)), $this->manifestTests->getTemplate('CustomTemplate')); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|