Completed
Pull Request — master (#11)
by Helpful
04:15
created

ConfigurablePageTest::testGetCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * ConfigurablePageTest contains test cases for the module classes
5
 *
6
 * @author  Mohamed Alsharaf <[email protected]>
7
 * @package configurablepage
8
 */
9
class ConfigurablePageTest 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 = 'ConfigurablePageTest.yml';
12
13
    public function testGetCMSFields()
14
    {
15
        $this->logInWithPermission('EDITOR');
16
17
        $page = $this->objFromFixture('ConfigurablePage', 'page-1');
18
        $fields = $page->getCMSFields();
19
20
        $this->assertTrue($fields->dataFieldByName('textfield1') !== null);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ConfigurablePageTest>.

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...
21
        $this->assertTrue($page->getCMSValidator()->fieldIsRequired('textfield1'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ConfigurablePageTest>.

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...
22
    }
23
24
    public function testWriteToField()
25
    {
26
        $this->logInWithPermission('EDITOR');
27
28
        $value = 'Value for text field 1';
29
        $page = $this->objFromFixture('ConfigurablePage', 'page-1');
30
        $page->textfield1 = $value;
31
        $page->Content = 'Page content $textfield1';
32
        $page->write();
33
34
        $page2 = $this->objFromFixture('ConfigurablePage', 'page-1');
35
        $this->assertContains($value, $page2->Content());
36
    }
37
38
    public function testFieldsRendering()
39
    {
40
        $this->logInWithPermission('EDITOR');
41
42
        $page3 = Page::get_by_link('page3');
43
        $memberId = Member::currentUserID();
44
        $values = [
45
            'checkboxgroup'  => '2,0',
46
            'countryfield'   => 'NZ',
47
            'dobfield'       => '2014-1-1',
48
            'memberfield1'   => (string)$memberId,
49
            'pagetypefield2' => (string)$page3->ID
50
        ];
51
52
        $page = $this->objFromFixture('ConfigurablePage', 'page-2');
53
        $page->Content = 'Page content ----->';
54
        foreach ($values as $name => $value) {
55
            $page->setField($name, $value);
56
            $page->$name = $value;
57
            $page->Content .= ' $' . $name;
58
        }
59
        $page->write();
60
61
        $content = $page->Content();
62
63
        $editableFields = $page->getEditableFields();
64
        foreach ($editableFields as $editableField) {
65
            $field = $editableField->getFormField();
66
            if (!$field instanceof DatalessField) {
67
                $field->value = $page->{$editableField->Name};
68
                $this->assertContains($editableField->getValueAsString(), $content);
69
            }
70
        }
71
    }
72
}
73