/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetConfigurableOptions()
 {
     $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     /** @var Configurable|\PHPUnit_Framework_MockObject_MockObject $configurable */
     $configurable = $this->getMockBuilder(Configurable::class)->setMethods(['getTable', 'getConnection'])->setConstructorArgs([$context, $this->relation])->getMock();
     $reflection = new \ReflectionClass(Configurable::class);
     $reflectionProperty = $reflection->getProperty('metadataPool');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($configurable, $this->metadataPoolMock);
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */
     $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['__sleep', '__wakeup', 'getData'])->disableOriginalConstructor()->getMock();
     $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn('link');
     $product->expects($this->once())->method('getData')->with('link')->willReturn('getId value');
     $configurable->expects($this->exactly(7))->method('getTable')->will($this->returnValueMap([['catalog_product_super_attribute', 'catalog_product_super_attribute value'], ['catalog_product_entity', 'catalog_product_entity value'], ['catalog_product_super_link', 'catalog_product_super_link value'], ['eav_attribute', 'eav_attribute value'], ['catalog_product_entity', 'catalog_product_entity value'], ['eav_attribute_option_value', 'eav_attribute_option_value value'], ['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value']]));
     $select = $this->getMock(\Magento\Framework\DB\Select::class, ['from', 'joinInner', 'joinLeft', 'where'], [], '', false);
     $select->expects($this->once())->method('from')->with(['super_attribute' => 'catalog_product_super_attribute value'], ['sku' => 'entity.sku', 'product_id' => 'product_entity.entity_id', 'attribute_code' => 'attribute.attribute_code', 'option_title' => 'option_value.value', 'super_attribute_label' => 'attribute_label.value'])->will($this->returnSelf());
     $superAttribute = $this->getMock(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute::class, ['getBackendTable', 'getAttributeId'], [], '', false);
     $superAttribute->expects($this->once())->method('getBackendTable')->willReturn('getBackendTable value');
     $superAttribute->expects($this->once())->method('getAttributeId')->willReturn('getAttributeId value');
     $attributes = [$superAttribute];
     $select->expects($this->exactly(5))->method('joinInner')->will($this->returnSelf())->withConsecutive([['product_entity' => 'catalog_product_entity value'], 'product_entity.link = super_attribute.product_id', []], [['product_link' => 'catalog_product_super_link value'], 'product_link.parent_id = super_attribute.product_id', []], [['attribute' => 'eav_attribute value'], 'attribute.attribute_id = super_attribute.attribute_id', []], [['entity' => 'catalog_product_entity value'], 'entity.entity_id = product_link.product_id', []], [['entity_value' => 'getBackendTable value'], implode(' AND ', ['entity_value.attribute_id = super_attribute.attribute_id', 'entity_value.store_id = 0', 'entity_value.link = entity.link']), []]);
     $select->expects($this->exactly(2))->method('joinLeft')->will($this->returnSelf())->withConsecutive([['option_value' => 'eav_attribute_option_value value'], implode(' AND ', ['option_value.option_id = entity_value.value', 'option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID]), []], [['attribute_label' => 'catalog_product_super_attribute_label value'], implode(' AND ', ['super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id', 'attribute_label.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID]), []]);
     $select->expects($this->once())->method('where')->will($this->returnSelf())->with('super_attribute.product_id = ?', 'getId value');
     $readerAdapter = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->setMethods(['select', 'fetchAll'])->disableOriginalConstructor()->getMockForAbstractClass();
     $readerAdapter->expects($this->once())->method('select')->willReturn($select);
     $readerAdapter->expects($this->once())->method('fetchAll')->with($select)->willReturn('fetchAll value');
     $configurable->expects($this->exactly(2))->method('getConnection')->willReturn($readerAdapter);
     $expectedAttributesOptionsData = ['getAttributeId value' => 'fetchAll value'];
     $actualAttributesOptionsData = $configurable->getConfigurableOptions($product, $attributes);
     $this->assertEquals($expectedAttributesOptionsData, $actualAttributesOptionsData);
 }
 public function testSaveCreate()
 {
     $this->hydrator->expects($this->once())->method('extract')->with($this->abstractEntity)->willReturn(['test_field_1' => 'test_value_1', 'test_filed_2' => 'test_field_2']);
     $this->metadata->expects($this->never())->method('checkIsEntityExists');
     $this->orchestratorPool->expects($this->once())->method('getWriteOperation')->with('Test\\Entity\\Type', 'create')->willReturn($this->writeOperation);
     $this->writeOperation->expects($this->once())->method('execute')->with('Test\\Entity\\Type', $this->abstractEntity)->willReturn($this->abstractEntity);
     $result = $this->subject->save('Test\\Entity\\Type', $this->abstractEntity);
     $this->assertEquals($this->abstractEntity, $result);
 }
