Completed
Push — master ( 309665...10097e )
by Simon
06:28
created

ShortlistTest::testisBrowser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
class ShortlistTest extends FunctionalTest
4
{
5
    protected static $fixture_file = 'fixtures.yml';
6
7
    public function testShortlistCreation()
8
    {
9
        $shortlists = ShortList::get();
10
11
        $this->get('shortlist');
12
13
        $this->assertNotEquals($shortlists->Count(), 0);
14
    }
15
16
    public function testAddItemtoShortList()
17
    {
18
        $testpage = $this->objFromFixture('ShortListItem', 'item1');
19
        $testpage->write();
20
21
        // create the shortlist
22
        $shortlist = new ShortList();
23
        $shortlist->write();
24
25
        $this->assertEquals($shortlist->ShortListItems()->Count(), 0);
26
27
        // add to the shortlist.
28
        $shortlist->ShortListItems()->add($testpage);
29
        $shortlist->write();
30
31
        $retrievedItem = $shortlist->ShortListItems()->filter('ID', $testpage->ID)->first()->getActualRecord();
32
33
        // Check the item has been saved correctly
34
        $this->assertEquals($retrievedItem->ClassName, 'Page');
35
        $this->assertEquals($retrievedItem->ID, $testpage->ID);
36
37
        // do we have an item added?
38
        $this->assertNotEquals($shortlist->ShortListItems()->Count(), 0);
39
        // what about the reverse side?
40
        $this->assertNotEquals($testpage->ShortList()->ID, 0);
41
    }
42
43
    public function testRemoveItemFromShortList()
44
    {
45
        $testpage = $this->objFromFixture('Page', 'page1');
46
47
        // create the shortlist
48
        $shortlist = new ShortList();
49
        $shortlist->write();
50
51
        $this->assertEquals($shortlist->ShortListItems()->Count(), 0);
52
53
        // create the item.
54
        $item = new ShortListItem();
55
        $item->ItemType = $testpage->ClassName;
56
        $item->ItemID = $testpage->ID;
57
        $item->write();
58
59
        // add to the shortlist.
60
        $shortlist->ShortListItems()->add($item);
61
        $shortlist->write();
62
63
        // do we have an item added?
64
        $this->assertNotEquals($shortlist->ShortListItems()->Count(), 0);
65
        // what about the reverse side?
66
        $this->assertNotEquals($item->ShortList()->ID, 0);
67
68
        $shortlist->ShortListItems()->remove($item);
69
70
            // do we have an item removed?
71
        $this->assertEquals($shortlist->ShortListItems()->Count(), 0);
72
    }
73
74
    /*
75
    |--------------------------------------------------------------------------
76
    | Check whether we are or are not a browser.
77
    |--------------------------------------------------------------------------
78
    */
79
    public function testisBrowser()
80
    {
81
        $list = $this->objFromFixture('ShortList', 'test');
82
        $ua = Controller::curr()->getRequest()->getHeader('User-Agent');
83
84
        if (empty(strtolower($ua))) {
85
            $this->assertFalse($list->isBrowser());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShortlistTest>.

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...
86
        } else {
87
            $this->assertTrue($list->isBrowser());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShortlistTest>.

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...
88
        }
89
    }
90
91
    public function testShortListLink()
92
    {
93
        $list = $this->objFromFixture('ShortList', 'test');
94
        $list->write();
95
96
        $configURL = Config::inst()->get('ShortList', 'URLSegment');
97
        $link = $list->Link();
98
99
        $configPos = strpos($link, $configURL);
100
        $linkPos = strpos($link, $list->URL);
101
102
        $this->assertGreaterThan($configPos, $linkPos);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<ShortlistTest>.

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...
103
    }
104
}
105