Esempio n. 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetProductCollection()
 {
     $storeId = 1;
     $categoryChildren = 'children';
     $visibleInCatalogIds = 1;
     $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->will($this->returnValue($visibleInCatalogIds));
     $products = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['setStoreId', 'addAttributeToSort', 'setVisibility', 'setCurPage', 'setPageSize', 'addCountToCategories'], [], '', false);
     $resourceCollection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Collection\\AbstractCollection', ['addAttributeToSelect', 'addAttributeToFilter', 'addIdFilter', 'load'], [], '', false);
     $resourceCollection->expects($this->exactly(3))->method('addAttributeToSelect')->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('addIdFilter')->with($categoryChildren)->will($this->returnSelf());
     $resourceCollection->expects($this->once())->method('load')->will($this->returnSelf());
     $products->expects($this->once())->method('addCountToCategories')->with($resourceCollection);
     $products->expects($this->once())->method('addAttributeToSort')->with('updated_at', 'desc')->will($this->returnSelf());
     $products->expects($this->once())->method('setVisibility')->with($visibleInCatalogIds)->will($this->returnSelf());
     $products->expects($this->once())->method('setCurPage')->with(1)->will($this->returnSelf());
     $products->expects($this->once())->method('setPageSize')->with(50)->will($this->returnSelf());
     $products->expects($this->once())->method('setStoreId')->with($storeId);
     $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($products));
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getResourceCollection', 'getChildren', 'getProductCollection', '__wakeup'], [], '', false);
     $category->expects($this->once())->method('getResourceCollection')->will($this->returnValue($resourceCollection));
     $category->expects($this->once())->method('getChildren')->will($this->returnValue($categoryChildren));
     $category->expects($this->once())->method('getProductCollection')->will($this->returnValue($products));
     $layer = $this->getMock('Magento\\Catalog\\Model\\Layer', ['setCurrentCategory', 'prepareProductCollection', 'getProductCollection', '__wakeup'], [], '', false);
     $layer->expects($this->once())->method('setCurrentCategory')->with($category)->will($this->returnSelf());
     $layer->expects($this->once())->method('getProductCollection')->will($this->returnValue($products));
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Layer\Resolver $layerResolver */
     $layerResolver = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Resolver')->disableOriginalConstructor()->setMethods(['get', 'create'])->getMock();
     $layerResolver->expects($this->any())->method($this->anything())->will($this->returnValue($layer));
     $this->categoryLayer->expects($this->once())->method('setStore')->with($storeId)->will($this->returnValue($layer));
     $this->assertEquals($products, $this->model->getProductCollection($category, $storeId));
 }
Esempio n. 2
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']);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function getRssData()
 {
     try {
         $category = $this->categoryRepository->get($this->getRequest()->getParam('cid'));
     } catch (NoSuchEntityException $e) {
         return ['title' => 'Category Not Found', 'description' => 'Category Not Found', 'link' => $this->getUrl(''), 'charset' => 'UTF-8'];
     }
     $category->setIsAnchor(true);
     $newUrl = $category->getUrl();
     $title = $category->getName();
     $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($this->rssModel->getProductCollection($category, $this->getStoreId()) as $product) {
         $product->setAllowedInRss(true);
         $product->setAllowedPriceInRss(true);
         $this->_eventManager->dispatch('rss_catalog_category_xml_callback', ['product' => $product]);
         if (!$product->getAllowedInRss()) {
             continue;
         }
         $description = '
                 <table><tr>
                     <td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td>
                     <td  style="text-decoration:none;">%s %s</td>
                 </tr></table>
             ';
         $description = sprintf($description, $product->getProductUrl(), $this->imageHelper->init($product, 'rss_thumbnail')->getUrl(), $product->getDescription(), $product->getAllowedPriceInRss() ? $this->renderPriceHtml($product) : '');
         $data['entries'][] = ['title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $description];
     }
     return $data;
 }