コード例 #1
0
 /**
  * @covers \Magento\ConfigurableProduct\Model\Product\SaveHandler::execute
  */
 public function testExecute()
 {
     $attributeId = 90;
     $sku = 'config-1';
     $id = 25;
     $configurableProductLinks = [1, 2, 3];
     $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['getTypeId', 'getSku', 'getData', 'getExtensionAttributes'])->getMock();
     $product->expects(static::once())->method('getTypeId')->willReturn(ConfigurableModel::TYPE_CODE);
     $product->expects(static::exactly(2))->method('getSku')->willReturn($sku);
     $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)->setMethods(['getConfigurableProductOptions', 'getConfigurableProductLinks'])->disableOriginalConstructor()->getMockForAbstractClass();
     $product->expects(static::once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
     $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['getAttributeId', 'loadByProductAndAttribute'])->getMock();
     $this->processSaveOptions($attribute, $product, $attributeId, $sku, $id);
     $option = $this->getMockForAbstractClass(OptionInterface::class);
     $option->expects(static::once())->method('getId')->willReturn($id);
     $list = [$option];
     $this->optionRepository->expects(static::once())->method('getList')->with($sku)->willReturn($list);
     $this->optionRepository->expects(static::never())->method('deleteById');
     $configurableAttributes = [$attribute];
     $extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn($configurableAttributes);
     $extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($configurableProductLinks);
     $this->configurable->expects(static::once())->method('saveProducts')->with($product, $configurableProductLinks);
     $entity = $this->saveHandler->execute('Entity', $product);
     static::assertSame($product, $entity);
 }
コード例 #2
0
 /**
  * @return void
  */
 public function testAfterGetMatchingProductIdsWithConfigurableProduct()
 {
     $this->configurableProductsProviderMock->expects($this->once())->method('getIds')->willReturn(['conf1', 'conf2']);
     $this->configurableMock->expects($this->any())->method('getChildrenIds')->willReturnMap([['conf1', true, [0 => ['simple1']]], ['conf2', true, [0 => ['simple1', 'simple2']]]]);
     $this->assertEquals(['simple1' => [0 => true, 1 => true, 3 => true, 4 => false], 'simple2' => [0 => false, 1 => false, 3 => true, 4 => false]], $this->configurableProductHandler->afterGetMatchingProductIds($this->ruleMock, ['conf1' => [0 => true, 1 => true], 'conf2' => [0 => false, 1 => false, 3 => true, 4 => false]]));
 }