コード例 #1
0
ファイル: ConfigurableTest.php プロジェクト: nja78/magento2
 /**
  * @depends testGetConfigurableAttributesAsArray
  */
 public function testGetProductByAttributes()
 {
     $attributes = $this->_model->getConfigurableAttributesAsArray($this->_product);
     $attribute = reset($attributes);
     $optionValueId = $attribute['values'][0]['value_index'];
     $product = $this->_model->getProductByAttributes([$attribute['attribute_id'] => $optionValueId], $this->_product);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Product', $product);
     $this->assertEquals("simple_10", $product->getSku());
 }
コード例 #2
0
ファイル: ConfigurableTest.php プロジェクト: nja78/magento2
 public function testGetProductByAttributesReturnFirstItem()
 {
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId'])->disableOriginalConstructor()->getMock();
     $firstItemMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getId'])->disableOriginalConstructor()->getMock();
     $productCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Product\\Collection')->setMethods(['setFlag', 'setProductFilter', 'addStoreFilter', 'addAttributeToSelect', 'addAttributeToFilter', 'getFirstItem'])->disableOriginalConstructor()->getMock();
     $this->_productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($productCollection));
     $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf());
     $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock);
     $firstItemMock->expects($this->any())->method('getId')->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(3)->willReturn($firstItemMock);
     $this->assertEquals($firstItemMock, $this->_model->getProductByAttributes($this->attributeData, $productMock));
 }