1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2016 Jan Eichhorn <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApaiIO\Test\Operations\Types; |
19
|
|
|
|
20
|
|
|
use ApaiIO\Operations\CartModify; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
|
23
|
|
|
class CartModifyTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testSetter() |
26
|
|
|
{ |
27
|
|
|
$operation = new CartModify(); |
28
|
|
|
$operation->setHMAC('1234'); |
29
|
|
|
$operation->setCartId('789'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetName() |
33
|
|
|
{ |
34
|
|
|
$operation = new CartModify(); |
35
|
|
|
$this->assertEquals('CartModify', $operation->getName()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testGetCartId() |
39
|
|
|
{ |
40
|
|
|
$operation = new CartModify(); |
41
|
|
|
$this->assertEquals(null, $operation->getCartId()); |
42
|
|
|
$operation->setCartId('789'); |
43
|
|
|
$this->assertEquals('789', $operation->getCartId()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetHMAC() |
47
|
|
|
{ |
48
|
|
|
$operation = new CartModify(); |
49
|
|
|
$this->assertEquals(null, $operation->getHMAC()); |
50
|
|
|
$operation->setHMAC('1234'); |
51
|
|
|
$this->assertEquals('1234', $operation->getHMAC()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testCountable() |
55
|
|
|
{ |
56
|
|
|
$operation = new CartModify(); |
57
|
|
|
$this->assertEquals(0, count($operation)); |
58
|
|
|
|
59
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
60
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
61
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
62
|
|
|
$operation->modifyAction('dummyId1', 'SaveForLater'); |
63
|
|
|
|
64
|
|
|
$this->assertEquals(4, count($operation)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @expectedException \OverflowException |
69
|
|
|
*/ |
70
|
|
|
public function testModifyQuantityModificationLimit() |
71
|
|
|
{ |
72
|
|
|
$operation = new CartModify(); |
73
|
|
|
|
74
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
75
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
76
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
77
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
78
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
79
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
80
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
81
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
82
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
83
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
84
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
85
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testModifyActionMoveToCart() |
89
|
|
|
{ |
90
|
|
|
$operation = new CartModify(); |
91
|
|
|
$operation->modifyAction('dummyId1', 'MoveToCart'); |
92
|
|
|
|
93
|
|
|
$this->assertEquals(1, count($operation)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testModifyActionSaveForLater() |
97
|
|
|
{ |
98
|
|
|
$operation = new CartModify(); |
99
|
|
|
$operation->modifyAction('dummyId1', 'SaveForLater'); |
100
|
|
|
|
101
|
|
|
$this->assertEquals(1, count($operation)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @expectedException \OutOfRangeException |
106
|
|
|
*/ |
107
|
|
|
public function testModifyActionWrongType() |
108
|
|
|
{ |
109
|
|
|
$operation = new CartModify(); |
110
|
|
|
$operation->modifyAction('dummyId1', 13); |
111
|
|
|
|
112
|
|
|
$this->assertEquals(1, count($operation)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @expectedException \OutOfRangeException |
117
|
|
|
*/ |
118
|
|
|
public function testModifyActionInvalidOption() |
119
|
|
|
{ |
120
|
|
|
$operation = new CartModify(); |
121
|
|
|
$operation->modifyAction('dummyId1', 13); |
122
|
|
|
|
123
|
|
|
$this->assertEquals(1, count($operation)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testModifyQuantityQuantityMinLimit() |
127
|
|
|
{ |
128
|
|
|
$operation = new CartModify(); |
129
|
|
|
$operation->modifyQuantity('dummyId1', 0); |
130
|
|
|
|
131
|
|
|
$this->assertEquals(1, count($operation)); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @expectedException \OutOfRangeException |
136
|
|
|
*/ |
137
|
|
|
public function testModifyQuantityQuantityUnderMinLimit() |
138
|
|
|
{ |
139
|
|
|
$operation = new CartModify(); |
140
|
|
|
$operation->modifyQuantity('dummyId1', -1); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testModifyQuantityQuantityMaxLimit() |
144
|
|
|
{ |
145
|
|
|
$operation = new CartModify(); |
146
|
|
|
$operation->modifyQuantity('dummyId1', 999); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @expectedException \OutOfRangeException |
151
|
|
|
*/ |
152
|
|
|
public function testModifyQuantityQuantityOverMaxLimit() |
153
|
|
|
{ |
154
|
|
|
$operation = new CartModify(); |
155
|
|
|
$operation->modifyQuantity('dummyId1', 1000); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @expectedException \InvalidArgumentException |
160
|
|
|
* @expectedExceptionMessage quantity must be integer, string given |
161
|
|
|
*/ |
162
|
|
|
public function testModifyQuantityQuantityWrongType() |
163
|
|
|
{ |
164
|
|
|
$operation = new CartModify(); |
165
|
|
|
$operation->modifyQuantity('dummyId1', '3'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @expectedException \InvalidArgumentException |
170
|
|
|
* @expectedExceptionMessage quantity must be integer, double given |
171
|
|
|
*/ |
172
|
|
|
public function testModifyQuantityQuantityWrongType2() |
173
|
|
|
{ |
174
|
|
|
$operation = new CartModify(); |
175
|
|
|
$operation->modifyQuantity('dummyId1', 3.3); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|