Completed
Push — master ( 0f13ab...9d4893 )
by Ben
02:07
created

testGetStyleguideData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
/**
3
 * @package simple-styleguide
4
 * @subpackage tests
5
 */
6
class SimpleStyleguideControllerTest extends SapphireTest
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...
7
{
8
    protected static $fixture_file = 'SimpleStyleguideControllerTest.yml';
9
10
    protected $requiredExtensions = [
11
        'SimpleStyleguideController' => ['SimpleStyleguideControllerTest_data'],
12
    ];
13
14
    public function testGetStyleguideData()
15
    {
16
        $controller = SimpleStyleguideController::create();
17
        $data = $controller->getStyleguideData();
18
19
        $this->assertInstanceOf('ArrayData', $data);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
20
        $this->assertEquals('Styleguide', $data->Title);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SimpleStyleguideControllerTest>.

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->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SimpleStyleguideControllerTest>.

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
            '<p>This controller is only accessible to developers and admin users.</p>',
23
            $data->Message->getValue()
24
        );
25
        $this->assertInstanceOf('Form', $data->TestForm);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
26
        $this->assertInstanceOf('HTMLText', $data->Content);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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
        $this->assertInstanceOf('ArrayList', $data->ColorSwatches);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
28
    }
29
30
    public function testGetStyleguideDataExtension()
31
    {
32
        $controller = SimpleStyleguideController::create();
33
        $data = $controller->getStyleguideData();
34
        $this->assertTrue($data->hasField('CustomData'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
35
    }
36
37
    public function testGetTestForm()
38
    {
39
        $controller = SimpleStyleguideController::create();
40
        $form = $controller->getTestForm();
41
42
        $this->assertInstanceOf('Form', $form);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
43
    }
44
45
    public function testGetContent()
46
    {
47
        $controller = SimpleStyleguideController::create();
48
        $content = $controller->getContent();
49
50
        $this->assertInstanceOf('HTMLText', $content);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
51
        $this->assertNotNull($content->getValue());
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
52
    }
53
54
    public function testGetColorSwatches()
55
    {
56
        $controller = SimpleStyleguideController::create();
57
        $swatchesFixture = [
58
            [
59
                'Name' => 'Black',
60
                'Description' => 'This color is rather dark',
61
                'CSSColor' => '#000000',
62
                'TextColor' => '#ffffff',
63
            ],
64
            [
65
                'Name' => 'Grey',
66
                'Description' => 'This color is grey',
67
                'CSSColor' => '#666666',
68
                'TextColor' => '#000000',
69
            ],
70
        ];
71
72
        Config::inst()->remove('SimpleStyleguideController', 'color_swatches');
73
        Config::inst()->update('SimpleStyleguideController', 'color_swatches', $swatchesFixture);
74
75
        $swatches = $controller->getColorSwatches();
76
77
        $this->assertInstanceOf('ArrayList', $swatches);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
78
        $this->assertEquals(count($swatchesFixture), $swatches->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SimpleStyleguideControllerTest>.

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...
79
    }
80
}
81
82
class SimpleStyleguideControllerTest_data extends DataExtension implements TestOnly {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
83
    public function updateStyleguideData($data)
84
    {
85
        $data->setField('CustomData', 'Test');
86
    }
87
}
88