Class CompareTest
Definition at line 12 of file CompareTest.php.
◆ getOptionMock()
getOptionMock |
( |
|
$code, |
|
|
|
$value |
|
) |
| |
|
protected |
- Parameters
-
- Returns
- \PHPUnit_Framework_MockObject_MockObject
Definition at line 87 of file CompareTest.php.
89 $optionMock = clone $this->optionMock;
90 $optionMock->expects($this->once())
92 ->will($this->returnValue(
$code));
93 $optionMock->expects($this->once())
95 ->will($this->returnValue(
$value));
◆ setUp()
test setUp
Definition at line 42 of file CompareTest.php.
44 $this->itemMock = $this->createPartialMock(
45 \
Magento\Quote\Model\Quote\Item::class,
46 [
'__wakeup',
'getProductId',
'getOptions']
48 $this->comparedMock = $this->createPartialMock(
49 \
Magento\Quote\Model\Quote\Item::class,
50 [
'__wakeup',
'getProductId',
'getOptions']
52 $this->optionMock = $this->createPartialMock(
53 \
Magento\Quote\Model\Quote\Item\Option::class,
54 [
'__wakeup',
'getCode',
'getValue']
56 $serializer = $this->getMockBuilder(\
Magento\Framework\Serialize\Serializer\Json::class)
57 ->setMethods([
'unserialize'])
58 ->disableOriginalConstructor()
59 ->getMockForAbstractClass();
61 ->method(
'unserialize')
64 return json_decode(
$value,
true);
68 $this->jsonValidatorMock = $this->getMockBuilder(\
Magento\Framework\Serialize\JsonValidator::class)
69 ->disableOriginalConstructor()
72 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
73 $this->helper = $objectManagerHelper->getObject(
74 \
Magento\Quote\Model\Quote\Item\Compare::class,
77 'jsonValidator' => $this->jsonValidatorMock
◆ testCompareDifferentProduct()
testCompareDifferentProduct |
( |
| ) |
|
test compare two different products
Definition at line 102 of file CompareTest.php.
104 $this->itemMock->expects($this->once())
105 ->method(
'getProductId')
106 ->will($this->returnValue(1));
107 $this->itemMock->expects($this->once())
108 ->method(
'getProductId')
109 ->will($this->returnValue(2));
111 $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
◆ testCompareItemWithComparedWithoutOption()
testCompareItemWithComparedWithoutOption |
( |
| ) |
|
test compare two items first with options and second without options
Definition at line 155 of file CompareTest.php.
157 $this->itemMock->expects($this->any())
158 ->method(
'getProductId')
159 ->will($this->returnValue(1));
160 $this->comparedMock->expects($this->any())
161 ->method(
'getProductId')
162 ->will($this->returnValue(1));
163 $this->itemMock->expects($this->any())
164 ->method(
'getOptions')
170 $this->
getOptionMock(
'option-3', json_encode([
'value' =>
'value-1',
'qty' => 2])),
174 $this->comparedMock->expects($this->any())
175 ->method(
'getOptions')
176 ->will($this->returnValue([]));
177 $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
getOptionMock($code, $value)
◆ testCompareItemWithoutOptionWithCompared()
testCompareItemWithoutOptionWithCompared |
( |
| ) |
|
test compare two items first without options and second with options
Definition at line 183 of file CompareTest.php.
185 $this->itemMock->expects($this->any())
186 ->method(
'getProductId')
187 ->will($this->returnValue(1));
188 $this->comparedMock->expects($this->any())
189 ->method(
'getProductId')
190 ->will($this->returnValue(1));
191 $this->comparedMock->expects($this->any())
192 ->method(
'getOptions')
193 ->will($this->returnValue(
199 json_encode([
'value' =>
'value-1',
'qty' => 2])
203 $this->itemMock->expects($this->any())
204 ->method(
'getOptions')
205 ->will($this->returnValue([]));
206 $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
getOptionMock($code, $value)
◆ testCompareProductWithDifferentOptions()
testCompareProductWithDifferentOptions |
( |
| ) |
|
test compare two items with different options
Definition at line 117 of file CompareTest.php.
119 $this->itemMock->expects($this->any())
120 ->method(
'getProductId')
121 ->will($this->returnValue(1));
122 $this->comparedMock->expects($this->any())
123 ->method(
'getProductId')
124 ->will($this->returnValue(1));
126 $this->itemMock->expects($this->any())
127 ->method(
'getOptions')
133 $this->
getOptionMock(
'option-3', json_encode([
'value' =>
'value-1',
'qty' => 2]))
137 $this->comparedMock->expects($this->any())
138 ->method(
'getOptions')
139 ->will($this->returnValue(
144 'value' =>
'value-1',
149 $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
getOptionMock($code, $value)
◆ testCompareWithEmptyValues()
testCompareWithEmptyValues |
( |
| ) |
|
Verify that compare ignores empty options.
Definition at line 212 of file CompareTest.php.
214 $itemOptionValue =
'{"non-empty-option":"test","empty_option":""}';
215 $comparedOptionValue =
'{"non-empty-option":"test"}';
217 $this->jsonValidatorMock->expects($this->any())
221 $this->itemMock->expects($this->any())
222 ->method(
'getProductId')
223 ->will($this->returnValue(1));
224 $this->comparedMock->expects($this->any())
225 ->method(
'getProductId')
226 ->will($this->returnValue(1));
228 $this->itemMock->expects($this->once())
229 ->method(
'getOptions')
235 $this->comparedMock->expects($this->once())
236 ->method(
'getOptions')
243 $this->assertTrue($this->helper->compare($this->itemMock, $this->comparedMock));
getOptionMock($code, $value)
The documentation for this class was generated from the following file: