|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ViewTemplateTest contains test cases for the module classes |
|
5
|
|
|
* |
|
6
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
7
|
|
|
* @package viewtemplate |
|
8
|
|
|
*/ |
|
9
|
|
|
class ViewTemplateTest extends FunctionalTest |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
protected static $fixture_file = 'ViewTemplateTest.yml'; |
|
12
|
|
|
|
|
13
|
|
|
public function testModifyViewTemplate() |
|
14
|
|
|
{ |
|
15
|
|
|
// Create a template object |
|
16
|
|
|
$template = $this->objFromFixture('ViewTemplate', 'template1'); |
|
17
|
|
|
|
|
18
|
|
|
// Login as admin |
|
19
|
|
|
$this->logInWithPermission('ADMIN'); |
|
20
|
|
|
|
|
21
|
|
|
// Assert: Update the template |
|
22
|
|
|
$this->assertNotEmpty($template->Title); |
|
|
|
|
|
|
23
|
|
|
$template->Title = 'tempalate1_update'; |
|
24
|
|
|
$template->write(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals($template->Title, 'tempalate1_update'); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testRenderTemplatePlaceholder() |
|
30
|
|
|
{ |
|
31
|
|
|
// Create page object |
|
32
|
|
|
$page = $this->objFromFixture('Page', 'page1'); |
|
33
|
|
|
$templateTitle = 'template1'; |
|
34
|
|
|
$templatePlaceHolder = '{{' . $templateTitle . '}}'; |
|
35
|
|
|
|
|
36
|
|
|
// Assert: render page |
|
37
|
|
|
$this->assertContains($templatePlaceHolder, $page->Content()); |
|
38
|
|
|
|
|
39
|
|
|
// Create template |
|
40
|
|
|
$template = $this->objFromFixture('ViewTemplate', $templateTitle); |
|
41
|
|
|
$templatePlaceHolder = '{{' . $template->Title . '}}'; |
|
42
|
|
|
|
|
43
|
|
|
// Page disable template view |
|
44
|
|
|
$page->EnableViewTemplate = false; |
|
45
|
|
|
|
|
46
|
|
|
// Assert: render page without view template |
|
47
|
|
|
$this->assertContains($templatePlaceHolder, $page->Content()); |
|
48
|
|
|
|
|
49
|
|
|
// Page enable template view |
|
50
|
|
|
$page->EnableViewTemplate = true; |
|
51
|
|
|
|
|
52
|
|
|
// Assert: render page with view template |
|
53
|
|
|
$this->assertNotContains($templatePlaceHolder, $page->Content()); |
|
54
|
|
|
|
|
55
|
|
|
// Login admin |
|
56
|
|
|
$this->logInWithPermission('ADMIN'); |
|
57
|
|
|
|
|
58
|
|
|
// Assert: Publish page |
|
59
|
|
|
$published = $page->doPublish(); |
|
60
|
|
|
$this->assertTrue($published); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
// Assert: page visible to public with render view template |
|
63
|
|
|
Member::currentUser()->logOut(); |
|
64
|
|
|
$response = Director::test(Director::makeRelative($page->Link())); |
|
65
|
|
|
$this->assertNotContains($templatePlaceHolder, $response->getBody()); |
|
66
|
|
|
$this->assertContains($template->ViewTemplate, $response->getBody()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testGetSettingsFields() |
|
70
|
|
|
{ |
|
71
|
|
|
// Login as admin |
|
72
|
|
|
$this->logInWithPermission('ADMIN'); |
|
73
|
|
|
|
|
74
|
|
|
// Create page object |
|
75
|
|
|
$page = $this->objFromFixture('Page', 'page1'); |
|
76
|
|
|
|
|
77
|
|
|
// Get Page settings fields |
|
78
|
|
|
$fields = $page->getSettingsFields(); |
|
79
|
|
|
$field = $fields->dataFieldByName('EnableViewTemplate'); |
|
80
|
|
|
|
|
81
|
|
|
// Assert view template field is added |
|
82
|
|
|
$this->assertTrue($field !== null); |
|
|
|
|
|
|
83
|
|
|
$this->assertInstanceOf('CheckboxField', $field); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testRenderViewTemplatePlaceholderOnly() |
|
87
|
|
|
{ |
|
88
|
|
|
// Login admin |
|
89
|
|
|
$this->logInWithPermission('ADMIN'); |
|
90
|
|
|
|
|
91
|
|
|
// Create page object & template |
|
92
|
|
|
$page = $this->objFromFixture('Page', 'page2'); |
|
93
|
|
|
$page->EnableViewTemplate = true; |
|
94
|
|
|
$template = $this->objFromFixture('ViewTemplate', 'template2'); |
|
95
|
|
|
$templatePlaceHolder = '{{' . $template->Title . '}}'; |
|
96
|
|
|
|
|
97
|
|
|
// Assert: render page with view template |
|
98
|
|
|
$content = $page->Content(); |
|
99
|
|
|
$this->assertNotContains($templatePlaceHolder, $content); |
|
100
|
|
|
$this->assertContains('Welcome Back, ADMIN', $content); |
|
101
|
|
|
$this->assertContains('$CurrentMember.FirstName', $content); |
|
102
|
|
|
$this->assertNotContains('I should not be here! Default Admin', $content); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.