Completed
Push — master ( 1a6960...9900fc )
by Jason
9s
created

TestCollectionObject   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSortOptions() 0 8 1
1
<?php
2
3
class CollectionExtensionTest extends FunctionalTest
4
{
5
    /**
6
     * @var string
7
     */
8
    protected static $fixture_file = array(
9
        'collection/tests/fixtures.yml',
10
    );
11
12
    /**
13
     * @var bool
14
     */
15
    protected static $disable_themes = true;
16
17
    /**
18
     * @var bool
19
     */
20
    protected static $use_draft_site = false;
21
22
    /**
23
     * @var array
24
     */
25
    protected $extraDataObjects = array(
26
        'TestCollection',
27
        'TestCollection_Controller',
28
        'TestCollectionObject',
29
    );
30
31
    /**
32
     *
33
     */
34
    public function setUp()
35
    {
36
        parent::setUp();
37
38
        ini_set('display_errors', 1);
39
        ini_set('log_errors', 1);
40
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
41
    }
42
43
    /**
44
     *
45
     */
46
    public function logOut()
47
    {
48
        $this->session()->clear('loggedInAs');
49
        $this->session()->clear('logInWithPermission');
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testGetCollection()
56
    {
57
        $object = $this->objFromFixture('TestCollection', 'default');
58
        $controller = new TestCollection_Controller($object);
59
        $this->assertInstanceOf('DataList', $controller->getCollection());
60
61
        $object = $controller->config()->managed_object;
62
        $this->assertInstanceOf($object, $controller->getCollection()->first());
63
    }
64
65
    /**
66
     *
67
     */
68
    public function testGetManagedObject()
69
    {
70
        $object = TestCollection_Controller::create();
71
        $expected = 'TestCollectionObject';
72
        $this->assertEquals($expected, $object->getCollectionObject());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CollectionExtensionTest>.

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...
73
    }
74
75
    /**
76
     *
77
     */
78
    public function testGetPageSize()
79
    {
80
        $object = TestCollection_Controller::create();
81
        $expected = 10;
82
        $this->assertEquals($expected, $object->getCollectionSize());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CollectionExtensionTest>.

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
    }
84
85
    /**
86
     *
87
     */
88
    public function testPaginatedList()
89
    {
90
        $object = $this->objFromFixture('TestCollection', 'default');
91
        $controller = new TestCollection_Controller($object);
92
        $this->assertInstanceOf('PaginatedList', $controller->PaginatedList());
93
    }
94
95
    /**
96
     *
97
     */
98
    public function testGroupedList()
99
    {
100
        $object = $this->objFromFixture('TestCollection', 'default');
101
        $controller = new TestCollection_Controller($object);
102
        $this->assertInstanceOf('GroupedList', $controller->GroupedList());
103
    }
104
105
    /**
106
     *
107
     */
108
    public function testCollectionSearchForm()
109
    {
110
        $object = $this->objFromFixture('TestCollection', 'default');
111
        $controller = new TestCollection_Controller($object);
112
        $this->assertInstanceOf('Form', $controller->CollectionSearchForm());
113
    }
114
}
115
116
/**
117
 * Class TestCollection.
118
 */
119
class TestCollection extends Page 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...
120
{
121
122
}
123
124
class TestCollection_Controller extends Page_Controller 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...
125
{
126
    private static $managed_object = 'TestCollectionObject';
0 ignored issues
show
Unused Code introduced by
The property $managed_object is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
127
128
    private static $extensions = ['CollectionExtension'];
129
}
130
131
class TestCollectionObject extends Dataobject 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...
132
{
133
    private static $db = [
134
        'Title' => 'Varchar(255)',
135
    ];
136
137
    public function getSortOptions()
138
    {
139
        return array(
140
            'Created' => 'Date',
141
            'Title' => 'Name A-Z',
142
            'Title DESC' => 'Name Z-A',
143
        );
144
    }
145
}