1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Inventory\Test\Extension; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Form\AddToCartForm; |
6
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Form\TestAddToCartForm; |
7
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct; |
8
|
|
|
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProductController; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
|
12
|
|
|
class AddToCartFormExtensionTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected static $extra_dataobjects = [ |
23
|
|
|
TestProduct::class, |
24
|
|
|
TestAddToCartForm::class, |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected static $extra_controllers = [ |
31
|
|
|
TestProductController::class, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
*/ |
37
|
|
|
public function testUpdateProductFields() |
38
|
|
|
{ |
39
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
40
|
|
|
$controller = TestProductController::create($object); |
41
|
|
|
AddToCartForm::create($this->owner, __FUNCTION__, null, null, null, $controller->data()); |
|
|
|
|
42
|
|
|
$fields = $form->Fields(); |
|
|
|
|
43
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
44
|
|
|
$this->assertNotNull($fields->dataFieldByName('expires')); |
45
|
|
|
|
46
|
|
|
// todo: add assertions to cover isOutOfStock() check via fixtures |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
|
|
public function testUpdateProductActions() |
53
|
|
|
{ |
54
|
|
|
$object = $this->objFromFixture(TestProduct::class, 'one'); |
55
|
|
|
$controller = TestProductController::create($object); |
56
|
|
|
$form = $controller->AddToCartForm(); |
57
|
|
|
$fields = $form->Actions(); |
58
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
59
|
|
|
|
60
|
|
|
// todo: add assertions to cover isOutOfStock() check via fixtures |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
public function testIsOutOfStock() |
67
|
|
|
{ |
68
|
|
|
$this->markTestSkipped(); |
69
|
|
|
// todo: write test to test out of stock via fixtures |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|