StaffDirectoryControllerTest::testPaginatedList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 23
rs 9.8333
1
<?php
2
3
namespace Dynamic\Staff\Tests\Pages;
4
5
use Dynamic\Staff\Pages\StaffDirectory;
6
use Dynamic\Staff\Pages\StaffDirectoryController;
7
use Dynamic\Staff\Pages\StaffMember;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Core\Injector\Injector;
11
use SilverStripe\Dev\SapphireTest;
12
use SilverStripe\ORM\GroupedList;
13
use SilverStripe\ORM\PaginatedList;
14
15
/**
16
 * Class StaffDirectoryControllerTest
17
 * @package Dynamic\Staff\Tests\Pages
18
 */
19
class StaffDirectoryControllerTest extends SapphireTest
20
{
21
    /**
22
     * @var string
23
     */
24
    protected static $fixture_file = '../fixtures.yml';
25
26
    /**
27
     * Tests getPageSize()
28
     */
29
    public function testGetPageSize()
30
    {
31
        /** @var StaffDirectory $directory */
32
        $directory = Injector::inst()->create(StaffDirectory::class);
33
        $controller = new StaffDirectoryController($directory);
34
35
        $this->assertEquals(10, $controller->getPageSize());
36
37
        Config::modify()->set(StaffDirectoryController::class, 'page_size', 12);
38
        $this->assertEquals(12, $controller->getPageSize());
39
    }
40
41
    /**
42
     * Tests PaginatedList()
43
     */
44
    public function testPaginatedList()
45
    {
46
        /** @var StaffDirectory $directory */
47
        $directory = $this->objFromFixture(StaffDirectory::class, 'default');
48
        /** @var StaffMember $one */
49
        $one = $this->objFromFixture(StaffMember::class, 'one');
0 ignored issues
show
Unused Code introduced by
The assignment to $one is dead and can be removed.
Loading history...
50
        /** @var StaffMember $two */
51
        $two = $this->objFromFixture(StaffMember::class, 'two');
0 ignored issues
show
Unused Code introduced by
The assignment to $two is dead and can be removed.
Loading history...
52
        /** @var StaffMember $three */
53
        $three = $this->objFromFixture(StaffMember::class, 'three');
0 ignored issues
show
Unused Code introduced by
The assignment to $three is dead and can be removed.
Loading history...
54
55
        $controller = new StaffDirectoryController($directory);
56
57
        $list = $controller->PaginatedList();
58
        $this->assertInstanceOf(PaginatedList::class, $list);
59
        $this->assertEquals(3, $list->count());
60
61
        $request = new HTTPRequest('GET', $directory->Link(), array(
62
            'start' => 1,
63
        ));
64
        $list = $controller->PaginatedList($request);
65
        $this->assertInstanceOf(PaginatedList::class, $list);
66
        $this->assertEquals(3, $list->count());
67
    }
68
69
    /**
70
     * Tests GroupedList()
71
     */
72
    public function testGroupedList()
73
    {
74
        /** @var StaffDirectory $directory */
75
        $directory = $this->objFromFixture(StaffDirectory::class, 'default');
76
        /** @var StaffMember $one */
77
        $one = $this->objFromFixture(StaffMember::class, 'one');
0 ignored issues
show
Unused Code introduced by
The assignment to $one is dead and can be removed.
Loading history...
78
        /** @var StaffMember $two */
79
        $two = $this->objFromFixture(StaffMember::class, 'two');
0 ignored issues
show
Unused Code introduced by
The assignment to $two is dead and can be removed.
Loading history...
80
        /** @var StaffMember $three */
81
        $three = $this->objFromFixture(StaffMember::class, 'three');
0 ignored issues
show
Unused Code introduced by
The assignment to $three is dead and can be removed.
Loading history...
82
83
        $controller = new StaffDirectoryController($directory);
84
85
        $list = $controller->GroupedList();
86
        $this->assertInstanceOf(GroupedList::class, $list);
87
        $this->assertEquals(3, $list->count());
88
    }
89
}
90