1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Test\Form; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Extension\Purchasable; |
6
|
|
|
use Dynamic\Foxy\Extension\Shippable; |
7
|
|
|
use Dynamic\Foxy\Form\AddToCartForm; |
8
|
|
|
use Dynamic\Foxy\Model\Variation; |
9
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestProduct; |
10
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestShippableProduct; |
11
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestShippableProductController; |
12
|
|
|
use Dynamic\Foxy\Test\TestOnly\TestVariation; |
13
|
|
|
use SilverStripe\Core\Config\Config; |
14
|
|
|
use SilverStripe\Core\Injector\Injector; |
15
|
|
|
use SilverStripe\Dev\SapphireTest; |
16
|
|
|
use SilverStripe\Forms\FieldList; |
17
|
|
|
use SilverStripe\Forms\Form; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class AddToCartFormTest |
21
|
|
|
* @package Dynamic\Foxy\Test\Form |
22
|
|
|
*/ |
23
|
|
|
class AddToCartFormTest extends SapphireTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected static $extra_dataobjects = [ |
34
|
|
|
TestProduct::class, |
35
|
|
|
TestVariation::class, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \string[][] |
40
|
|
|
*/ |
41
|
|
|
protected static $required_extensions = [ |
42
|
|
|
TestProduct::class => [ |
43
|
|
|
Purchasable::class, |
44
|
|
|
], |
45
|
|
|
TestShippableProduct::class => [ |
46
|
|
|
Purchasable::class, |
47
|
|
|
Shippable::class, |
48
|
|
|
], |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* |
53
|
|
|
*/ |
54
|
|
|
public function setUp() |
55
|
|
|
{ |
56
|
|
|
Config::modify()->set(TestVariation::class, 'has_one', ['Product' => TestProduct::class]); |
57
|
|
|
|
58
|
|
|
return parent::setUp(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
|
public function testConstruct() |
65
|
|
|
{ |
66
|
|
|
$object = Injector::inst()->create(TestShippableProduct::class); |
67
|
|
|
$controller = TestShippableProductController::create($object); |
68
|
|
|
$form = $controller->AddToCartForm($controller, __FUNCTION__, null, null, null, $object); |
69
|
|
|
$this->assertInstanceOf(Form::class, $form); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
*/ |
75
|
|
|
public function testGetProductFields() |
76
|
|
|
{ |
77
|
|
|
$object = Injector::inst()->create(TestShippableProduct::class); |
78
|
|
|
$object->Weight = 1.0; |
79
|
|
|
$controller = TestShippableProductController::create($object); |
80
|
|
|
$form = $controller->AddToCartForm($controller, __FUNCTION__, null, null, null, $object); |
81
|
|
|
$fields = $form->Fields(); |
82
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
|
|
public function testGetProductActions() |
89
|
|
|
{ |
90
|
|
|
$object = Injector::inst()->create(TestShippableProduct::class); |
91
|
|
|
$controller = TestShippableProductController::create($object); |
92
|
|
|
$form = $controller->AddToCartForm($controller, __FUNCTION__, null, null, null, $object); |
93
|
|
|
$fields = $form->Actions(); |
94
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|