1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class TestProductWishListTest |
5
|
|
|
*/ |
6
|
|
|
class ProductWishListTest extends SapphireTest |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected 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('TestProductWishList', '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('TestProductWishList', '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('TestProductWishList', '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('TestProductWishList', '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('TestProductWishList', 'three'); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($viewableWishList->canView($cantAccess)); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* |
81
|
|
|
*/ |
82
|
|
|
public function testProvidePermissions() |
83
|
|
|
{ |
84
|
|
|
$expected = [ |
85
|
|
|
'WishList_EDIT' => [ |
86
|
|
|
'name' => 'Edit a Wish List', |
87
|
|
|
'category' => 'Wish List Permissions', |
88
|
|
|
], |
89
|
|
|
'WishList_DELETE' => [ |
90
|
|
|
'name' => 'Delete a Wish List', |
91
|
|
|
'category' => 'Wish List Permissions', |
92
|
|
|
], |
93
|
|
|
'WishList_CREATE' => [ |
94
|
|
|
'name' => 'Create a Wish List', |
95
|
|
|
'category' => 'Wish List Permissions', |
96
|
|
|
], |
97
|
|
|
'WishList_VIEW' => [ |
98
|
|
|
'name' => 'View a Wish List', |
99
|
|
|
'category' => 'Wish List Permissions', |
100
|
|
|
], |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
$this->assertEquals($expected, Injector::inst()->get('ProductWishList')->providePermissions()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* |
108
|
|
|
*/ |
109
|
|
|
public function testGetViewAction() |
110
|
|
|
{ |
111
|
|
|
$this->assertEquals('view', Injector::inst()->get('ProductWishList')->getViewAction()); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* |
116
|
|
|
*/ |
117
|
|
|
public function testGetFrontEndRequiredFields() |
118
|
|
|
{ |
119
|
|
|
$this->assertInstanceOf('RequiredFields', |
120
|
|
|
Injector::inst()->get('ProductWishList')->getFrontEndRequiredFields()); |
121
|
|
|
|
122
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'one'); |
123
|
|
|
$this->assertTrue($wishList->getFrontEndRequiredFields()->fieldIsRequired('OtherField')); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* |
128
|
|
|
*/ |
129
|
|
|
public function testGetFrontEndActions() |
130
|
|
|
{ |
131
|
|
|
$this->assertInstanceOf('FieldList', Injector::inst()->get('ProductWishList')->getFrontEndActions()); |
132
|
|
|
|
133
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'one'); |
134
|
|
|
$this->assertNull($wishList->getFrontEndActions()->dataFieldByName('action_CancelFormAction')); |
|
|
|
|
135
|
|
|
$this->assertInstanceOf('CancelFormAction', |
136
|
|
|
$wishList->getFrontEndActions(true)->dataFieldByName('action_CancelFormAction')); |
137
|
|
|
|
138
|
|
|
$this->assertInstanceOf('FormAction', $wishList->getFrontEndActions()->dataFieldByName('action_OtherAction')); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* |
143
|
|
|
*/ |
144
|
|
|
public function testGetFrontEndFields() |
145
|
|
|
{ |
146
|
|
|
$baseFields = Injector::inst()->get('ProductWishList')->getFrontEndFields(); |
147
|
|
|
$this->assertInstanceOf('FieldList', $baseFields); |
148
|
|
|
$this->assertNull($baseFields->fieldByName('MemberID')); |
|
|
|
|
149
|
|
|
|
150
|
|
|
$wishList = $this->objFromFixture('TestProductWishList', 'four'); |
151
|
|
|
$updatedFields = $wishList->getFrontEndFields(); |
152
|
|
|
$this->assertInstanceOf('FieldList', $updatedFields); |
153
|
|
|
$this->assertInstanceOf('TextareaField', $updatedFields->dataFieldByName('OtherField')); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |
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.