Example #1
0
 public function testCreateProductDataFromModel()
 {
     $productModelMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $attrCodes = ['sku', 'price', 'status', 'updatedAt', 'entity_id'];
     $this->productBuilder->expects($this->once())->method('getCustomAttributesCodes')->will($this->returnValue($attrCodes));
     $attributes = [ProductDataObject::SKU => ProductDataObject::SKU . 'value', ProductDataObject::PRICE => ProductDataObject::PRICE . 'value', ProductDataObject::STATUS => ProductDataObject::STATUS . 'dataValue'];
     $this->productBuilder->expects($this->once())->method('populateWithArray')->with($attributes);
     $this->productBuilder->expects($this->once())->method('getData')->will($this->returnValue($attributes));
     $this->productBuilder->expects($this->once())->method('create')->will($this->returnValue(new ProductDataObject($this->productBuilder)));
     $dataUsingMethodCallback = $this->returnCallback(function ($attrCode) {
         if (in_array($attrCode, ['sku', 'price', 'entity_id'])) {
             return $attrCode . 'value';
         }
         return null;
     });
     $productModelMock->expects($this->exactly(count($attrCodes)))->method('getDataUsingMethod')->will($dataUsingMethodCallback);
     $dataCallback = $this->returnCallback(function ($attrCode) {
         if ($attrCode == 'status') {
             return $attrCode . 'dataValue';
         }
         return null;
     });
     $productModelMock->expects($this->exactly(2))->method('getData')->will($dataCallback);
     $this->converter = new Converter($this->productBuilder);
     $productData = $this->converter->createProductDataFromModel($productModelMock);
     $this->assertEquals(ProductDataObject::SKU . 'value', $productData->getSku());
     $this->assertEquals(ProductDataObject::PRICE . 'value', $productData->getPrice());
     $this->assertEquals(ProductDataObject::STATUS . 'dataValue', $productData->getStatus());
     $this->assertEquals(null, $productData->getUpdatedAt());
 }
 public function testLoadBundleProduct()
 {
     $productId = 'test_id';
     $productSku = 'test_sku';
     $this->productRepository->expects($this->once())->method('get')->with($productId)->will($this->returnValue($this->product));
     $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->product->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     $optionCustomAttributeValue = ['a', 'b'];
     $this->optionReadService->expects($this->once())->method('getList')->with($productSku)->will($this->returnValue($optionCustomAttributeValue));
     $this->productBuilder->expects($this->at(0))->method('setCustomAttribute')->with('bundle_product_options', $optionCustomAttributeValue);
     $this->model->load($productId, $this->productBuilder);
 }
Example #3
0
 /**
  * @param array $configurableAttributeData
  * @dataProvider productVariationDataProvider
  */
 public function testGenerateVariation($configurableAttributeData)
 {
     $attributeCode = 'code';
     $attribute = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock();
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->attributeReadService->expects($this->once())->method('info')->with($configurableAttributeData['attribute_id'])->will($this->returnValue($attribute));
     $options = null;
     $this->variationMatrix->expects($this->any())->method('getVariations')->with([$configurableAttributeData['attribute_id'] => ["attribute_id" => $configurableAttributeData['attribute_id'], "values" => $configurableAttributeData['values'], "options" => $options, "attribute_code" => $attributeCode]])->will($this->returnValue([[$configurableAttributeData['attribute_id'] => ['value' => '14', 'label' => 'dd', 'price' => ['index' => 14, 'price' => 10]]]]));
     $product = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getPrice')->will($this->returnValue(100));
     $configurableAttribute = $this->getMockBuilder('Magento\\ConfigurableProduct\\Service\\V1\\Data\\Option')->disableOriginalConstructor()->getMock();
     $configurableAttribute->expects($this->any())->method('__toArray')->will($this->returnValue($configurableAttributeData));
     $configurableAttribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($configurableAttributeData['attribute_id']));
     $this->productBuilder->expects($this->any())->method('populute')->with($product);
     $this->productBuilder->expects($this->once())->method('setCustomAttribute')->with($attributeCode, 14);
     $this->productBuilder->expects($this->once())->method('setPrice')->with(110);
     $this->productBuilder->expects($this->once())->method('create')->will($this->returnValue($product));
     $result = $this->object->generateVariation($product, [$configurableAttribute]);
     $this->assertCount(1, $result);
     $this->assertEquals([$product], $result);
 }