|
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
|
|
|
|
|
22
|
|
|
class CartModifyTest extends \PHPUnit_Framework_TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testSetter() |
|
25
|
|
|
{ |
|
26
|
|
|
$operation = new CartModify(); |
|
27
|
|
|
$operation->setHMAC('1234'); |
|
28
|
|
|
$operation->setCartId('789'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetName() |
|
32
|
|
|
{ |
|
33
|
|
|
$operation = new CartModify(); |
|
34
|
|
|
$this->assertEquals('CartModify', $operation->getName()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetCartId() |
|
38
|
|
|
{ |
|
39
|
|
|
$operation = new CartModify(); |
|
40
|
|
|
$this->assertEquals(null, $operation->getCartId()); |
|
41
|
|
|
$operation->setCartId('789'); |
|
42
|
|
|
$this->assertEquals('789', $operation->getCartId()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGetHMAC() |
|
46
|
|
|
{ |
|
47
|
|
|
$operation = new CartModify(); |
|
48
|
|
|
$this->assertEquals(null, $operation->getHMAC()); |
|
49
|
|
|
$operation->setHMAC('1234'); |
|
50
|
|
|
$this->assertEquals('1234', $operation->getHMAC()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testCountable() |
|
54
|
|
|
{ |
|
55
|
|
|
$operation = new CartModify(); |
|
56
|
|
|
$this->assertEquals(0, count($operation)); |
|
57
|
|
|
|
|
58
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
59
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
60
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
|
61
|
|
|
$operation->modifyAction('dummyId1', 'SaveForLater'); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals(4, count($operation)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @expectedException \OverflowException |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testModifyQuantityModificationLimit() |
|
70
|
|
|
{ |
|
71
|
|
|
$operation = new CartModify(); |
|
72
|
|
|
|
|
73
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
74
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
75
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
|
76
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
77
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
78
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
|
79
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
80
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
81
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
|
82
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
83
|
|
|
$operation->modifyQuantity('dummyId1', 1); |
|
84
|
|
|
$operation->modifyQuantity('dummyId2', 1); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testModifyActionMoveToCart() |
|
88
|
|
|
{ |
|
89
|
|
|
$operation = new CartModify(); |
|
90
|
|
|
$operation->modifyAction('dummyId1', 'MoveToCart'); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals(1, count($operation)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testModifyActionSaveForLater() |
|
96
|
|
|
{ |
|
97
|
|
|
$operation = new CartModify(); |
|
98
|
|
|
$operation->modifyAction('dummyId1', 'SaveForLater'); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertEquals(1, count($operation)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @expectedException \OutOfRangeException |
|
105
|
|
|
*/ |
|
106
|
|
|
public function testModifyActionWrongType() |
|
107
|
|
|
{ |
|
108
|
|
|
$operation = new CartModify(); |
|
109
|
|
|
$operation->modifyAction('dummyId1', 13); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertEquals(1, count($operation)); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @expectedException \OutOfRangeException |
|
116
|
|
|
*/ |
|
117
|
|
|
public function testModifyActionInvalidOption() |
|
118
|
|
|
{ |
|
119
|
|
|
$operation = new CartModify(); |
|
120
|
|
|
$operation->modifyAction('dummyId1', 13); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertEquals(1, count($operation)); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testModifyQuantityQuantityMinLimit() |
|
126
|
|
|
{ |
|
127
|
|
|
$operation = new CartModify(); |
|
128
|
|
|
$operation->modifyQuantity('dummyId1', 0); |
|
129
|
|
|
|
|
130
|
|
|
$this->assertEquals(1, count($operation)); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @expectedException \OutOfRangeException |
|
135
|
|
|
*/ |
|
136
|
|
|
public function testModifyQuantityQuantityUnderMinLimit() |
|
137
|
|
|
{ |
|
138
|
|
|
$operation = new CartModify(); |
|
139
|
|
|
$operation->modifyQuantity('dummyId1', -1); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function testModifyQuantityQuantityMaxLimit() |
|
143
|
|
|
{ |
|
144
|
|
|
$operation = new CartModify(); |
|
145
|
|
|
$operation->modifyQuantity('dummyId1', 999); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @expectedException \OutOfRangeException |
|
150
|
|
|
*/ |
|
151
|
|
|
public function testModifyQuantityQuantityOverMaxLimit() |
|
152
|
|
|
{ |
|
153
|
|
|
$operation = new CartModify(); |
|
154
|
|
|
$operation->modifyQuantity('dummyId1', 1000); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @expectedException \InvalidArgumentException |
|
159
|
|
|
* @expectedExceptionMessage quantity must be integer, string given |
|
160
|
|
|
*/ |
|
161
|
|
|
public function testModifyQuantityQuantityWrongType() |
|
162
|
|
|
{ |
|
163
|
|
|
$operation = new CartModify(); |
|
164
|
|
|
$operation->modifyQuantity('dummyId1', '3'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @expectedException \InvalidArgumentException |
|
169
|
|
|
* @expectedExceptionMessage quantity must be integer, double given |
|
170
|
|
|
*/ |
|
171
|
|
|
public function testModifyQuantityQuantityWrongType2() |
|
172
|
|
|
{ |
|
173
|
|
|
$operation = new CartModify(); |
|
174
|
|
|
$operation->modifyQuantity('dummyId1', 3.3); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|