1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Wishlist\Test\Model; |
4
|
|
|
|
5
|
|
|
use Dynamic\Wishlist\Model\ProductWishList; |
6
|
|
|
use Dynamic\Wishlist\Test\Extra\TestProductWishList; |
7
|
|
|
use Dynamic\Wishlist\Test\Extra\TestWishListPage; |
8
|
|
|
use SilverStripe\Core\Injector\Injector; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\Forms\RequiredFields; |
12
|
|
|
use SilverStripe\Forms\TextareaField; |
13
|
|
|
use SilverStripe\Security\Member; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class TestProductWishListTest |
17
|
|
|
*/ |
18
|
|
|
class ProductWishListTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected static $extra_dataobjects = [ |
30
|
|
|
TestWishListPage::class, |
31
|
|
|
TestProductWishList::class, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
*/ |
37
|
|
|
public function testCanCreate() |
38
|
|
|
{ |
39
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
40
|
|
|
$canAccess = $this->objFromFixture(Member::class, 'cancreate'); |
41
|
|
|
$cantAccess = $this->objFromFixture(Member::class, 'cantcreate'); |
42
|
|
|
|
43
|
|
|
$this->assertTrue($wishList->canCreate($canAccess)); |
44
|
|
|
$this->assertFalse($wishList->canCreate($cantAccess)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
*/ |
50
|
|
|
public function testCanEdit() |
51
|
|
|
{ |
52
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
53
|
|
|
$canAccess = $this->objFromFixture(Member::class, 'cancreate'); |
54
|
|
|
$cantAccess = $this->objFromFixture(Member::class, 'cantcreate'); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->assertTrue($wishList->canEdit($canAccess)); |
57
|
|
|
//$this->assertFalse($wishList->canEdit($cantAccess)); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function testCanDelete() |
64
|
|
|
{ |
65
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
66
|
|
|
$canAccess = $this->objFromFixture(Member::class, 'cancreate'); |
67
|
|
|
$cantAccess = $this->objFromFixture(Member::class, 'cantcreate'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this->assertTrue($wishList->canDelete($canAccess)); |
70
|
|
|
//$this->assertFalse($wishList->canDelete($cantAccess)); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
public function testCanView() |
77
|
|
|
{ |
78
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
79
|
|
|
$canAccess = $this->objFromFixture(Member::class, 'cancreate'); |
80
|
|
|
$cantAccess = $this->objFromFixture(Member::class, 'cantcreate'); |
81
|
|
|
|
82
|
|
|
$this->assertTrue($wishList->canView($canAccess)); |
83
|
|
|
//todo fix following assertion |
84
|
|
|
//$this->assertFalse($wishList->canView($cantAccess)); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$viewableWishList = $this->objFromFixture(TestProductWishList::class, 'three'); |
87
|
|
|
|
88
|
|
|
$this->assertTrue($viewableWishList->canView($cantAccess)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* |
93
|
|
|
*/ |
94
|
|
|
public function testProvidePermissions() |
95
|
|
|
{ |
96
|
|
|
$expected = [ |
97
|
|
|
'WishList_EDIT' => [ |
98
|
|
|
'name' => 'Edit a Wish List', |
99
|
|
|
'category' => 'Wish List Permissions', |
100
|
|
|
], |
101
|
|
|
'WishList_DELETE' => [ |
102
|
|
|
'name' => 'Delete a Wish List', |
103
|
|
|
'category' => 'Wish List Permissions', |
104
|
|
|
], |
105
|
|
|
'WishList_CREATE' => [ |
106
|
|
|
'name' => 'Create a Wish List', |
107
|
|
|
'category' => 'Wish List Permissions', |
108
|
|
|
], |
109
|
|
|
'WishList_VIEW' => [ |
110
|
|
|
'name' => 'View a Wish List', |
111
|
|
|
'category' => 'Wish List Permissions', |
112
|
|
|
], |
113
|
|
|
]; |
114
|
|
|
|
115
|
|
|
$this->assertEquals($expected, Injector::inst()->get(ProductWishList::class)->providePermissions()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* |
120
|
|
|
*/ |
121
|
|
|
public function testGetViewAction() |
122
|
|
|
{ |
123
|
|
|
$this->assertEquals('view', Injector::inst()->get(ProductWishList::class)->getViewAction()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* |
128
|
|
|
*/ |
129
|
|
|
public function testGetFrontEndRequiredFields() |
130
|
|
|
{ |
131
|
|
|
$this->assertInstanceOf( |
132
|
|
|
RequiredFields::class, |
133
|
|
|
Injector::inst()->get(ProductWishList::class)->getFrontEndRequiredFields() |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
/** @var TestProductWishList $wishList */ |
137
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
138
|
|
|
$this->assertTrue($wishList->getFrontEndRequiredFields()->fieldIsRequired('OtherField')); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* |
143
|
|
|
*/ |
144
|
|
|
public function testGetFrontEndActions() |
145
|
|
|
{ |
146
|
|
|
$this->assertInstanceOf( |
147
|
|
|
FieldList::class, |
148
|
|
|
Injector::inst()->get(ProductWishList::class)->getFrontEndActions() |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
/** @var TestProductWishList $wishList */ |
152
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'one'); |
153
|
|
|
$this->assertNull($wishList->getFrontEndActions()->dataFieldByName('action_CancelFormAction')); |
154
|
|
|
$this->assertInstanceOf('CancelFormAction', |
155
|
|
|
$wishList->getFrontEndActions(true)->dataFieldByName('action_CancelFormAction')); |
156
|
|
|
|
157
|
|
|
$this->assertInstanceOf('FormAction', $wishList->getFrontEndActions()->dataFieldByName('action_OtherAction')); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* |
162
|
|
|
*/ |
163
|
|
|
public function testGetFrontEndFields() |
164
|
|
|
{ |
165
|
|
|
/** @var ProductWishList $baseWishList */ |
166
|
|
|
$baseWishList = Injector::inst()->get(ProductWishList::class); |
167
|
|
|
$baseFields = $baseWishList->getFrontEndFields(); |
168
|
|
|
$this->assertInstanceOf(FieldList::class, $baseFields); |
169
|
|
|
$this->assertNull($baseFields->fieldByName('MemberID')); |
170
|
|
|
|
171
|
|
|
/** @var TestProductWishList $wishList */ |
172
|
|
|
$wishList = $this->objFromFixture(TestProductWishList::class, 'four'); |
173
|
|
|
$updatedFields = $wishList->getFrontEndFields(); |
174
|
|
|
$this->assertInstanceOf(FieldList::class, $updatedFields); |
175
|
|
|
$this->assertInstanceOf(TextareaField::class, $updatedFields->dataFieldByName('OtherField')); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
} |
179
|
|
|
|