1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class ProductWishListTest |
5
|
|
|
*/ |
6
|
|
|
class ProductWishListTest extends SapphireTest |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
public static $fixture_file = 'product-wishlist/tests/fixtures.yml'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $extraDataObjects = [ |
18
|
|
|
'TestWishListPage', |
19
|
|
|
'TestProductWishList', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$wishList = $this->objFromFixture('ProductWishList', 'one'); |
28
|
|
|
$canAccess = $this->objFromFixture('Member', 'cancreate'); |
29
|
|
|
$cantAccess = $this->objFromFixture('Member', 'cantcreate'); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($wishList->canCreate($canAccess)); |
|
|
|
|
32
|
|
|
$this->assertFalse($wishList->canCreate($cantAccess)); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$wishList = $this->objFromFixture('ProductWishList', 'one'); |
41
|
|
|
$canAccess = $this->objFromFixture('Member', 'cancreate'); |
42
|
|
|
$cantAccess = $this->objFromFixture('Member', 'cantcreate'); |
43
|
|
|
|
44
|
|
|
$this->assertTrue($wishList->canEdit($canAccess)); |
|
|
|
|
45
|
|
|
$this->assertFalse($wishList->canEdit($cantAccess)); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$wishList = $this->objFromFixture('ProductWishList', 'one'); |
54
|
|
|
$canAccess = $this->objFromFixture('Member', 'cancreate'); |
55
|
|
|
$cantAccess = $this->objFromFixture('Member', 'cantcreate'); |
56
|
|
|
|
57
|
|
|
$this->assertTrue($wishList->canDelete($canAccess)); |
|
|
|
|
58
|
|
|
$this->assertFalse($wishList->canDelete($cantAccess)); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function testCanView() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$wishList = $this->objFromFixture('ProductWishList', 'one'); |
67
|
|
|
$canAccess = $this->objFromFixture('Member', 'cancreate'); |
68
|
|
|
$cantAccess = $this->objFromFixture('Member', 'cantcreate'); |
69
|
|
|
|
70
|
|
|
$this->assertTrue($wishList->canView($canAccess)); |
|
|
|
|
71
|
|
|
//todo fix following assertion |
72
|
|
|
//$this->assertFalse($wishList->canView($cantAccess)); |
|
|
|
|
73
|
|
|
|
74
|
|
|
$viewableWishList = $this->objFromFixture('ProductWishList', 'three'); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($viewableWishList->canView($cantAccess)); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* |
81
|
|
|
*/ |
82
|
|
|
public function testProvidePermissions() |
83
|
|
|
{ |
84
|
|
|
$expected = [ |
85
|
|
|
'WishList_EDIT' => 'Edit a Wish List', |
86
|
|
|
'WishList_DELETE' => 'Delete a Wish List', |
87
|
|
|
'WishList_CREATE' => 'Create a Wish List', |
88
|
|
|
'WishList_VIEW' => 'View a Wish List', |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
$this->assertEquals($expected, Injector::inst()->get('ProductWishList')->providePermissions()); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
|
public function testGetViewAction() |
98
|
|
|
{ |
99
|
|
|
$this->assertEquals('view', Injector::inst()->get('ProductWishList')->getViewAction()); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testGetUpdateLink() |
103
|
|
|
{ |
104
|
|
|
$this->assertFalse(Injector::inst()->get('ProductWishList')->getUpdateLink()); |
|
|
|
|
105
|
|
|
|
106
|
|
|
$hasLink = $this->objFromFixture('ProductWishList', 'one'); |
107
|
|
|
$expected = "update/{$hasLink->ID}"; |
108
|
|
|
|
109
|
|
|
$this->assertEquals($expected, $hasLink->getUpdateLink()); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
*/ |
115
|
|
|
public function testGetFrontEndRequiredFields() |
116
|
|
|
{ |
117
|
|
|
$this->assertInstanceOf('RequiredFields', |
118
|
|
|
Injector::inst()->get('ProductWishList')->getFrontEndRequiredFields()); |
119
|
|
|
|
120
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'one'); |
121
|
|
|
$this->assertTrue($wishList->getFrontEndRequiredFields()->fieldIsRequired('OtherField')); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* |
126
|
|
|
*/ |
127
|
|
|
public function testGetFrontEndActions() |
128
|
|
|
{ |
129
|
|
|
$this->assertInstanceOf('FieldList', Injector::inst()->get('ProductWishList')->getFrontEndActions()); |
130
|
|
|
|
131
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'one'); |
132
|
|
|
$this->assertNull($wishList->getFrontEndActions()->dataFieldByName('action_CancelFormAction')); |
|
|
|
|
133
|
|
|
$this->assertInstanceOf('CancelFormAction', $wishList->getFrontEndActions(true)->dataFieldByName('action_CancelFormAction')); |
134
|
|
|
|
135
|
|
|
$this->assertInstanceOf('FormAction', $wishList->getFrontEndActions()->dataFieldByName('action_OtherAction')); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* |
140
|
|
|
*/ |
141
|
|
|
public function testGetFrontEndFields() |
142
|
|
|
{ |
143
|
|
|
$baseFields = Injector::inst()->get('ProductWishList')->getFrontEndFields(); |
144
|
|
|
$this->assertInstanceOf('FieldList', $baseFields); |
145
|
|
|
$this->assertNull($baseFields->fieldByName('MemberID')); |
|
|
|
|
146
|
|
|
|
147
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'one'); |
148
|
|
|
$updatedFields = $wishList->getFrontEndFields(); |
149
|
|
|
$this->assertInstanceOf('FieldList', $updatedFields); |
150
|
|
|
$this->assertInstanceOf('TextareaField', $updatedFields->dataFieldByName('OtherField')); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.