Ejemplo n.º 1
0
 /**
  * @dataProvider dataForGetStoreOptionValues
  */
 public function testGetStoreOptionValues($values)
 {
     $this->block->expects($this->once())->method('getData')->with('store_option_values_1')->willReturn($values);
     if ($values === null) {
         $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
         $option = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option', ['getId', 'getValue', 'getLabel'], [], '', false);
         $attrOptionCollectionMock = $objectManager->getCollectionMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option\\Collection', [$option, $option]);
         $this->attrOptionCollectionFactoryMock->expects($this->once())->method('create')->willReturn($attrOptionCollectionMock);
         $attribute = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute', ['getId'], [], '', false);
         $attribute->expects($this->once())->method('getId')->willReturn(23);
         $this->registryMock->expects($this->once())->method('registry')->with('entity_attribute')->willReturn($attribute);
         $attrOptionCollectionMock->expects($this->once())->method('setAttributeFilter')->with(23)->will($this->returnSelf());
         $attrOptionCollectionMock->expects($this->once())->method('setStoreFilter')->with(1, false)->will($this->returnSelf());
         $zendDbSelectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
         $attrOptionCollectionMock->expects($this->once())->method('getSelect')->willReturn($zendDbSelectMock);
         $zendDbSelectMock->expects($this->once())->method('joinLeft')->will($this->returnSelf());
         $option->expects($this->at(0))->method('getId')->willReturn(14);
         $option->expects($this->at(1))->method('getValue')->willReturn('Blue');
         $option->expects($this->at(2))->method('getId')->willReturn(14);
         $option->expects($this->at(3))->method('getLabel')->willReturn('#0000FF');
         $option->expects($this->at(4))->method('getId')->willReturn(15);
         $option->expects($this->at(5))->method('getValue')->willReturn('Black');
         $option->expects($this->at(6))->method('getId')->willReturn(15);
         $option->expects($this->at(7))->method('getLabel')->willReturn('#000000');
         $values = [14 => 'Blue', 'swatch' => [14 => '#0000FF', 15 => '#000000'], 15 => 'Black'];
     }
     $result = $this->block->getStoreOptionValues(1);
     $this->assertEquals($result, $values);
 }
Ejemplo n.º 2
0
 public function testGetItems()
 {
     $optionId = 1;
     $optionData = ['title' => 'test title'];
     $productSku = 'product_sku';
     $productMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductInterface');
     $productMock->expects($this->once())->method('getSku')->willReturn($productSku);
     $optionMock = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getOptionId', 'getData', 'getTitle', 'getDefaultTitle'], [], '', false);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $optionsCollMock = $objectManager->getCollectionMock('Magento\\Bundle\\Model\\Resource\\Option\\Collection', [$optionMock]);
     $this->typeMock->expects($this->once())->method('getOptionsCollection')->with($productMock)->willReturn($optionsCollMock);
     $optionMock->expects($this->exactly(2))->method('getOptionId')->willReturn($optionId);
     $optionMock->expects($this->once())->method('getData')->willReturn($optionData);
     $optionMock->expects($this->once())->method('getTitle')->willReturn(null);
     $optionMock->expects($this->once())->method('getDefaultTitle')->willReturn($optionData['title']);
     $linkMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\LinkInterface');
     $this->linkListMock->expects($this->once())->method('getItems')->with($productMock, $optionId)->willReturn([$linkMock]);
     $newOptionMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface');
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($newOptionMock, $optionData, '\\Magento\\Bundle\\Api\\Data\\OptionInterface')->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setOptionId')->with($optionId)->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setTitle')->with($optionData['title'])->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setSku')->with($productSku)->willReturnSelf();
     $newOptionMock->expects($this->once())->method('setProductLinks')->with([$linkMock])->willReturnSelf();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($newOptionMock);
     $this->assertEquals([$newOptionMock], $this->model->getItems($productMock));
 }
Ejemplo n.º 3
0
 public function testBuild()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $expectedData = ['100500' => ['some' => 'data']];
     $attributes = ['attributeOne' => ['code' => 'one'], 'attributeTwo' => ['code' => 'two']];
     $this->_linkMock->expects($this->once())->method('useCrossSellLinks');
     $this->_linkMock->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes));
     $productLinkMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Link', ['__wakeup', 'getLinkedProductId', 'toArray'], [], '', false);
     $productLinkMock->expects($this->once())->method('getLinkedProductId')->will($this->returnValue('100500'));
     $productLinkMock->expects($this->once())->method('toArray')->with(['one', 'two'])->will($this->returnValue(['some' => 'data']));
     $collectionMock = $helper->getCollectionMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Link\\Collection', [$productLinkMock]);
     $this->_productMock->expects($this->once())->method('getCrossSellLinkCollection')->will($this->returnValue($collectionMock));
     $this->_duplicateMock->expects($this->once())->method('setCrossSellLinkData')->with($expectedData);
     $this->_model->build($this->_productMock, $this->_duplicateMock);
 }
Ejemplo n.º 4
0
 public function testBuild()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $expectedData = ['100500' => ['some' => 'data']];
     $this->_productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE));
     $attributes = ['attributeOne' => ['code' => 'one'], 'attributeTwo' => ['code' => 'two']];
     $this->_linkMock->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes));
     $productLinkMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link', ['__wakeup', 'getLinkedProductId', 'toArray'], [], '', false);
     $this->_linkMock->expects($this->atLeastOnce())->method('setLinkTypeId')->with(\Magento\GroupedProduct\Model\Resource\Product\Link::LINK_TYPE_GROUPED);
     $productLinkMock->expects($this->once())->method('getLinkedProductId')->will($this->returnValue('100500'));
     $productLinkMock->expects($this->once())->method('toArray')->with(['one', 'two'])->will($this->returnValue(['some' => 'data']));
     $collectionMock = $helper->getCollectionMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link\\Collection', [$productLinkMock]);
     $collectionMock->expects($this->once())->method('setProduct')->with($this->_productMock);
     $collectionMock->expects($this->once())->method('addLinkTypeIdFilter');
     $collectionMock->expects($this->once())->method('addProductIdFilter');
     $collectionMock->expects($this->once())->method('joinAttributes');
     $this->_linkMock->expects($this->once())->method('getLinkCollection')->will($this->returnValue($collectionMock));
     $this->_duplicateMock->expects($this->once())->method('setGroupedLinkData')->with($expectedData);
     $this->_model->build($this->_productMock, $this->_duplicateMock);
 }