1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Inventory\Test\Extension; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Extension\Purchasable; |
6
|
|
|
use Dynamic\Foxy\Form\AddToCartForm; |
7
|
|
|
use Dynamic\Foxy\Inventory\Extension\AddToCartFormExtension; |
8
|
|
|
use Dynamic\Foxy\Inventory\Extension\ProductExpirationManager; |
9
|
|
|
use Dynamic\Foxy\Inventory\Extension\ProductInventoryManager; |
10
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Form\TestAddToCartForm; |
11
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct; |
12
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProductController; |
13
|
|
|
use SilverStripe\Core\Config\Config; |
14
|
|
|
use SilverStripe\Dev\SapphireTest; |
15
|
|
|
use SilverStripe\Forms\FieldList; |
16
|
|
|
|
17
|
|
|
class AddToCartFormExtensionTest extends SapphireTest |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected static $extra_dataobjects = [ |
28
|
|
|
TestProduct::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected static $required_extensions = [ |
35
|
|
|
AddToCartForm::class => [ |
36
|
|
|
AddToCartFormExtension::class, |
37
|
|
|
], |
38
|
|
|
TestProduct::class => [ |
39
|
|
|
Purchasable::class, |
40
|
|
|
ProductInventoryManager::class, |
41
|
|
|
ProductExpirationManager::class, |
42
|
|
|
], |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected static $extra_controllers = [ |
49
|
|
|
TestProductController::class, |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
protected function setUp() |
56
|
|
|
{ |
57
|
|
|
parent::setUp(); |
58
|
|
|
|
59
|
|
|
Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
public function testUpdateProductFields() |
66
|
|
|
{ |
67
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
68
|
|
|
$controller = TestProductController::create($object); |
69
|
|
|
$form = AddToCartForm::create($controller, __FUNCTION__, null, null, null, $controller->data()); |
70
|
|
|
$fields = $form->Fields(); |
71
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
72
|
|
|
$this->assertNotNull($fields->dataFieldByName('expires')); |
73
|
|
|
|
74
|
|
|
// todo: add assertions to cover isOutOfStock() check via fixtures |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* |
79
|
|
|
*/ |
80
|
|
|
public function testUpdateProductActions() |
81
|
|
|
{ |
82
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
83
|
|
|
$controller = TestProductController::create($object); |
84
|
|
|
$form = $controller->AddToCartForm(); |
85
|
|
|
$fields = $form->Actions(); |
86
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
87
|
|
|
|
88
|
|
|
// todo: add assertions to cover isOutOfStock() check via fixtures |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* |
93
|
|
|
*/ |
94
|
|
|
public function testIsOutOfStock() |
95
|
|
|
{ |
96
|
|
|
$this->markTestSkipped(); |
97
|
|
|
// todo: write test to test out of stock via fixtures |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|