Passed
Pull Request — master (#7)
by Jason
01:50
created

AddToCartFormExtensionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 21
c 3
b 0
f 0
dl 0
loc 65
rs 10

3 Methods

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