예제 #3
0
 /**
  * @param string $entityType
  * @param array $entity
  * @param string $identifier
  * @param string $linkField
  * @dataProvider executeParameters
  */
 public function testExecute($entityType, $entity, $identifier, $linkField)
 {
     $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($entityType)->willReturn($this->metadataMock);
     $entityWithMainRead = array_merge($entity, ['main_read' => 'some info']);
     $this->readMainMock->expects($this->once())->method('execute')->with($entityType, $entity, $identifier)->willReturn($entityWithMainRead);
     $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $entityWithExtensionAndRelation = $entityWithMainRead;
     if (isset($entity[$linkField])) {
         $entityWithExtension = array_merge($entityWithMainRead, ['ext' => 'extParameter']);
         $this->readExtensionMock->expects($this->once())->method('execute')->with($entityType, $entityWithMainRead)->willReturn($entityWithExtension);
         $entityWithExtensionAndRelation = array_merge($entityWithExtension, ['relation' => 'some_relation']);
         $this->readRelationMock->expects($this->once())->method('execute')->with($entityType, $entityWithExtension)->willReturn($entityWithExtensionAndRelation);
     }
     $this->assertEquals($entityWithExtensionAndRelation, $this->read->execute($entityType, $entity, $identifier));
 }
 /**
  * Test `Save` method
  */
 public function testSave()
 {
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['getIsDuplicate', 'dataHasChangedFor', 'getConfigurableAttributesData', 'getStoreId', 'getId', 'getData', 'hasData', 'getAssociatedProductIds', '__wakeup', '__sleep'])->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue('false'));
     $product->expects($this->any())->method('getConfigurableAttributesData')->will($this->returnValue($this->attributeData));
     $product->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true));
     $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2]));
     $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids')->will($this->returnValue(true));
     $extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)->setMethods(['getConfigurableProductOptions', 'getConfigurableProductLinks'])->getMockForAbstractClass();
     $this->entityMetadata->expects(static::once())->method('getLinkField')->willReturn('link');
     $dataMap = [['extension_attributes', null, $extensionAttributes], ['_cache_instance_used_product_attribute_ids', null, 1], ['link', null, 1]];
     $product->expects($this->any())->method('getData')->willReturnMap($dataMap);
     $attribute = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['addData', 'setStoreId', 'setProductId', 'save', '__wakeup', '__sleep'])->getMock();
     $expectedAttributeData = $this->attributeData[1];
     unset($expectedAttributeData['id']);
     $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->will($this->returnSelf());
     $attribute->expects($this->once())->method('setStoreId')->with(1)->will($this->returnSelf());
     $attribute->expects($this->once())->method('setProductId')->with(1)->will($this->returnSelf());
     $attribute->expects($this->once())->method('save')->will($this->returnSelf());
     $this->_configurableAttributeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($attribute));
     $attributeCollection = $this->getMockBuilder('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Attribute\\Collection')->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor()->getMock();
     $this->_attributeCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($attributeCollection));
     $this->_typeConfigurableFactory->expects($this->once())->method('create')->will($this->returnSelf());
     $this->_typeConfigurableFactory->expects($this->once())->method('saveProducts')->withAnyParameters()->will($this->returnSelf());
     $this->_model->save($product);
 }
 public function testRemoveChild()
 {
     $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product));
     $bundle = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Bundle', [], [], '', false);
     $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle));
     $productSku = 'productSku';
     $optionId = 1;
     $productId = 1;
     $childSku = 'childSku';
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->getRemoveOptions();
     $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku));
     $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId));
     $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55));
     $selection->expects($this->any())->method('getProductId')->willReturn($productId);
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection]));
     $this->metadataMock->expects($this->any())->method('getLinkField')->willReturn($this->linkField);
     $this->product->expects($this->any())->method('getData')->with($this->linkField)->willReturn(3);
     $bundle->expects($this->once())->method('dropAllUnneededSelections')->with(3, []);
     $bundle->expects($this->once())->method('removeProductRelations')->with(3, [$productId]);
     //Params come in lowercase to method
     $this->assertTrue($this->model->removeChild($productSku, $optionId, $childSku));
 }