Completed
Pull Request — master (#6)
by Helpful
06:26
created

testRenderViewTemplatePlaceholderOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<ViewTemplateTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
        $template->Title = 'tempalate1_update';
24
        $template->write();
25
26
        $this->assertEquals($template->Title, 'tempalate1_update');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ViewTemplateTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ViewTemplateTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ViewTemplateTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
        $this->assertInstanceOf('CheckboxField', $field);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<ViewTemplateTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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