当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductFactory::expects方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\ProductFactory::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductFactory::expects方法的具体用法?PHP ProductFactory::expects怎么用?PHP ProductFactory::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\ProductFactory的用法示例。


在下文中一共展示了ProductFactory::expects方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false);
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getSku', 'getTypeId', 'getStoreId', '__sleep', '__wakeup', 'getAttributes', 'setAttributeSetId'])->getMock();
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
     $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
     $this->product->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
     $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product));
     $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);
     $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock();
     $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward);
     $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->layout);
     $this->resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->initializationHelper = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false);
     $this->productFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->productFactory->expects($this->any())->method('create')->willReturn($this->product);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJsonFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\JsonFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson);
     $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory];
     $this->action = (new ObjectManagerHelper($this))->getObject('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Validate', ['context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, 'initializationHelper' => $this->initializationHelper, 'resultJsonFactory' => $this->resultJsonFactory, 'productFactory' => $this->productFactory]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:27,代码来源:ValidateTest.php

示例2: setUp

 protected function setUp()
 {
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->visibility = $this->getMock('Magento\\Catalog\\Model\\Product\\Visibility', [], [], '', false);
     $this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', [], [], '', false);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->newProducts = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Rss\\Product\\NewProducts', ['productFactory' => $this->productFactory, 'visibility' => $this->visibility, 'localeDate' => $this->timezone]);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:NewProductsTest.php

示例3: testExecuteNullProduct

 public function testExecuteNullProduct()
 {
     $this->productMock->expects($this->once())->method('load')->with(59)->willReturn($this->productMock);
     $this->productModelFactoryMock->expects($this->once())->method('create')->willReturn($this->productMock);
     $this->swatchHelperMock->expects($this->once())->method('getAttributesFromConfigurable')->with($this->productMock)->willReturn([$this->attributeMock]);
     $this->swatchHelperMock->expects($this->once())->method('loadVariationByFallback')->with($this->productMock, ['size' => 454])->willReturn(null);
     $this->swatchHelperMock->expects($this->once())->method('getProductMediaGallery')->with($this->productMock)->willReturn($this->mediaGallery);
     $this->jsonMock->expects($this->once())->method('setData')->with($this->mediaGallery)->will($this->returnSelf());
     $result = $this->controller->execute();
     $this->assertInstanceOf('\\Magento\\Framework\\Controller\\Result\\Json', $result);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:MediaTest.php

示例4: setUp

 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->mathDivision = $this->getMock('\\Magento\\Framework\\Math\\Division', ['getExactDivision'], [], '', false);
     $this->localeFormat = $this->getMockForAbstractClass('\\Magento\\Framework\\Locale\\FormatInterface', ['getNumber']);
     $this->localeFormat->expects($this->any())->method('getNumber')->willReturn($this->qty);
     $this->object = $this->objectManagerHelper->getObject('Magento\\Framework\\DataObject');
     $this->objectFactory = $this->getMock('\\Magento\\Framework\\DataObject\\Factory', ['create'], [], '', false);
     $this->objectFactory->expects($this->any())->method('create')->willReturn($this->object);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['load', 'isComposite', '__wakeup', 'isSaleable'], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->productFactory->expects($this->any())->method('create')->willReturn($this->product);
     $this->stockStateProvider = $this->objectManagerHelper->getObject('Magento\\CatalogInventory\\Model\\StockStateProvider', ['mathDivision' => $this->mathDivision, 'localeFormat' => $this->localeFormat, 'objectFactory' => $this->objectFactory, 'productFactory' => $this->productFactory, 'qtyCheckApplicable' => $this->qtyCheckApplicable]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:StockStateProviderTest.php

示例5: testAfterImportData

 /**
  * Test for afterImportData()
  * Covers afterImportData() + protected methods used inside except related to generateUrls() ones.
  * generateUrls will be covered separately.
  *
  * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::afterImportData
  * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::_populateForUrlGeneration
  * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::isGlobalScope
  * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::populateGlobalProduct
  * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::addProductToImport
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterImportData()
 {
     $newSku = ['entity_id' => 'value'];
     $websiteId = 'websiteId value';
     $productsCount = count($this->products);
     $websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false);
     $storeIds = [1, Store::DEFAULT_STORE_ID];
     $websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
     $this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock);
     $this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn($newSku);
     $this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]]);
     $getProductWebsitesCallsCount = $productsCount * 2;
     $this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturn([$newSku['entity_id'] => $websiteId]);
     $map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]];
     $this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map));
     $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false);
     $product->expects($this->exactly($productsCount))->method('setId')->with($newSku['entity_id']);
     $product->expects($this->any())->method('getId')->willReturn($newSku['entity_id']);
     $product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku']));
     $product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]));
     $product->expects($this->once())->method('setStoreId')->with($this->products[1][ImportProduct::COL_STORE]);
     $this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product);
     $this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku['entity_id']]);
     $productUrls = ['url 1', 'url 2'];
     $importMock = $this->getImportMock(['generateUrls', 'canonicalUrlRewriteGenerate', 'categoriesUrlRewriteGenerate', 'currentUrlRewritesRegenerate', 'cleanOverriddenUrlKey']);
     $importMock->expects($this->once())->method('generateUrls')->willReturn($productUrls);
     $this->urlPersist->expects($this->once())->method('replace')->with($productUrls);
     $importMock->afterImportData($this->observer);
 }
开发者ID:nja78,项目名称:magento2,代码行数:42,代码来源:ImportTest.php

示例6: testGenerateSimpleProducts

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerateSimpleProducts()
 {
     $productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
     $stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
     $parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
     $newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
     $productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getSetAttributes'])->disableOriginalConstructor()->getMock();
     $editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
     $frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
     $parentProductMock->expects($this->once())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
     $this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
     $newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
     $productTypeMock->expects($this->once())->method('getSetAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
     $editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
     $editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
     $editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
     $frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
     $editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
     $parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
     $parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
     $newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
     $this->stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
     $newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
     $parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
     $newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
     $newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
     $this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:36,代码来源:VariationHandlerTest.php

示例7: testToHtml

 /**
  * Test for method _toHtml
  *
  * @return void
  */
 public function testToHtml()
 {
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getProductUrl', 'getDescription', 'getAllowedPriceInRss', 'getName', '__wakeup', 'getResourceCollection'], [], '', false);
     $productCollectionMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['addPriceDataFieldFilter', 'addPriceData', 'addAttributeToSelect', 'addAttributeToSort', 'getSelect'], [], '', false);
     $rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false);
     $productUrl = '<a href="http://product.url">Product Url</a>';
     $imgThumbSrc = 'http://source-for-thumbnail';
     $productTitle = 'Product title';
     $basePriceFormatted = '<span class="price">$10.00</span>';
     $finalPriceFormatted = '<span class="price">$20.00</span>';
     $productDescription = '<table><tr>' . '<td><a href="' . $productUrl . '"><img src="' . $imgThumbSrc . '" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;"><p>Price: ' . $basePriceFormatted . ' Special Price: ' . $finalPriceFormatted . '</p></td></tr></table>';
     $expectedData = ['title' => $productTitle, 'link' => $productUrl, 'description' => $productDescription];
     $expectedResult = new \Magento\Framework\Object(['rss_feed' => '<xml>Feed of the rss</xml>']);
     $this->addMocks();
     $this->productFactoryMock->expects($this->once())->method('create')->will($this->returnValue($productMock));
     $productMock->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollectionMock));
     $productCollectionMock->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf());
     $productCollectionMock->expects($this->once())->method('addPriceData')->will($this->returnSelf());
     $productCollectionMock->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
     $productCollectionMock->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf());
     $this->rssFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rssObjMock));
     $productMock->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue($productUrl));
     $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc));
     $productMock->expects($this->any())->method('getAllowedPriceInRss')->will($this->returnValue(true));
     $productMock->expects($this->once())->method('getName')->will($this->returnValue($productTitle));
     $this->priceCurrencyMock->expects($this->exactly(2))->method('convertAndFormat')->will($this->returnValueMap([[10, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $basePriceFormatted], [20, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $finalPriceFormatted]]));
     $rssObjMock->expects($this->once())->method('_addEntry')->with($expectedData)->will($this->returnSelf());
     $rssObjMock->expects($this->once())->method('createRssXml')->will($this->returnValue($expectedResult));
     $this->assertEquals($expectedResult, $this->block->toHtml());
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:35,代码来源:SpecialTest.php

