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