37 private $serializerMock;
41 $this->configPoolMock = $this->createMock(\
Magento\Catalog\Helper\
Product\ConfigurationPool::class);
42 $this->eventManagerMock = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
43 $this->dataObjectHelperMock = $this->createMock(\
Magento\Framework\Api\DataObjectHelper::class);
44 $this->totalsFactoryMock = $this->createPartialMock(
45 \
Magento\
Quote\Api\Data\TotalsItemInterfaceFactory::class,
49 $this->serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)->getMock();
51 $this->model = new \Magento\Quote\Model\Cart\Totals\ItemConverter(
52 $this->configPoolMock,
53 $this->eventManagerMock,
54 $this->totalsFactoryMock,
55 $this->dataObjectHelperMock,
62 $productType =
'simple';
65 $itemMock->expects($this->once())->method(
'toArray')->will($this->returnValue([
'options' => []]));
66 $itemMock->expects($this->any())->method(
'getProductType')->will($this->returnValue($productType));
68 $simpleConfigMock = $this->createMock(\
Magento\Catalog\Helper\
Product\Configuration::class);
69 $defaultConfigMock = $this->createMock(\
Magento\Catalog\Helper\
Product\Configuration::class);
71 $this->configPoolMock->expects($this->any())->method(
'getByProductType')
72 ->will($this->returnValueMap([[
'simple', $simpleConfigMock], [
'default', $defaultConfigMock]]));
74 $options = [
'1' => [
'label' =>
'option1'],
'2' => [
'label' =>
'option2']];
75 $simpleConfigMock->expects($this->once())->method(
'getOptions')->with($itemMock)
76 ->will($this->returnValue(
$options));
78 $option = [
'data' =>
'optionsData',
'label' =>
''];
79 $defaultConfigMock->expects($this->any())->method(
'getFormattedOptionValue')->will($this->returnValue(
$option));
81 $this->eventManagerMock->expects($this->once())->method(
'dispatch')
82 ->with(
'items_additional_data', [
'item' => $itemMock]);
84 $this->totalsFactoryMock->expects($this->once())->method(
'create');
87 'options' =>
'{"1":{"data":"optionsData","label":"option1"},"2":{"data":"optionsData","label":"option2"}}' 89 $this->dataObjectHelperMock->expects($this->once())->method(
'populateWithArray')
90 ->with(
null, $expectedData, \
Magento\
Quote\Api\Data\TotalsItemInterface::class);
94 'data' =>
'optionsData',
98 'data' =>
'optionsData',
102 $this->serializerMock->expects($this->once())->method(
'serialize')
103 ->will($this->returnValue(json_encode(
$optionData)));
105 $this->model->modelToDataObject($itemMock);