Passed
Push — master ( d83585...c5f1b0 )
by Jason
10:27
created

ProductExpirationManagerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 26
c 1
b 0
f 0
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 6 1
A setUp() 0 6 1
A testGetCartReservations() 0 18 3
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Test\Extension;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use Dynamic\Foxy\Inventory\Extension\ProductExpirationManager;
7
use Dynamic\Foxy\Inventory\Extension\ProductInventoryManager;
8
use Dynamic\Foxy\Inventory\Model\CartReservation;
9
use Dynamic\Foxy\Inventory\Test\TestOnly\Page\TestProduct;
10
use Dynamic\Foxy\Model\Variation;
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Model\Variation was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SilverStripe\Core\Config\Config;
12
use SilverStripe\Dev\SapphireTest;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\Forms\GridField\GridField;
15
16
class ProductExpirationManagerTest extends SapphireTest
17
{
18
    /**
19
     * @var string
20
     */
21
    protected static $fixture_file = '../fixtures.yml';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $extra_dataobjects = [
27
        TestProduct::class,
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    protected static $required_extensions = [
34
        TestProduct::class => [
35
            Purchasable::class,
36
            ProductInventoryManager::class,
37
            ProductExpirationManager::class,
38
        ],
39
    ];
40
41
    /**
42
     *
43
     */
44
    protected function setUp()
45
    {
46
        parent::setUp();
47
48
        Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false);
49
        Config::modify()->set(Variation::class, 'has_one', ['TestProduct' => TestProduct::class]);
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testGetCMSFields()
56
    {
57
        $object = $this->objFromFixture(TestProduct::class, 'one');
58
        $fields = $object->getCMSFields();
59
        $this->assertInstanceOf(FieldList::class, $fields);
60
        $this->assertInstanceOf(GridField::class, $fields->dataFieldByName('CartReservations'));
61
    }
62
63
    /**
64
     * @throws \SilverStripe\ORM\ValidationException
65
     */
66
    public function testGetCartReservations()
67
    {
68
        $object = $this->objFromFixture(TestProduct::class, 'one');
69
70
        $this->assertEquals(0, $object->getCartReservations()->count());
71
72
        for ($i = 0; $i < 5; $i++) {
73
            $reservation = CartReservation::create();
74
            if ($i < 3) {
75
                $reservation->Expires = date('Y-m-d H:i:s', strtotime('tomorrow'));
76
            }
77
            $reservation->ProductID = $object->ID;
78
            $reservation->write();
79
        }
80
81
        $object2 = TestProduct::get()->byID($object->ID);
82
83
        $this->assertEquals(3, $object2->getCartReservations()->count());
84
    }
85
}
86