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()); |
|
|
|
|
86
|
|
|
} else { |
87
|
|
|
$this->assertTrue($list->isBrowser()); |
|
|
|
|
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); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.