示例#1
0
 /**
  * Test for method addNewItemXmlCallback
  */
 public function testAddNewItemXmlCallback()
 {
     $priceHtmlForTest = '<div class="price">Price is 10 for example</div>';
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getProductUrl', 'getDescription', 'getAllowedInRss', 'getName', '__wakeup'], [], '', false);
     $rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false);
     $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', true, true, true, ['getBlock']);
     $priceRendererMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false);
     $productTitle = 'Product title';
     $productUrl = '<a href="http://product.url">Product Url</a>';
     $imgThumbSrc = 'http://source-for-thumbnail';
     $productDescription = 'Product description';
     $description = '<table><tr><td><a href="' . $productUrl . '"><img src="' . $imgThumbSrc . '" border="0" align="left" height="75" width="75"></a></td><td  style="text-decoration:none;">' . $productDescription . $priceHtmlForTest . '</td></tr></table>';
     $productMock->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue($productUrl));
     $productMock->expects($this->once())->method('getDescription')->will($this->returnValue($productDescription));
     $productMock->expects($this->any())->method('getAllowedInRss')->will($this->returnValue(true));
     $productMock->expects($this->once())->method('getName')->will($this->returnValue($productTitle));
     $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf());
     $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc));
     $layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($priceRendererMock));
     $priceRendererMock->expects($this->once())->method('render')->will($this->returnValue($priceHtmlForTest));
     $expectedData = ['title' => $productTitle, 'link' => $productUrl, 'description' => $description];
     $rssObjMock->expects($this->once())->method('_addEntry')->with($expectedData)->will($this->returnSelf());
     $args = ['product' => $productMock, 'rssObj' => $rssObjMock, 'row' => ''];
     $this->block->setLayout($layoutMock);
     $this->assertNull($this->block->addNewItemXmlCallback($args));
 }
示例#2
0
 public function testGetProductThumbnail()
 {
     $productForThumbnail = $this->_initProduct();
     /** Ensure that image helper was initialized with correct arguments */
     $this->_imageHelper->expects($this->once())->method('init')->with($productForThumbnail, 'thumbnail')->will($this->returnSelf());
     $productThumbnail = $this->_renderer->getProductThumbnail();
     $this->assertSame($this->_imageHelper, $productThumbnail, 'Invalid product thumbnail is returned.');
 }
示例#3
0
 /**
  * @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']));
 }
示例#4
0
 /**
  * @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']));
 }
示例#5
0
 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);
 }
示例#6
0
 /**
  * Additional function to process forming description for wishlist item
  *
  * @param \Magento\Wishlist\Model\Wishlist $wishlistModelMock
  * @param array $staticArgs
  * @return string
  */
 protected function processWishlistItemDescription($wishlistModelMock, $staticArgs)
 {
     $imgThumbSrc = 'http://source-for-thumbnail';
     $priceHtmlForTest = '<div class="price">Price is 10 for example</div>';
     $productDescription = 'Product description';
     $productShortDescription = 'Product short description';
     $wishlistItem = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $wishlistItemsCollection = [$wishlistItem];
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getAllowedInRss', 'getAllowedPriceInRss', 'getDescription', 'getShortDescription', 'getName', 'getVisibleInSiteVisibilities', 'getUrlModel', '__wakeup'], [], '', false);
     $urlModelMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Url', [], [], '', false);
     $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', true, true, true, ['getBlock']);
     $wishlistModelMock->expects($this->once())->method('getItemCollection')->will($this->returnValue($wishlistItemsCollection));
     $wishlistItem->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
     $productMock->expects($this->once())->method('getUrlModel')->will($this->returnValue($urlModelMock));
     $productMock->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue($urlModelMock));
     $urlModelMock->expects($this->once())->method('getUrl')->will($this->returnValue($staticArgs['productUrl']));
     $productMock->expects($this->once())->method('getName')->will($this->returnValue($staticArgs['productName']));
     $productMock->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true));
     $productMock->expects($this->once())->method('getVisibleInSiteVisibilities')->will($this->returnValue(true));
     $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf());
     $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc));
     $priceRendererMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false);
     $layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($priceRendererMock));
     $priceRendererMock->expects($this->once())->method('render')->will($this->returnValue($priceHtmlForTest));
     $productMock->expects($this->any())->method('getDescription')->will($this->returnValue($productDescription));
     $productMock->expects($this->any())->method('getShortDescription')->will($this->returnValue($productShortDescription));
     $this->catalogOutputMock->expects($this->any())->method('productAttribute')->will($this->returnArgument(1));
     $this->block->setLayout($layoutMock);
     $description = '<table><tr><td><a href="' . $staticArgs['productUrl'] . '"><img src="' . $imgThumbSrc . '" border="0" align="left" height="75" width="75"></a></td><td style="text-decoration:none;">' . $productShortDescription . '<p>' . $priceHtmlForTest . '</p><p>Comment: ' . $productDescription . '<p>' . '</td></tr></table>';
     return $description;
 }
示例#7
0
 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']);
 }
示例#8
0
 /**
  * {@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]);
 }
 /**
  * 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());
 }
示例#10
0
 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);
 }
 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();
 }
示例#12
0
 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);
 }
示例#13
0
 public function testGetProductThumbnailUrl()
 {
     $url = 'pub/media/catalog/product/cache/1/thumbnail/75x/9df78eab33525d08d6e5fb8d27136e95/_/_/__green.gif';
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $configView = $this->getMock('Magento\\Framework\\Config\\View', array('getVarValue'), array(), '', false);
     $configView->expects($this->any())->method('getVarValue')->will($this->returnValue(75));
     $this->_configManager->expects($this->any())->method('getViewConfig')->will($this->returnValue($configView));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', array('isConfigurable', '__wakeup'), array(), '', false);
     $product->expects($this->any())->method('isConfigurable')->will($this->returnValue(true));
     $childProduct = $this->getMock('Magento\\Catalog\\Model\\Product', array('getThumbnail', 'getDataByKey', '__wakeup'), array(), '', false);
     $childProduct->expects($this->any())->method('getThumbnail')->will($this->returnValue('/_/_/__green.gif'));
     $this->_imageHelper->expects($this->any())->method('init')->will($this->returnValue($this->_imageHelper));
     $this->_imageHelper->expects($this->any())->method('resize')->will($this->returnValue($this->_imageHelper));
     $this->_imageHelper->expects($this->any())->method('__toString')->will($this->returnValue($url));
     $arguments = array('statusListFactory' => $this->getMock('Magento\\Sales\\Model\\Status\\ListFactory', array(), array(), '', false), 'productFactory' => $this->getMock('Magento\\Catalog\\Model\\ProductFactory', array(), array(), '', false), 'itemOptionFactory' => $this->getMock('Magento\\Sales\\Model\\Quote\\Item\\OptionFactory', array(), array(), '', false));
     $childItem = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments);
     $childItem->setData('product', $childProduct);
     $item = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments);
     $item->setData('product', $product);
     $item->addChild($childItem);
     $this->_renderer->setItem($item);
     $configurableUrl = $this->_renderer->getProductThumbnailUrl();
     $this->assertNotNull($configurableUrl);
 }
 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);
 }
示例#15
0
 /**
  * @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);
 }
示例#16
0
 /**
  * @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);
 }
示例#17
0
 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());
 }
示例#18
0
 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);
 }