Blame view

framework/tests/core/manifest/TemplateManifestTest.php 3.49 KB
385d70ca   Administrator   Importers CRUD
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  <?php
  /**
   * Tests for the template manifest.
   *
   * @package framework
   * @subpackage tests
   */
  class TemplateManifestTest extends SapphireTest {
  
  	protected $base;
  	protected $manifest;
  	protected $manifestTests;
  
  	public function setUp() {
  		parent::setUp();
  
  		$this->base = dirname(__FILE__) . '/fixtures/templatemanifest';
  		$this->manifest      = new SS_TemplateManifest($this->base, 'myproject');
  		$this->manifestTests = new SS_TemplateManifest($this->base, 'myproject', true);
  
  		$this->manifest->regenerate(false);
  		$this->manifestTests->regenerate(false);
  	}
  
  	public function testGetTemplates() {
  		$expect = array(
  			'root' => array(
  				'module' => "{$this->base}/module/Root.ss"
  			),
  			'page' => array(
  				'main'   => "{$this->base}/module/templates/Page.ss",
  				'Layout' => "{$this->base}/module/templates/Layout/Page.ss",
  				'themes' => array('theme' => array(
  					'main'   => "{$this->base}/themes/theme/templates/Page.ss",
  					'Layout' => "{$this->base}/themes/theme/templates/Layout/Page.ss"
  				))
  			),
  			'custompage' => array(
  				'Layout' => "{$this->base}/module/templates/Layout/CustomPage.ss"
  			),
  			'customtemplate' => array(
  				'main' => "{$this->base}/module/templates/CustomTemplate.ss",
  				'myproject' => array(
  					'main' => "{$this->base}/myproject/templates/CustomTemplate.ss"
  				)
  			),
  			'subfolder' => array(
  				'main' => "{$this->base}/module/subfolder/templates/Subfolder.ss"
  			),
  			'customthemepage' => array (
  				'Layout' => "{$this->base}/module/templates/Layout/CustomThemePage.ss",
  				'themes' =>
  				array(
  					'theme' => array('main' => "{$this->base}/themes/theme/templates/CustomThemePage.ss",)
  				)
  			),
  			'include' => array('themes' => array(
  				'theme' => array(
  					'Includes' => "{$this->base}/themes/theme/templates/Includes/Include.ss"
  				)
  			))
  		);
  
  		$expectTests = $expect;
  		$expectTests['test'] = array(
  			'main' => "{$this->base}/module/tests/templates/Test.ss"
  		);
  
  		$manifest      = $this->manifest->getTemplates();
  		$manifestTests = $this->manifestTests->getTemplates();
  
  		ksort($expect);
  		ksort($expectTests);
  		ksort($manifest);
  		ksort($manifestTests);
  		
  		$this->assertEquals(
  			$expect, $manifest,
  			'All templates are correctly loaded in the manifest.'
  		);
  
  		$this->assertEquals(
  			$expectTests, $manifestTests,
  			'The test manifest is the same, but includes test templates.'
  		);
  	}
  
  	public function testGetTemplate() {
  		$expectPage = array(
  			'main'   => "{$this->base}/module/templates/Page.ss",
  			'Layout' => "{$this->base}/module/templates/Layout/Page.ss",
  			'themes' => array('theme' => array(
  				'main'   => "{$this->base}/themes/theme/templates/Page.ss",
  				'Layout' => "{$this->base}/themes/theme/templates/Layout/Page.ss"
  			))
  		);
  
  		$expectTests = array(
  			'main' => "{$this->base}/module/tests/templates/Test.ss"
  		);
  
  		$this->assertEquals($expectPage, $this->manifest->getTemplate('Page'));
  		$this->assertEquals($expectPage, $this->manifest->getTemplate('PAGE'));
  		$this->assertEquals($expectPage, $this->manifestTests->getTemplate('Page'));
  		$this->assertEquals($expectPage, $this->manifestTests->getTemplate('PAGE'));
  
  		$this->assertEquals(array(), $this->manifest->getTemplate('Test'));
  		$this->assertEquals($expectTests, $this->manifestTests->getTemplate('Test'));
  
  		$this->assertEquals(array(
  			'main' => "{$this->base}/module/templates/CustomTemplate.ss",
  			'myproject' => array(
  				'main' => "{$this->base}/myproject/templates/CustomTemplate.ss"		
  		)), $this->manifestTests->getTemplate('CustomTemplate'));
  	}
  
  }