示例8: setUp

 protected function setUp()
 {
     $this->stockItemMock = $this->getMockBuilder('\\Magento\\CatalogInventory\\Model\\Stock\\Item')->disableOriginalConstructor()->setMethods(['getItemId', 'getProductId', 'setIsInStock', 'setStockStatusChangedAutomaticallyFlag', 'getStockStatusChangedAutomaticallyFlag', 'getManageStock', 'setLowStockDate', 'setStockStatusChangedAuto', 'hasStockStatusChangedAutomaticallyFlag', 'setQty', 'getWebsiteId', 'setWebsiteId', 'getStockId', 'setStockId'])->getMock();
     $this->stockConfigurationMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\StockConfigurationInterface')->disableOriginalConstructor()->getMock();
     $this->stockStateProviderMock = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Spi\\StockStateProviderInterface')->disableOriginalConstructor()->getMock();
     $this->stockItemResourceMock = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Resource\\Stock\\Item')->disableOriginalConstructor()->getMock();
     $this->stockItemFactoryMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterfaceFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->stockItemCollectionMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemCollectionInterfaceFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->productFactoryMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductFactory')->disableOriginalConstructor()->setMethods(['load', 'create'])->getMock();
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getTypeId', '__wakeup'])->getMock();
     $this->productFactoryMock->expects($this->any())->method('create')->willReturn($this->productMock);
     $this->queryBuilderFactoryMock = $this->getMockBuilder('Magento\\Framework\\DB\\QueryBuilderFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->mapperMock = $this->getMockBuilder('Magento\\Framework\\DB\\MapperFactory')->disableOriginalConstructor()->getMock();
     $this->localeDateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock();
     $this->indexProcessorMock = $this->getMock('Magento\\CatalogInventory\\Model\\Indexer\\Stock\\Processor', ['reindexRow'], [], '', false);
     $this->model = new StockItemRepository($this->stockConfigurationMock, $this->stockStateProviderMock, $this->stockItemResourceMock, $this->stockItemFactoryMock, $this->stockItemCollectionMock, $this->productFactoryMock, $this->queryBuilderFactoryMock, $this->mapperMock, $this->localeDateMock, $this->indexProcessorMock);
 }
开发者ID:nja78,项目名称:magento2,代码行数:17,代码来源:StockItemRepositoryTest.php

示例9: setUp

 /**
  * Set up test
  *
  * @return void
  */
 protected function setUp()
 {
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\ResourceModel\\Rule\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
     $this->backend = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\EntityManager\\MetadataPool', [], [], '', false);
     $metadata = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->db = $this->getMock('Zend_Db_Statement_Interface', [], [], '', false);
     $this->website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', [], [], '', false);
     $this->rules = $this->getMock('Magento\\CatalogRule\\Model\\Rule', [], [], '', false);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false);
     $this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->dateFormat = $this->getMock('Magento\\Framework\\Stdlib\\DateTime', [], [], '', false);
     $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTime', [], [], '', false);
     $this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute'], [], '', false);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connection->expects($this->any())->method('query')->will($this->returnValue($this->db));
     $this->select->expects($this->any())->method('distinct')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('order')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$this->website]));
     $this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->rules->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->rules->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('getCustomerGroupIds')->will($this->returnValue([1]));
     $this->ruleCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
     $this->ruleCollectionFactory->expects($this->any())->method('addFieldToFilter')->will($this->returnValue([$this->rules]));
     $this->product->expects($this->any())->method('load')->will($this->returnSelf());
     $this->product->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->product->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('validate')->with($this->product)->willReturn(true);
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder($this->ruleCollectionFactory, $this->priceCurrency, $this->resource, $this->storeManager, $this->logger, $this->eavConfig, $this->dateFormat, $this->dateTime, $this->productFactory);
     $this->setProperties($this->indexBuilder, ['metadataPool' => $this->metadataPool]);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:52,代码来源:IndexBuilderTest.php

