Completed
Pull Request — master (#3)
by Jason
03:44
created

ViewableDataObjectTest::testValidURLSegment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
use Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface;
4
5
class ViewableDataObjectTest extends SapphireTest
6
{
7
    /**
8
     * @var array
9
     */
10
    protected static $fixture_file = array(
11
        'viewable-dataobject/tests/fixtures.yml',
12
    );
13
14
    /**
15
     * @var array
16
     */
17
    protected $extraDataObjects = array(
18
        'ViewableTestObject',
19
    );
20
21
    protected function getObject()
22
    {
23
        return $this->objFromFixture('ViewableTestObject', 'one');
24
    }
25
26
    public function testUpdateCMSFields()
27
    {
28
        $object = $this->getObject();
29
        $fields = $object->getCMSFields();
30
        $this->assertInstanceOf('FieldList', $fields);
31
    }
32
33
    public function testHasParentPage()
34
    {
35
        $object = $this->getObject();
36
        $this->assertInstanceOf('Page', $object->getParentPage());
37
    }
38
39
    public function testHasViewAction()
40
    {
41
        $object = $this->getObject();
42
        $this->assertEquals($object->hasViewAction(), 'view');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ViewableDataObjectTest>.

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 testLink()
46
    {
47
        $object = $this->getObject();
48
        $page = $this->objFromFixture('Page', 'default');
49
        $this->assertEquals($page->Link() . 'view/' . $object->URLSegment, $object->Link());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ViewableDataObjectTest>.

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...
50
    }
51
52
    public function testGetAbsoluteLink()
53
    {
54
        $object = $this->getObject();
55
        $page = $this->objFromFixture('Page', 'default');
56
        $this->assertEquals($page->AbsoluteLink() . 'view/' . $object->URLSegment, $object->getAbsoluteLink());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ViewableDataObjectTest>.

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...
57
    }
58
59
    public function testValidURLSegment()
60
    {
61
        $object = $this->objFromFixture('ViewableTestObject', 'one');
62
        $object2 = $this->objFromFixture('ViewableTestObject', 'two');
63
        $object->URLSegment = $object2->URLSegment;
64
        $this->assertFalse($object->validURLSegment());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ViewableDataObjectTest>.

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...
65
        $object->URLSegment = 'object-one';
66
        $this->assertTrue($object->validURLSegment());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ViewableDataObjectTest>.

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...
67
    }
68
69
    public function testBreadcrumbs()
70
    {
71
        $object = $this->objFromFixture('ViewableTestObject', 'one');
72
        $this->assertInstanceOf("HTMLText", $object->Breadcrumbs());
73
    }
74
}
75
76
class ViewableTestObject extends DataObject implements TestOnly, Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface
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...
77
{
78
    private static $db = [
79
        'Title' => 'Varchar(255)',
80
        'Content' => 'HtmlText',
81
    ];
82
83
    private static $extensions = [
84
        'Dynamic\ViewableDataObject\Extensions\ViewableDataObject',
85
    ];
86
87
    public function getParentPage()
88
    {
89
        return Page::get()->first();
90
    }
91
}