本文整理汇总了PHP中Magento\Catalog\Helper\Image::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::expects方法的具体用法?PHP Image::expects怎么用?PHP Image::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Helper\Image
的用法示例。
在下文中一共展示了Image::expects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetOptions
/**
* @param array $expected
* @param array $data
* @dataProvider getOptionsDataProvider
*/
public function testGetOptions(array $expected, array $data)
{
$this->_imageHelperMock->expects($this->at(0))->method('init')->will($this->returnValue('http://example.com/base_img_url'));
for ($i = 1; $i <= count($data['allowed_products']); $i++) {
$this->_imageHelperMock->expects($this->at($i))->method('init')->will($this->returnValue('http://example.com/base_img_url_' . $i));
}
$this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
}
示例2: testGetOptions
/**
* @param array $expected
* @param array $data
* @dataProvider getOptionsDataProvider
*/
public function testGetOptions(array $expected, array $data)
{
if (count($data['allowed_products'])) {
$imageHelper1 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
$imageHelper1->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url');
$imageHelper2 = $this->getMockBuilder('Magento\\Catalog\\Helper\\Image')->disableOriginalConstructor()->getMock();
$imageHelper2->expects($this->any())->method('getUrl')->willReturn('http://example.com/base_img_url_2');
$this->_imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$data['current_product_mock'], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][0], 'product_page_image_large', [], $imageHelper1], [$data['allowed_products'][1], 'product_page_image_large', [], $imageHelper2]]);
}
$this->assertEquals($expected, $this->_model->getOptions($data['current_product_mock'], $data['allowed_products']));
}
示例3: testGenerate
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData());
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config);
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}
示例4: testGetRssData
public function testGetRssData()
{
$category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->setMethods(['__sleep', '__wakeup', 'load', 'getId', 'getUrl', 'getName'])->disableOriginalConstructor()->getMock();
$category->expects($this->once())->method('getName')->will($this->returnValue('Category Name'));
$category->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/category-name.html'));
$this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category));
$product = $this->getMockBuilder('\\Magento\\catalog\\Model\\Product')->setMethods(['__sleep', '__wakeup', 'getName', 'getAllowedInRss', 'getProductUrl', 'getDescription', 'getAllowedPriceInRss'])->disableOriginalConstructor()->getMock();
$product->expects($this->once())->method('getName')->will($this->returnValue('Product Name'));
$product->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true));
$product->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue('http://magento.com/product.html'));
$product->expects($this->once())->method('getDescription')->will($this->returnValue('Product Description'));
$product->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue(true));
$this->rssModel->expects($this->once())->method('getProductCollection')->will($this->returnValue([$product]));
$this->imageHelper->expects($this->once())->method('init')->with($product, 'thumbnail')->will($this->returnSelf());
$this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link'));
$data = $this->block->getRssData();
$this->assertEquals($this->rssFeed['link'], $data['link']);
$this->assertEquals($this->rssFeed['title'], $data['title']);
$this->assertEquals($this->rssFeed['description'], $data['description']);
$this->assertEquals($this->rssFeed['entries'][0]['title'], $data['entries'][0]['title']);
$this->assertEquals($this->rssFeed['entries'][0]['link'], $data['entries'][0]['link']);
$this->assertContains('<a href="http://magento.com/product.html">', $data['entries'][0]['description']);
$this->assertContains('<img src="image_link" border="0" align="left" height="75" width="75">', $data['entries'][0]['description']);
$this->assertContains('<td style="text-decoration:none;">Product Description </td>', $data['entries'][0]['description']);
}
示例5: createModel
/**
* {@inheritdoc}
*/
protected function createModel()
{
$this->currencyMock = $this->getMockBuilder(CurrencyInterface::class)->setMethods(['getCurrency', 'toCurrency'])->getMockForAbstractClass();
$this->currencyMock->expects($this->any())->method('getCurrency')->willReturn($this->currencyMock);
$this->imageHelperMock = $this->getMockBuilder(ImageHelper::class)->setMethods(['init', 'getUrl'])->disableOriginalConstructor()->getMock();
$this->imageHelperMock->expects($this->any())->method('init')->willReturn($this->imageHelperMock);
$this->attributeSetRepositoryMock = $this->getMockBuilder(AttributeSetRepositoryInterface::class)->setMethods(['get'])->getMockForAbstractClass();
$attributeSetMock = $this->getMockBuilder(AttributeSetInterface::class)->setMethods(['getAttributeSetName'])->getMockForAbstractClass();
$this->attributeSetRepositoryMock->expects($this->any())->method('get')->willReturn($attributeSetMock);
return $this->objectManager->getObject(Grouped::class, ['locator' => $this->locatorMock, 'productLinkRepository' => $this->linkRepositoryMock, 'productRepository' => $this->productRepositoryMock, 'localeCurrency' => $this->currencyMock, 'imageHelper' => $this->imageHelperMock, 'attributeSetRepository' => $this->attributeSetRepositoryMock]);
}
示例6: addMocks
/**
* Additional function to break up mocks initialization
*
* @return void
*/
protected function addMocks()
{
$resIteratorcallback = function () {
$arguments = func_get_args();
$arguments[2]['results'] = [['use_special' => false, 'price' => 10, 'final_price' => 20]];
};
$this->storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue(0));
$this->storeMock->expects($this->once())->method('getFrontendName')->will($this->returnValue('store name'));
$this->catalogHelperMock->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false));
$this->resourceIteratorMock->expects($this->once())->method('walk')->will($this->returnCallback($resIteratorcallback));
$this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf());
}
示例7: testGetItemData
public function testGetItemData()
{
$urlModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Url::class)->disableOriginalConstructor()->getMock();
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->setMethods(['getUrlModel', 'isVisibleInSiteVisibility', 'getSku'])->disableOriginalConstructor()->getMock();
$product->expects($this->any())->method('getUrlModel')->willReturn($urlModel);
$product->expects($this->any())->method('isVisibleInSiteVisibility')->willReturn(true);
$product->expects($this->any())->method('getSku')->willReturn('simple');
/** @var \Magento\Quote\Model\Quote\Item $item */
$item = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)->setMethods(['getProductType', 'getProduct', 'getCalculationPrice'])->disableOriginalConstructor()->getMock();
$item->expects($this->any())->method('getProduct')->willReturn($product);
$item->expects($this->any())->method('getProductType')->willReturn('simple');
$item->expects($this->any())->method('getCalculationPrice')->willReturn(5);
$this->imageHelper->expects($this->any())->method('init')->with($product)->willReturnSelf();
$this->imageHelper->expects($this->any())->method('getUrl')->willReturn('url');
$this->imageHelper->expects($this->any())->method('getLabel')->willReturn('label');
$this->imageHelper->expects($this->any())->method('getWidth')->willReturn(100);
$this->imageHelper->expects($this->any())->method('getHeight')->willReturn(100);
$this->configurationPool->expects($this->any())->method('getByProductType')->willReturn($product);
$itemData = $this->model->getItemData($item);
$this->assertArrayHasKey('options', $itemData);
$this->assertArrayHasKey('qty', $itemData);
$this->assertArrayHasKey('item_id', $itemData);
$this->assertArrayHasKey('configure_url', $itemData);
$this->assertArrayHasKey('is_visible_in_site_visibility', $itemData);
$this->assertArrayHasKey('product_type', $itemData);
$this->assertArrayHasKey('product_name', $itemData);
$this->assertArrayHasKey('product_sku', $itemData);
$this->assertArrayHasKey('product_url', $itemData);
$this->assertArrayHasKey('product_has_url', $itemData);
$this->assertArrayHasKey('product_price', $itemData);
$this->assertArrayHasKey('product_price_value', $itemData);
$this->assertArrayHasKey('product_image', $itemData);
$this->assertArrayHasKey('canApplyMsrp', $itemData);
}
示例8: testGetJsonSwatchConfigWithoutVisualImageType
public function testGetJsonSwatchConfigWithoutVisualImageType()
{
$this->configurable->setProduct($this->product);
$this->swatchHelper->expects($this->once())->method('getSwatchAttributesAsArray')->with($this->product)->willReturn([1 => ['options' => [1 => 'testA', 3 => 'testB'], 'use_product_image_for_swatch' => true, 'attribute_code' => 'code']]);
$this->swatchHelper->expects($this->once())->method('getSwatchesByOptionsId')->with([1, 3])->willReturn([3 => ['type' => Swatch::SWATCH_TYPE_VISUAL_IMAGE, 'value' => 'hello']]);
$this->swatchHelper->expects($this->once())->method('loadFirstVariationWithSwatchImage')->with($this->product, ['code' => 3])->willReturn($this->product);
$this->swatchMediaHelper->expects($this->exactly(2))->method('getSwatchAttributeImage')->withConsecutive(['swatch_image', 'hello'], ['swatch_thumb', 'hello'])->willReturn('/path');
$this->product->expects($this->exactly(4))->method('getData')->withConsecutive(['swatch_image'], ['image'], ['swatch_image'], ['image'])->will($this->onConsecutiveCalls(null, null, null, null));
$this->imageHelper->expects($this->never())->method('init');
$this->imageHelper->expects($this->never())->method('resize');
$this->jsonEncoder->expects($this->once())->method('encode');
$this->configurable->getJsonSwatchConfig();
}
示例9: testGetGalleryImages
public function testGetGalleryImages()
{
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
$productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock();
$productTypeMock->expects($this->once())->method('getStoreFilter')->with($productMock)->willReturn($storeMock);
$productMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
$productMock->expects($this->once())->method('getMediaGalleryImages')->willReturn($this->getImagesCollection());
$this->registry->expects($this->once())->method('registry')->with('product')->willReturn($productMock);
$this->imageHelper->expects($this->exactly(3))->method('init')->willReturnMap([[$productMock, 'product_page_image_small', [], $this->imageHelper], [$productMock, 'product_page_image_medium', [], $this->imageHelper], [$productMock, 'product_page_image_large', [], $this->imageHelper]])->willReturnSelf();
$this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with('test_file')->willReturnSelf();
$this->imageHelper->expects($this->at(0))->method('getUrl')->willReturn('product_page_image_small_url');
$this->imageHelper->expects($this->at(1))->method('getUrl')->willReturn('product_page_image_medium_url');
$this->imageHelper->expects($this->at(2))->method('getUrl')->willReturn('product_page_image_large_url');
$this->imageHelper->expects($this->exactly(2))->method('constrainOnly')->with(true)->willReturnSelf();
$this->imageHelper->expects($this->exactly(2))->method('keepAspectRatio')->with(true)->willReturnSelf();
$this->imageHelper->expects($this->exactly(2))->method('keepFrame')->with(false)->willReturnSelf();
$images = $this->model->getGalleryImages();
$this->assertInstanceOf('Magento\\Framework\\Data\\Collection', $images);
}
示例10: testGetRssData
public function testGetRssData()
{
$this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'new_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/new_products/store_id/1'));
$item = $this->getItemMock();
$this->newProducts->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item]));
$this->imageHelper->expects($this->once())->method('init')->with($item, 'thumbnail')->will($this->returnSelf());
$this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link'));
$data = ['title' => 'New Products from Store 1', 'description' => 'New Products from Store 1', 'link' => 'http://magento.com/rss/feed/index/type/new_products/store_id/1', 'charset' => 'UTF-8', 'language' => null, 'entries' => [['title' => 'Product Name', 'link' => 'http://magento.com/product-name.html']]];
$rssData = $this->block->getRssData();
$description = $rssData['entries'][0]['description'];
unset($rssData['entries'][0]['description']);
$this->assertEquals($data, $rssData);
$this->assertContains('<a href="http://magento.com/product-name.html">', $description);
$this->assertContains('<img src="image_link" border="0" align="left" height="75" width="75">', $description);
$this->assertContains('<td style="text-decoration:none;">Product Description </td>', $description);
}
示例11: testGenerate
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGenerate()
{
$imageFile = 'image.jpg';
$imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
$this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
$this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
$data = $this->getTestData();
$this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
$themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
$themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
$this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
$this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
$this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
$this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
$this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
$this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
$this->model->generate($this->product);
}
示例12: testGetProductMediaGallery
/**
* @dataProvider dataForMediaGallery
*/
public function testGetProductMediaGallery($mediaGallery, $image)
{
$this->productMock->expects($this->once())->method('getMediaAttributeValues')->willReturn($mediaGallery);
$this->imageHelperMock->expects($this->any())->method('init')->willReturnMap([[$this->productMock, 'product_page_image_large', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_medium', [], $this->imageHelperMock], [$this->productMock, 'product_page_image_small', [], $this->imageHelperMock]]);
$this->imageHelperMock->expects($this->any())->method('setImageFile')->with($image)->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('constrainOnly')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('keepAspectRatio')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('keepFrame')->willReturnSelf();
$this->imageHelperMock->expects($this->any())->method('getUrl')->willReturn('http://full_path_to_image/magento1.png');
$mediaObject = $this->getMock('\\Magento\\Framework\\DataObject', [], [], '', false);
$iterator = new \ArrayIterator([$mediaObject]);
$mediaCollectionMock = $this->getMock('\\Magento\\Framework\\Data\\Collection', [], [], '', false);
$mediaCollectionMock->expects($this->any())->method('getIterator')->willReturn($iterator);
$mediaObject->method('getData')->withConsecutive(['value_id'], ['file'])->willReturnOnConsecutiveCalls(0, $image);
$this->productMock->method('getMediaGalleryImages')->willReturn($mediaCollectionMock);
$this->swatchHelperObject->getProductMediaGallery($this->productMock);
}
示例13: testGetSectionDataWithoutItems
public function testGetSectionDataWithoutItems()
{
$items = [];
$result = ['counter' => null, 'items' => []];
$this->wishlistHelperMock->expects($this->once())->method('getItemCount')->willReturn(count($items));
$this->viewMock->expects($this->never())->method('loadLayout');
$this->wishlistHelperMock->expects($this->never())->method('getWishlistItemCollection');
$this->catalogImageHelperMock->expects($this->never())->method('init');
$this->catalogImageHelperMock->expects($this->never())->method('getUrl');
$this->catalogImageHelperMock->expects($this->never())->method('getLabel');
$this->catalogImageHelperMock->expects($this->never())->method('getWidth');
$this->catalogImageHelperMock->expects($this->never())->method('getHeight');
$this->wishlistHelperMock->expects($this->never())->method('getProductUrl');
$this->sidebarMock->expects($this->never())->method('getProductPriceHtml');
$this->wishlistHelperMock->expects($this->never())->method('getAddToCartParams');
$this->wishlistHelperMock->expects($this->never())->method('getRemoveParams');
$this->assertEquals($result, $this->model->getSectionData());
}
示例14: testGetRssData
public function testGetRssData()
{
$this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'special_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/special_products/store_id/1'));
$item = $this->getItemMock();
$this->rssModel->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item]));
$this->msrpHelper->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false));
$this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue(date('Y-m-d')));
$this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0));
$this->imageHelper->expects($this->once())->method('init')->with($item, 'rss_thumbnail')->will($this->returnSelf());
$this->imageHelper->expects($this->once())->method('getUrl')->will($this->returnValue('image_link'));
$this->outputHelper->expects($this->once())->method('productAttribute')->will($this->returnValue(''));
$data = ['title' => 'Store 1 - Special Products', 'description' => 'Store 1 - Special Products', 'link' => 'http://magento.com/rss/feed/index/type/special_products/store_id/1', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => [['title' => 'Product Name', 'link' => 'http://magento.com/product-name.html']]];
$rssData = $this->block->getRssData();
$description = $rssData['entries'][0]['description'];
unset($rssData['entries'][0]['description']);
$this->assertEquals($data, $rssData);
$this->assertContains('<a href="http://magento.com/product-name.html"><', $description);
$this->assertContains(sprintf('<p>Price: Special Price: 10<br />Special Expires On: %s</p>', date('Y-m-d')), $description);
$this->assertContains('<img src="image_link" alt="" border="0" align="left" height="75" width="75" />', $description);
}