Skip to content

Commit 0e43599

Browse files
author
Maxim Medinskiy
committed
MAGETWO-40041: Increase code coverage for South Team Modules
1 parent 43b0c45 commit 0e43599

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testRemoveOptionByCode($code, $option)
165165
$this->model->addOption($option);
166166
$this->assertEquals(1, count($this->model->getOptions()));
167167
$this->model->removeOption($code);
168-
$actualOptions = $this->model->getOptions();
168+
$actualOptions = $this->model->getOptions();
169169
$actualOption = array_pop($actualOptions);
170170
$this->assertTrue($actualOption->isDeleted());
171171
}
@@ -185,7 +185,7 @@ public function getOptionsDataProvider()
185185
->getMock();
186186
return [
187187
['first_key', ['code' => 'first_key', 'value' => 'first_data']],
188-
['second_key',$optionMock],
188+
['second_key', $optionMock],
189189
['third_key', new \Magento\Framework\Object(['code' => 'third_key', 'product' => $productMock])],
190190
];
191191
}
@@ -262,4 +262,63 @@ public function testCompareOptionsNegativeOptionsTwoHaveNotOption()
262262

263263
$this->assertFalse($result);
264264
}
265+
266+
public function testSetAndSaveItemOptions()
267+
{
268+
$this->assertEmpty($this->model->getOptions());
269+
$firstOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
270+
->disableOriginalConstructor()
271+
->setMethods(['getCode', 'isDeleted', 'delete', '__wakeup'])
272+
->getMock();
273+
$firstOptionMock->expects($this->any())
274+
->method('getCode')
275+
->willReturn('first_code');
276+
$firstOptionMock->expects($this->any())
277+
->method('isDeleted')
278+
->willReturn(true);
279+
$firstOptionMock->expects($this->once())
280+
->method('delete');
281+
282+
$secondOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
283+
->disableOriginalConstructor()
284+
->setMethods(['getCode', 'save', '__wakeup'])
285+
->getMock();
286+
$secondOptionMock->expects($this->any())
287+
->method('getCode')
288+
->willReturn('second_code');
289+
$secondOptionMock->expects($this->once())
290+
->method('save');
291+
292+
$this->model->setOptions([$firstOptionMock, $secondOptionMock]);
293+
$this->assertNull($this->model->isOptionsSaved());
294+
$this->model->saveItemOptions();
295+
$this->assertTrue($this->model->isOptionsSaved());
296+
}
297+
298+
public function testGetProductWithException()
299+
{
300+
$this->setExpectedException('Magento\Framework\Exception\LocalizedException', __('Cannot specify product.'));
301+
$this->model->getProduct();
302+
}
303+
304+
public function testGetProduct()
305+
{
306+
$productId = 1;
307+
$storeId = 0;
308+
$this->model->setData('product_id', $productId);
309+
$this->model->setData('store_id', $storeId);
310+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
311+
->disableOriginalConstructor()
312+
->getMock();
313+
$productMock->expects($this->any())
314+
->method('setFinalPrice')
315+
->with(null);
316+
$productMock->expects($this->any())
317+
->method('setCustomOprtions')
318+
->with([]);
319+
$this->productRepository->expects($this->once())
320+
->method('getById')
321+
->willReturn($productMock);
322+
$this->assertEquals($productMock, $this->model->getProduct());
323+
}
265324
}

0 commit comments

Comments
 (0)