CollectionExtensionTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 110
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A logOut() 0 4 1
A testPaginatedList() 0 5 1
A testGetManagedObject() 0 5 1
A testGetCollection() 0 8 1
A testCollectionSearchForm() 0 5 1
A testGetPageSize() 0 5 1
A setUp() 0 7 1
A testGroupedList() 0 5 1
1
<?php
2
3
namespace Dynamic\Collection\Test;
4
5
use Dynamic\Collection\Test\TestOnly\TestCollection;
6
use Dynamic\Collection\Test\TestOnly\TestCollectionController;
7
use Dynamic\Collection\Test\TestOnly\TestCollectionObject;
8
use SilverStripe\Dev\FunctionalTest;
9
use SilverStripe\Forms\Form;
10
use SilverStripe\ORM\DataList;
11
use SilverStripe\ORM\GroupedList;
12
use SilverStripe\ORM\PaginatedList;
13
14
class CollectionExtensionTest extends FunctionalTest
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $fixture_file = array(
20
        'fixtures.yml',
21
    );
22
23
    /**
24
     * @var bool
25
     */
26
    protected static $disable_themes = true;
27
28
    /**
29
     * @var bool
30
     */
31
    protected static $use_draft_site = false;
32
33
    /**
34
     * @var array
35
     */
36
    protected static $extra_dataobjects = array(
37
        TestCollection::class,
38
        TestCollectionController::class,
39
        TestCollectionObject::class,
40
    );
41
42
    /**
43
     *
44
     */
45
    public function setUp()
46
    {
47
        parent::setUp();
48
49
        ini_set('display_errors', 1);
50
        ini_set('log_errors', 1);
51
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
52
    }
53
54
    /**
55
     *
56
     */
57
    public function logOut()
58
    {
59
        $this->session()->clear('loggedInAs');
60
        $this->session()->clear('logInWithPermission');
61
    }
62
63
    /**
64
     *
65
     */
66
    public function testGetCollection()
67
    {
68
        $object = $this->objFromFixture(TestCollection::class, 'default');
69
        $controller = new TestCollectionController($object);
70
        $this->assertInstanceOf(DataList::class, $controller->getCollection());
0 ignored issues
show
Bug introduced by
The method getCollection() does not exist on Dynamic\Collection\Test\...estCollectionController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
        $this->assertInstanceOf(DataList::class, $controller->/** @scrutinizer ignore-call */ getCollection());
Loading history...
71
72
        $object = $controller->config()->managed_object;
73
        $this->assertInstanceOf($object, $controller->getCollection()->first());
74
    }
75
76
    /**
77
     *
78
     */
79
    public function testGetManagedObject()
80
    {
81
        $object = TestCollectionController::create();
82
        $expected = TestCollectionObject::class;
83
        $this->assertEquals($expected, $object->getCollectionObject());
84
    }
85
86
    /**
87
     *
88
     */
89
    public function testGetPageSize()
90
    {
91
        $object = TestCollectionController::create();
92
        $expected = 10;
93
        $this->assertEquals($expected, $object->getCollectionSize());
94
    }
95
96
    /**
97
     *
98
     */
99
    public function testPaginatedList()
100
    {
101
        $object = $this->objFromFixture(TestCollection::class, 'default');
102
        $controller = new TestCollectionController($object);
103
        $this->assertInstanceOf(PaginatedList::class, $controller->PaginatedList());
0 ignored issues
show
Bug introduced by
The method PaginatedList() does not exist on Dynamic\Collection\Test\...estCollectionController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
        $this->assertInstanceOf(PaginatedList::class, $controller->/** @scrutinizer ignore-call */ PaginatedList());
Loading history...
104
    }
105
106
    /**
107
     *
108
     */
109
    public function testGroupedList()
110
    {
111
        $object = $this->objFromFixture(TestCollection::class, 'default');
112
        $controller = new TestCollectionController($object);
113
        $this->assertInstanceOf(GroupedList::class, $controller->GroupedList());
0 ignored issues
show
Bug introduced by
The method GroupedList() does not exist on Dynamic\Collection\Test\...estCollectionController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $this->assertInstanceOf(GroupedList::class, $controller->/** @scrutinizer ignore-call */ GroupedList());
Loading history...
114
    }
115
116
    /**
117
     *
118
     */
119
    public function testCollectionSearchForm()
120
    {
121
        $object = $this->objFromFixture(TestCollection::class, 'default');
122
        $controller = new TestCollectionController($object);
123
        $this->assertInstanceOf(Form::class, $controller->CollectionSearchForm());
0 ignored issues
show
Bug introduced by
The method CollectionSearchForm() does not exist on Dynamic\Collection\Test\...estCollectionController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
        $this->assertInstanceOf(Form::class, $controller->/** @scrutinizer ignore-call */ CollectionSearchForm());
Loading history...
124
    }
125
}
126