本文整理汇总了PHP中Magento\Catalog\Model\Product::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::expects方法的具体用法?PHP Product::expects怎么用?PHP Product::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetLinkData
public function testGetLinkData()
{
$expectingFileData = ['file' => ['file' => 'file/link.gif', 'name' => '<a href="final_url">link.gif</a>', 'size' => '1.1', 'status' => 'old'], 'sample_file' => ['file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old']];
$this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
$this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
$this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
$this->downloadableProductModel->expects($this->any())->method('getLinks')->will($this->returnValue([$this->downloadableLinkModel]));
$this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
$this->downloadableLinkModel->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->downloadableLinkModel->expects($this->any())->method('getTitle')->will($this->returnValue('Link Title'));
$this->downloadableLinkModel->expects($this->any())->method('getPrice')->will($this->returnValue('10'));
$this->downloadableLinkModel->expects($this->any())->method('getNumberOfDownloads')->will($this->returnValue('6'));
$this->downloadableLinkModel->expects($this->any())->method('getLinkUrl')->will($this->returnValue(null));
$this->downloadableLinkModel->expects($this->any())->method('getLinkType')->will($this->returnValue('file'));
$this->downloadableLinkModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
$this->downloadableLinkModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
$this->downloadableLinkModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
$this->downloadableLinkModel->expects($this->any())->method('getLinkFile')->will($this->returnValue('file/link.gif'));
$this->downloadableLinkModel->expects($this->any())->method('getStoreTitle')->will($this->returnValue('Store Title'));
$this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Link Title'));
$this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/link.gif'));
$this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
$this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
$this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
$linkData = $this->block->getLinkData();
foreach ($linkData as $link) {
$fileSave = $link->getFileSave(0);
$sampleFileSave = $link->getSampleFileSave(0);
$this->assertEquals($expectingFileData['file'], $fileSave);
$this->assertEquals($expectingFileData['sample_file'], $sampleFileSave);
}
}
示例2: setUp
/**
* Set up
*/
protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
$this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
$this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
$this->product->expects($this->any())->method('getId')->willReturn(1);
$this->product->expects($this->any())->method('getPriceType')->willReturn(1);
$this->product->expects($this->any())->method('getSkuType')->willReturn(1);
$this->product->expects($this->any())->method('getPriceView')->willReturn(1);
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
$this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
$this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
$this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
$this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
$this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
$this->option->expects($this->any())->method('getId')->willReturn(1);
$this->option->expects($this->any())->method('getTitle')->willReturn('title');
$this->option->expects($this->any())->method('getType')->willReturn(1);
$this->option->expects($this->any())->method('getRequired')->willReturn(1);
$this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
$this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
$this->selection->expects($this->any())->method('getSku')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
$this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
$this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
$this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
$this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
$this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
$this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
}
示例3: testGetImages
public function testGetImages()
{
$mediaGallery = ['images' => [['value_id' => '1', 'file' => 'image_1.jpg', 'media_type' => 'image'], ['value_id' => '2', 'file' => 'image_2.jpg', 'media_type' => 'image']]];
$this->registryMock->expects($this->once())->method('registry')->willReturn($this->productMock);
$this->productMock->expects($this->once())->method('getData')->willReturn($mediaGallery);
$this->assertSame($mediaGallery, $this->gallery->getImages());
}
示例4: testGetSampleData
public function testGetSampleData()
{
$expectingFileData = array('sample_file' => array('file' => 'file/sample.gif', 'name' => '<a href="final_url">sample.gif</a>', 'size' => '1.1', 'status' => 'old'));
$this->productModel->expects($this->any())->method('getTypeId')->will($this->returnValue('downloadable'));
$this->productModel->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->downloadableProductModel));
$this->productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(0));
$this->downloadableProductModel->expects($this->any())->method('getSamples')->will($this->returnValue(array($this->downloadableSampleModel)));
$this->coreRegistry->expects($this->any())->method('registry')->will($this->returnValue($this->productModel));
$this->downloadableSampleModel->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->downloadableSampleModel->expects($this->any())->method('getTitle')->will($this->returnValue('Sample Title'));
$this->downloadableSampleModel->expects($this->any())->method('getSampleUrl')->will($this->returnValue(null));
$this->downloadableSampleModel->expects($this->any())->method('getSampleFile')->will($this->returnValue('file/sample.gif'));
$this->downloadableSampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('file'));
$this->downloadableSampleModel->expects($this->any())->method('getSortOrder')->will($this->returnValue(0));
$this->escaper->expects($this->any())->method('escapeHtml')->will($this->returnValue('Sample Title'));
$this->fileHelper->expects($this->any())->method('getFilePath')->will($this->returnValue('/file/path/sample.gif'));
$this->fileHelper->expects($this->any())->method('ensureFileInFilesystem')->will($this->returnValue(true));
$this->fileHelper->expects($this->any())->method('getFileSize')->will($this->returnValue('1.1'));
$this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue('final_url'));
$sampleData = $this->block->getSampleData();
foreach ($sampleData as $sample) {
$fileSave = $sample->getFileSave(0);
$this->assertEquals($expectingFileData['sample_file'], $fileSave);
}
}
示例5: testBeforeInitializeLinksProductIsReadonly
public function testBeforeInitializeLinksProductIsReadonly()
{
$this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(Grouped::TYPE_CODE));
$this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(true));
$this->productMock->expects($this->never())->method('setGroupedLinkData');
$this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, ['associated' => 'value']);
}
示例6: testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost
public function testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost()
{
$this->request->expects($this->any())->method('getParam')->willReturnMap([['set', null, 4]]);
$this->request->expects($this->any())->method('getPost')->willReturnMap([['set', null, null]]);
$this->product->expects($this->once())->method('setAttributeSetId')->with(4);
$this->action->execute();
}
示例7: testPrepareJsonAttributes
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPrepareJsonAttributes()
{
$storeId = '1';
$attributeId = 5;
$attributeOptions = [['value_index' => 'option_id_1', 'label' => 'label_1'], ['value_index' => 'option_id_2', 'label' => 'label_2']];
$position = 2;
$expected = ['attributes' => [$attributeId => ['id' => $attributeId, 'code' => 'test_attribute', 'label' => 'Test', 'position' => $position, 'options' => [0 => ['id' => 'option_id_1', 'label' => 'label_1', 'products' => 'option_products_1'], 1 => ['id' => 'option_id_2', 'label' => 'label_2', 'products' => 'option_products_2']]]], 'defaultValues' => [$attributeId => 'option_id_1']];
$options = [$attributeId => ['option_id_1' => 'option_products_1', 'option_id_2' => 'option_products_2']];
$productAttributeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getStoreLabel', '__wakeup', 'getAttributeCode', 'getId', 'getAttributeLabel'])->getMock();
$productAttributeMock->expects($this->once())->method('getId')->willReturn($attributeId);
$productAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn($expected['attributes'][$attributeId]['code']);
$attributeMock = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['getProductAttribute', '__wakeup', 'getLabel', 'getOptions', 'getAttributeId', 'getPosition'])->getMock();
$attributeMock->expects($this->once())->method('getProductAttribute')->willReturn($productAttributeMock);
$attributeMock->expects($this->once())->method('getPosition')->willReturn($position);
$this->product->expects($this->once())->method('getStoreId')->willReturn($storeId);
$productAttributeMock->expects($this->once())->method('getStoreLabel')->with($storeId)->willReturn($expected['attributes'][$attributeId]['label']);
$attributeMock->expects($this->atLeastOnce())->method('getAttributeId')->willReturn($attributeId);
$attributeMock->expects($this->atLeastOnce())->method('getOptions')->willReturn($attributeOptions);
$configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock();
$configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->product)->willReturn([$attributeMock]);
$configuredValueMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
$configuredValueMock->expects($this->any())->method('getData')->willReturn($expected['defaultValues'][$attributeId]);
$this->product->expects($this->once())->method('getTypeInstance')->willReturn($configurableProduct);
$this->product->expects($this->once())->method('hasPreconfiguredValues')->willReturn(true);
$this->product->expects($this->once())->method('getPreconfiguredValues')->willReturn($configuredValueMock);
$this->assertEquals($expected, $this->configurableAttributeData->getAttributesData($this->product, $options));
}
示例8: testConvertTo
public function testConvertTo()
{
$rowData = ['value_id' => '6', 'file' => '/s/a/sample-1_1.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '5', 'disabled' => '0', 'label_default' => null, 'position_default' => '5', 'disabled_default' => '0'];
$productImages = ['image' => '/s/a/sample_3.jpg', 'small_image' => '/s/a/sample-1_1.jpg', 'thumbnail' => '/s/a/sample-1_1.jpg', 'swatch_image' => '/s/a/sample_3.jpg'];
$this->productMock->expects($this->any())->method('getMediaAttributeValues')->willReturn($productImages);
$this->modelObject->convertTo($this->productMock, $rowData);
}
示例9: testGetAllowAttributes
public function testGetAllowAttributes()
{
$typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
$typeInstanceMock->expects($this->once())->method('getConfigurableAttributes')->with($this->_productMock);
$this->_productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
$this->_model->getAllowAttributes($this->_productMock);
}
示例10: _testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost
public function _testAttributeSetIsObtainedFromGetWhenThereIsNoOneInPost()
{
$this->request->expects($this->any())->method('getParam')->willReturnMap([['set', null, 4]]);
$this->request->expects($this->any())->method('getPost')->willReturnMap([['set', null, null], ['product', [], []]]);
$this->product->expects($this->once())->method('setAttributeSetId')->with(4);
$this->initializationHelper->expects($this->any())->method('initializeFromData')->willReturn($this->product);
$this->action->execute();
}
示例11: testAfterExecuteNoVideo
public function testAfterExecuteNoVideo()
{
$mediaData = ['images' => [['value_id' => '7', 'file' => '/h/d/hd_image.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '4', 'disabled' => '0', 'label_default' => null, 'position_default' => '4', 'disabled_default' => '0']], 'values' => []];
$this->product->expects($this->once())->method('getData')->with('media_gallery')->willReturn($mediaData);
$this->resourceModel->expects($this->never())->method('loadDataFromTableByValueId');
$this->mediaGalleryReadHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
$this->subject->afterExecute($this->mediaGalleryReadHandler, $this->product);
}
示例12: testAfterDeleteScheduled
public function testAfterDeleteScheduled()
{
$this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true));
$this->indexerMock->expects($this->never())->method('reindexRow');
$this->prepareIndexer();
$this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock));
}
示例13: testExecuteObtainsProductDataFromSession
public function testExecuteObtainsProductDataFromSession()
{
$this->action->getRequest()->expects($this->any())->method('getParam')->willReturn(true);
$this->action->getRequest()->expects($this->any())->method('getFullActionName')->willReturn('catalog_product_new');
$this->session->expects($this->any())->method('getProductData')->willReturn(['product' => ['name' => 'test-name']]);
$this->product->expects($this->once())->method('addData')->with(['name' => 'test-name', 'stock_data' => null]);
$this->action->execute();
}
示例14: testValidateWithNoValue
/**
* @return void
*/
public function testValidateWithNoValue()
{
$this->product->setData('attribute', 'color');
$this->product->setData('value_parsed', '1');
$this->product->setData('operator', '!=');
$this->productModel->expects($this->once())->method('getData')->with('color')->willReturn(null);
$this->assertFalse($this->product->validate($this->productModel));
}
示例15: testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError
/**
* @param string $exceptionType
* @return void
* @dataProvider exceptionTypeDataProvider
*/
public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType)
{
$productData = ['product' => ['name' => 'test-name']];
$this->request->expects($this->any())->method('getPostValue')->willReturn($productData);
$this->initializationHelper->expects($this->any())->method('initialize')->willReturn($this->product);
$this->product->expects($this->any())->method('getSku')->willThrowException(new $exceptionType(__('message')));
$this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/new');
$this->action->execute();
}