1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Test\Model; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Extension\Purchasable; |
6
|
|
|
use Dynamic\Foxy\Model\OptionType; |
|
|
|
|
7
|
|
|
use Dynamic\Foxy\Model\Variation; |
8
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestProduct; |
9
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestVariationDataExtension; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
use SilverStripe\Forms\FieldList; |
13
|
|
|
use SilverStripe\Security\Member; |
14
|
|
|
use SilverStripe\Versioned\Versioned; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class ProductOptionTest |
18
|
|
|
* @package Dynamic\Foxy\Test\Model |
19
|
|
|
*/ |
20
|
|
|
class VariationTest extends SapphireTest |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
public static $extra_dataobjects = [ |
31
|
|
|
TestProduct::class, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \string[][] |
36
|
|
|
*/ |
37
|
|
|
protected static $required_extensions = [ |
38
|
|
|
TestProduct::class => [ |
39
|
|
|
Purchasable::class, |
40
|
|
|
], |
41
|
|
|
Variation::class => [ |
42
|
|
|
TestVariationDataExtension::class, |
43
|
|
|
], |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* |
48
|
|
|
*/ |
49
|
|
|
public function testGetCMSFields() |
50
|
|
|
{ |
51
|
|
|
$object = singleton(Variation::class); |
52
|
|
|
$fields = $object->getCMSFields(); |
53
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* |
58
|
|
|
*/ |
59
|
|
|
public function testCanCreate() |
60
|
|
|
{ |
61
|
|
|
/** @var ProductOption $object */ |
62
|
|
|
$object = singleton(Variation::class); |
63
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
64
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
65
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
66
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
67
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
68
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
69
|
|
|
|
70
|
|
|
$this->assertFalse($object->canCreate($default)); |
71
|
|
|
$this->assertTrue($object->canCreate($admin)); |
72
|
|
|
$this->assertTrue($object->canCreate($siteOwner)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
public function testCanEdit() |
79
|
|
|
{ |
80
|
|
|
/** @var ProductOption $object */ |
81
|
|
|
$object = singleton(Variation::class); |
82
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
83
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
84
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
85
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
86
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
87
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
88
|
|
|
|
89
|
|
|
$this->assertFalse($object->canEdit($default)); |
90
|
|
|
$this->assertTrue($object->canEdit($admin)); |
91
|
|
|
$this->assertTrue($object->canEdit($siteOwner)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
|
public function testCanDelete() |
98
|
|
|
{ |
99
|
|
|
/** @var ProductOption $object */ |
100
|
|
|
$object = singleton(Variation::class); |
101
|
|
|
/** @var \SilverStripe\Security\Member $admin */ |
102
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
103
|
|
|
/** @var \SilverStripe\Security\Member $siteOwner */ |
104
|
|
|
$siteOwner = $this->objFromFixture(Member::class, 'site-owner'); |
105
|
|
|
/** @var \SilverStripe\Security\Member $default */ |
106
|
|
|
$default = $this->objFromFixture(Member::class, 'default'); |
107
|
|
|
|
108
|
|
|
$this->assertFalse($object->canDelete($default)); |
109
|
|
|
$this->assertTrue($object->canDelete($admin)); |
110
|
|
|
$this->assertTrue($object->canDelete($siteOwner)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
115
|
|
|
*/ |
116
|
|
|
public function testGenerateKey() |
117
|
|
|
{ |
118
|
|
|
$this->markTestSkipped(); |
119
|
|
|
/*$product = $this->findOrMakeProduct(); |
120
|
|
|
$option = ProductOption::create(); |
121
|
|
|
//$option->write(); |
122
|
|
|
|
123
|
|
|
$option->Title = $title = 'My Title'; |
124
|
|
|
$price = 150; |
125
|
|
|
$action = 'Set'; |
126
|
|
|
|
127
|
|
|
$product->Options()->add( |
128
|
|
|
$option, |
129
|
|
|
[ |
130
|
|
|
'Available' => true, |
131
|
|
|
'PriceModifier' => $price, |
132
|
|
|
'PriceModifierAction' => $action, |
133
|
|
|
] |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
$actionSymbol = ProductOption::getOptionModifierActionSymbol($action); |
137
|
|
|
|
138
|
|
|
$expected = "{$title}{p{$actionSymbol}{$price}|w+0|c+0}"; |
139
|
|
|
|
140
|
|
|
$option = $product->Options()->filter('ProductOptionID', $option->ID)->first(); |
141
|
|
|
|
142
|
|
|
$this->assertEquals( |
143
|
|
|
$expected, |
144
|
|
|
$option->OptionModifierKey |
145
|
|
|
);//*/ |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return TestProduct|\SilverStripe\ORM\DataObject |
150
|
|
|
*/ |
151
|
|
|
protected function findOrMakeProduct() |
152
|
|
|
{ |
153
|
|
|
if (!$product = TestProduct::get()->first()) { |
154
|
|
|
$product = TestProduct::create(); |
155
|
|
|
$product->Title = 'My Product'; |
156
|
|
|
$product->writeToStage(Versioned::DRAFT); |
157
|
|
|
$product->publishSingle(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $product; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths