25 private $configurationPool;
30 private $itemResolver;
34 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35 $this->imageHelper = $this->getMockBuilder(\
Magento\Catalog\Helper\Image::class)
36 ->disableOriginalConstructor()
38 $this->configurationPool = $this->getMockBuilder(\
Magento\Catalog\Helper\Product\ConfigurationPool::class)
40 ->disableOriginalConstructor()
42 $checkoutHelper = $this->getMockBuilder(\
Magento\Checkout\Helper\Data::class)
43 ->setMethods([
'formatPrice'])->disableOriginalConstructor()->getMock();
44 $checkoutHelper->expects($this->any())->method(
'formatPrice')->willReturn(5);
45 $this->itemResolver = $this->createMock(ItemResolverInterface::class);
47 \
Magento\Checkout\CustomerData\DefaultItem::class,
49 'imageHelper' => $this->imageHelper,
50 'configurationPool' => $this->configurationPool,
51 'checkoutHelper' => $checkoutHelper,
52 'itemResolver' => $this->itemResolver,
57 public function testGetItemData()
59 $urlModel = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Url::class)
60 ->disableOriginalConstructor()
63 ->setMethods([
'getUrlModel',
'isVisibleInSiteVisibility',
'getSku'])
64 ->disableOriginalConstructor()
66 $product->expects($this->any())->method(
'getUrlModel')->willReturn($urlModel);
67 $product->expects($this->any())->method(
'isVisibleInSiteVisibility')->willReturn(
true);
68 $product->expects($this->any())->method(
'getSku')->willReturn(
'simple');
70 $item = $this->getMockBuilder(\
Magento\Quote\Model\Quote\Item::class)
71 ->setMethods([
'getProductType',
'getProduct',
'getCalculationPrice'])
72 ->disableOriginalConstructor()
74 $item->expects($this->any())->method(
'getProduct')->willReturn(
$product);
75 $item->expects($this->any())->method(
'getProductType')->willReturn(
'simple');
76 $item->expects($this->any())->method(
'getCalculationPrice')->willReturn(5);
78 $this->imageHelper->expects($this->any())->method(
'init')->with(
$product)->willReturnSelf();
79 $this->imageHelper->expects($this->any())->method(
'getUrl')->willReturn(
'url');
80 $this->imageHelper->expects($this->any())->method(
'getLabel')->willReturn(
'label');
81 $this->imageHelper->expects($this->any())->method(
'getWidth')->willReturn(100);
82 $this->imageHelper->expects($this->any())->method(
'getHeight')->willReturn(100);
83 $this->configurationPool->expects($this->any())->method(
'getByProductType')->willReturn(
$product);
85 $this->itemResolver->expects($this->any())
86 ->method(
'getFinalProduct')
88 ->will($this->returnValue(
$product));
90 $itemData = $this->model->getItemData(
$item);
91 $this->assertArrayHasKey(
'options', $itemData);
92 $this->assertArrayHasKey(
'qty', $itemData);
93 $this->assertArrayHasKey(
'item_id', $itemData);
94 $this->assertArrayHasKey(
'configure_url', $itemData);
95 $this->assertArrayHasKey(
'is_visible_in_site_visibility', $itemData);
96 $this->assertArrayHasKey(
'product_type', $itemData);
97 $this->assertArrayHasKey(
'product_name', $itemData);
98 $this->assertArrayHasKey(
'product_sku', $itemData);
99 $this->assertArrayHasKey(
'product_url', $itemData);
100 $this->assertArrayHasKey(
'product_has_url', $itemData);
101 $this->assertArrayHasKey(
'product_price', $itemData);
102 $this->assertArrayHasKey(
'product_price_value', $itemData);
103 $this->assertArrayHasKey(
'product_image', $itemData);
104 $this->assertArrayHasKey(
'canApplyMsrp', $itemData);