示例10: testAroundSaveWithLinksWithDuplicateAttributes

 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Products "5" and "4" have the same set of attribute values.
  */
 public function testAroundSaveWithLinksWithDuplicateAttributes()
 {
     $links = [4, 5];
     $attributeCode = 'color';
     $attributeId = 23;
     $this->option->expects(static::once())->method('getAttributeId')->willReturn($attributeId);
     $this->product->expects(static::once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE);
     $this->result->expects(static::once())->method('getExtensionAttributes')->willReturn($this->extensionAttributes);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductOptions')->willReturn([$this->option]);
     $this->extensionAttributes->expects(static::once())->method('getConfigurableProductLinks')->willReturn($links);
     $this->productAttributeRepository->expects(static::once())->method('get')->willReturn($this->eavAttribute);
     $this->eavAttribute->expects(static::once())->method('getAttributeCode')->willReturn($attributeCode);
     $product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->setMethods(['load', 'getData', '__wakeup'])->getMock();
     $this->productFactory->expects(static::exactly(2))->method('create')->willReturn($product);
     $product->expects(static::exactly(2))->method('load')->willReturnSelf();
     $product->expects(static::exactly(4))->method('getData')->with($attributeCode)->willReturn($attributeId);
     $this->plugin->aroundSave($this->productRepository, $this->closure, $this->product);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:22,代码来源:AroundProductRepositorySaveTest.php

示例11: testAfterImportData

 /**
  * Test for afterImportData()
  * Covers afterImportData() + protected methods used inside
  *
  * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::afterImportData
  * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::_populateForUrlGeneration
  * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::isGlobalScope
  * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::populateGlobalProduct
  * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::addProductToImport
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterImportData()
 {
     $newSku = [['entity_id' => 'value'], ['entity_id' => 'value3']];
     $websiteId = 'websiteId value';
     $productsCount = count($this->products);
     $websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false);
     $storeIds = [1, Store::DEFAULT_STORE_ID];
     $websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
     $this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock);
     $this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->will($this->onConsecutiveCalls($newSku[0], $newSku[1]));
     $this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn([]);
     $getProductWebsitesCallsCount = $productsCount * 2;
     $this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturnOnConsecutiveCalls([$newSku[0]['entity_id'] => $websiteId], [$newSku[0]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId]);
     $map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]];
     $this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map));
     $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false);
     $product->expects($this->exactly($productsCount))->method('setId')->withConsecutive([$newSku[0]['entity_id']], [$newSku[1]['entity_id']]);
     $product->expects($this->any())->method('getId')->willReturnOnConsecutiveCalls($newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id']);
     $product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku']));
     $product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]));
     $product->expects($this->exactly($productsCount))->method('setStoreId')->withConsecutive([$this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE]]);
     $this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product);
     $this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[0]['entity_id']], ['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[1]['entity_id']]);
     $this->connection->expects($this->once())->method('fetchAll')->willReturn([]);
     $this->select->expects($this->any())->method('from')->willReturnSelf();
     $this->select->expects($this->any())->method('where')->willReturnSelf();
     $this->urlFinder->expects($this->any())->method('findAllByData')->willReturn([]);
     $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->willReturn('urlPathWithSuffix');
     $this->productUrlPathGenerator->expects($this->any())->method('getUrlPath')->willReturn('urlPath');
     $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->willReturn('canonicalUrlPath');
     $this->urlRewrite->expects($this->any())->method('setStoreId')->willReturnSelf();
     $this->urlRewrite->expects($this->any())->method('setEntityId')->willReturnSelf();
     $this->urlRewrite->expects($this->any())->method('setEntityType')->willReturnSelf();
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->willReturnSelf();
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->willReturnSelf();
     $this->urlRewrite->expects($this->any())->method('getTargetPath')->willReturn('targetPath');
     $this->urlRewrite->expects($this->any())->method('getStoreId')->willReturnOnConsecutiveCalls(0, 'not global');
     $this->urlRewriteFactory->expects($this->any())->method('create')->willReturn($this->urlRewrite);
     $productUrls = ['targetPath-0' => $this->urlRewrite, 'targetPath-not global' => $this->urlRewrite];
     $this->urlPersist->expects($this->once())->method('replace')->with($productUrls);
     $this->import->execute($this->observer);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:54,代码来源:AfterImportDataObserverTest.php

示例12: testUpdateItem

 /**
  * @param int|\Magento\Wishlist\Model\Item|\PHPUnit_Framework_MockObject_MockObject $itemId
  * @param \Magento\Framework\Object $buyRequest
  * @param null|array|\Magento\Framework\Object $param
  * @throws \Magento\Framework\Model\Exception
  *
  * @dataProvider updateItemDataProvider
  */
 public function testUpdateItem($itemId, $buyRequest, $param)
 {
     $storeId = 1;
     $productId = 1;
     $stores = [(new \Magento\Framework\Object())->setId($storeId)];
     $newItem = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock();
     $newItem->expects($this->any())->method('setProductId')->will($this->returnSelf());
     $newItem->expects($this->any())->method('setWishlistId')->will($this->returnSelf());
     $newItem->expects($this->any())->method('setStoreId')->will($this->returnSelf());
     $newItem->expects($this->any())->method('setOptions')->will($this->returnSelf());
     $newItem->expects($this->any())->method('setProduct')->will($this->returnSelf());
     $newItem->expects($this->any())->method('setQty')->will($this->returnSelf());
     $newItem->expects($this->any())->method('getItem')->will($this->returnValue(2));
     $this->itemFactory->expects($this->once())->method('create')->will($this->returnValue($newItem));
     $this->storeManager->expects($this->any())->method('getStores')->will($this->returnValue($stores));
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($stores[0]));
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $instanceType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock();
     $instanceType->expects($this->once())->method('processConfiguration')->will($this->returnValue($this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock()));
     $newProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $newProduct->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $newProduct->expects($this->once())->method('load')->with($productId)->will($this->returnSelf());
     $newProduct->expects($this->once())->method('getTypeInstance')->will($this->returnValue($instanceType));
     $item = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->getMock();
     $item->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $items = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Collection')->disableOriginalConstructor()->getMock();
     $items->expects($this->once())->method('addWishlistFilter')->will($this->returnSelf());
     $items->expects($this->once())->method('addStoreFilter')->will($this->returnSelf());
     $items->expects($this->once())->method('setVisibilityFilter')->will($this->returnSelf());
     $items->expects($this->once())->method('getItemById')->will($this->returnValue($item));
     $items->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$item])));
     $this->itemsFactory->expects($this->any())->method('create')->will($this->returnValue($items));
     $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($newProduct));
     $this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->updateItem($itemId, $buyRequest, $param));
 }
开发者ID:buskamuza,项目名称:magento2-skeleton,代码行数:44,代码来源:WishlistTest.php

示例13: testPopulateToUrlGenerationReturnProduct

 public function testPopulateToUrlGenerationReturnProduct()
 {
     $rowData = [\Magento\CatalogImportExport\Model\Import\Product::COL_SKU => 'value'];
     $newSku = ['entity_id' => 'new sku value'];
     $expectedRowData = [\Magento\CatalogImportExport\Model\Import\Product::COL_SKU => 'value', 'entity_id' => $newSku['entity_id']];
     $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['addData'], [], '', false);
     $productMock->expects($this->once())->method('addData')->with($expectedRowData);
     $this->catalogProductFactory->expects($this->once())->method('create')->willReturn($productMock);
     $this->skuProcessor->expects($this->once())->method('getNewSku')->willReturn($newSku);
     $result = $this->importProduct->_populateToUrlGeneration($rowData);
     $this->assertEquals($productMock, $result);
 }
开发者ID:shazal,项目名称:magento2,代码行数:12,代码来源:ProductTest.php


注:本文中的Magento\Catalog\Model\ProductFactory::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。