public function testGetAddToCartPostParams()
 {
     $url = 'http://localhost.com/dev/';
     $id = 1;
     $uenc = strtr(base64_encode($url), '+/=', '-_,');
     $expectedPostData = ['action' => $url, 'data' => ['product' => $id, 'uenc' => $uenc]];
     $this->typeInstanceMock->expects($this->once())->method('hasRequiredOptions')->with($this->equalTo($this->productMock))->will($this->returnValue(false));
     $this->cartHelperMock->expects($this->any())->method('getAddUrl')->with($this->equalTo($this->productMock), $this->equalTo([]))->will($this->returnValue($url));
     $this->productMock->expects($this->once())->method('getEntityId')->will($this->returnValue($id));
     $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($this->typeInstanceMock));
     $this->urlHelperMock->expects($this->once())->method('getEncodedUrl')->with($this->equalTo($url))->will($this->returnValue($uenc));
     $result = $this->block->getAddToCartPostParams($this->productMock);
     $this->assertEquals($expectedPostData, $result);
 }
Example #2
0
 public function testPrepareSortableFieldsByCategory()
 {
     /** @var $category \Magento\Catalog\Model\Category */
     $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category');
     $category->setDefaultSortBy('name');
     $this->_block->prepareSortableFieldsByCategory($category);
     $this->assertEquals('name', $this->_block->getSortBy());
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getImage($product, $imageId, $attributes = array())
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getImage');
     if (!$pluginInfo) {
         return parent::getImage($product, $imageId, $attributes);
     } else {
         return $this->___callPlugins('getImage', func_get_args(), $pluginInfo);
     }
 }
Example #4
0
 public function testGetAddToCartPostParams()
 {
     $url = 'http://localhost.com/dev/';
     $id = 1;
     $uenc = strtr(base64_encode($url), '+/=', '-_,');
     $data = array('product' => $id, \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $uenc);
     $expectedPostData = json_encode(array('action' => $url, 'data' => array('product' => $id, 'uenc' => $uenc)));
     $this->typeInstanceMock->expects($this->once())->method('hasRequiredOptions')->with($this->equalTo($this->productMock))->will($this->returnValue(false));
     $this->cartHelperMock->expects($this->any())->method('getAddUrl')->with($this->equalTo($this->productMock), $this->equalTo(array()))->will($this->returnValue($url));
     $this->productMock->expects($this->once())->method('getEntityId')->will($this->returnValue($id));
     $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($this->typeInstanceMock));
     $this->postDataHelperMock->expects($this->once())->method('getEncodedUrl')->with($this->equalTo($url))->will($this->returnValue($uenc));
     $this->postDataHelperMock->expects($this->once())->method('getPostData')->with($this->equalTo($url), $this->equalTo($data))->will($this->returnValue($expectedPostData));
     $result = $this->block->getAddToCartPostParams($this->productMock);
     $this->assertEquals($expectedPostData, $result);
 }
Example #5
0
 public function testGetIdentities()
 {
     $this->assertEquals([\Magento\Catalog\Model\Product::CACHE_TAG], $this->block->getIdentities());
 }
Example #6
0
 /**
  * @param \Magento\Catalog\Block\Product\Context $context
  * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
  * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
  * @param CategoryRepositoryInterface $categoryRepository
  * @param \Magento\Framework\Url\Helper\Data $urlHelper
  * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
  * @param array $data
  */
 public function __construct(\Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, \Magento\Catalog\Model\Layer\Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Url\Helper\Data $urlHelper, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = [])
 {
     $this->_productCollectionFactory = $productCollectionFactory;
     parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
 }
 /**
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $toolbar = $this->getToolbarBlock();
     // called prepare sortable parameters
     $collection = $this->_getProductCollection();
     // use sortable parameters
     $orders = $this->getAvailableOrders();
     if ($orders) {
         $toolbar->setAvailableOrders($orders);
     }
     $toolbar->setDefaultOrder('relevance');
     $dir = $this->getDefaultDirection();
     if ($dir) {
         $toolbar->setDefaultDirection($dir);
     }
     $modes = $this->getModes();
     if ($modes) {
         $toolbar->setModes($modes);
     }
     // set collection to toolbar and apply sort
     $toolbar->setCollection($collection);
     $this->setChild('toolbar', $toolbar);
     $this->_eventManager->dispatch('catalog_block_product_list_collection', ['collection' => $this->_getProductCollection()]);
     $this->_getProductCollection()->load();
     return parent::_beforeToHtml();
 }
Example #8
0
 /**
  * @return $this
  */
 protected function _beforeToHtml()
 {
     parent::_beforeToHtml();
     /** @var \Magento\Catalog\Block\Product\ProductList\Toolbar $toolbar */
     $toolbar = $this->getChildBlock('toolbar');
     /** @var \Magento\Theme\Block\Html\Pager $pager */
     $pager = $toolbar->getChildBlock('product_list_toolbar_pager');
     $pager->setFragment('sample_news.author.view.product');
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet');
     if (!$pluginInfo) {
         return parent::offsetGet($offset);
     } else {
         return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo);
     }
 }
Example #10
0
 /**
  * @param \Magento\Catalog\Block\Product\Context $context
  * @param \Magento\Core\Helper\PostData $postDataHelper
  * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
  * @param \Magento\Catalog\Model\Layer\Category $catalogLayer
  * @param \Magento\Catalog\Model\LayerFactory $layerFactory
  * @param \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory
  * @param array $data
  */
 public function __construct(\Magento\Catalog\Block\Product\Context $context, \Magento\Core\Helper\PostData $postDataHelper, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\Layer\Category $catalogLayer, \Magento\Catalog\Model\LayerFactory $layerFactory, \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory, array $data = array())
 {
     $this->_layerFactory = $layerFactory;
     $this->_productCollectionFactory = $productCollectionFactory;
     parent::__construct($context, $postDataHelper, $categoryFactory, $catalogLayer, $data);
 }
 public function testScope()
 {
     $this->assertFalse($this->block->isScopePrivate());
 }