Exemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     /** @var \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory */
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     /** @var \Magento\Framework\Store\StoreManagerInterface $storeManager */
     $this->storeManager = $this->getMockBuilder('\\Magento\\Framework\\Store\\StoreManagerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     /** @var \Magento\Catalog\Model\Layer $layer */
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState'])->getMock();
     /** @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder */
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterAttribute = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\Attribute')->disableOriginalConstructor()->setMethods(['getCount', 'applyFilterToCollection'])->getMock();
     $this->filterAttribute->expects($this->any())->method('applyFilterToCollection')->will($this->returnSelf());
     $this->filterAttributeFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\AttributeFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->filterAttributeFactory->expects($this->once())->method('create')->will($this->returnValue($this->filterAttribute));
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->frontend = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->setMethods(['getOption', 'getSelectOptions'])->getMock();
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->attribute->expects($this->atLeastOnce())->method('getFrontend')->will($this->returnValue($this->frontend));
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     $stripTagsFilter = $this->getMockBuilder('\\Magento\\Framework\\Filter\\StripTags')->disableOriginalConstructor()->setMethods(['filter'])->getMock();
     $stripTagsFilter->expects($this->any())->method('filter')->will($this->returnArgument(0));
     $string = $this->getMockBuilder('\\Magento\\Framework\\Stdlib\\String')->disableOriginalConstructor()->setMethods(['strlen'])->getMock();
     $string->expects($this->any())->method('strlen')->will($this->returnCallback(function ($value) {
         return strlen($value);
     }));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\Attribute', ['filterItemFactory' => $this->filterItemFactory, 'storeManager' => $this->storeManager, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterAttributeFactory' => $this->filterAttributeFactory, 'tagFilter' => $stripTagsFilter, 'string' => $string]);
 }
Exemplo n.º 2
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $dataProviderFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\PriceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->dataProvider = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Price')->disableOriginalConstructor()->setMethods(['setPriceId', 'getPrice', 'getResource'])->getMock();
     $this->resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\Price')->disableOriginalConstructor()->setMethods(['applyPriceRange'])->getMock();
     $this->dataProvider->expects($this->any())->method('getResource')->will($this->returnValue($this->resource));
     $dataProviderFactory->expects($this->once())->method('create')->will($this->returnValue($this->dataProvider));
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($filterItem));
     $escaper = $this->getMockBuilder('\\Magento\\Framework\\Escaper')->disableOriginalConstructor()->setMethods(['escapeHtml'])->getMock();
     $escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $algorithmFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\AlgorithmFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->algorithm = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\Auto')->disableOriginalConstructor()->setMethods(['getItemsData'])->getMock();
     $algorithmFactory->expects($this->any())->method('create')->will($this->returnValue($this->algorithm));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\Price', ['dataProviderFactory' => $dataProviderFactory, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterItemFactory' => $this->filterItemFactory, 'escaper' => $escaper, 'algorithmFactory' => $algorithmFactory]);
 }
Exemplo n.º 3
0
 protected function setUp()
 {
     $this->productCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->setMethods(['getMaxPrice'])->getMock();
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getProductCollection'])->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->productCollection));
     $this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock();
     $this->scopeConfig = $this->getMockBuilder('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
     $this->resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\Price')->disableOriginalConstructor()->setMethods(['getCount'])->getMock();
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Price', ['layer' => $this->layer, 'coreRegistry' => $this->coreRegistry, 'scopeConfig' => $this->scopeConfig, 'resource' => $this->resource]);
 }
Exemplo n.º 4
0
 public function testGetCategoryWithAppliedId()
 {
     $storeId = 1234;
     $categoryId = 4321;
     $this->store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->layer->expects($this->any())->method('getCurrentCategory')->will($this->returnValue($this->category));
     $this->category->expects($this->once())->method('setStoreId')->with($this->equalTo($storeId))->will($this->returnSelf());
     $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId))->will($this->returnSelf());
     $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId));
     $this->category->expects($this->any())->method('getPathIds')->will($this->returnValue([20, 10]));
     $this->coreRegistry->expects($this->once())->method('register')->with($this->equalTo('current_category_filter'), $this->equalTo($this->category), $this->equalTo(true))->will($this->returnSelf());
     $this->target->setCategoryId($categoryId);
     $this->assertSame($this->category, $this->target->getCategory());
     $this->assertSame(20, $this->target->getResetValue());
     return $this->target;
 }
Exemplo n.º 5
0
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $this->filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($this->filterItem));
     $this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection')->disableOriginalConstructor()->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     $filterDecimalFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\DecimalFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\Decimal')->disableOriginalConstructor()->setMethods([])->getMock();
     $filterDecimalFactory->expects($this->once())->method('create')->will($this->returnValue($resource));
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Decimal', ['filterItemFactory' => $this->filterItemFactory, 'layer' => $this->layer, 'filterDecimalFactory' => $filterDecimalFactory]);
     $this->target->setAttributeModel($this->attribute);
 }
Exemplo n.º 6
0
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $dataProviderFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\CategoryFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->dataProvider = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Category')->disableOriginalConstructor()->setMethods(['setCategoryId', 'getCategory'])->getMock();
     $dataProviderFactory->expects($this->once())->method('create')->will($this->returnValue($this->dataProvider));
     $this->category = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getChildrenCategories', 'getIsActive'])->getMock();
     $this->dataProvider->expects($this->any())->method('getCategory', 'isValid')->will($this->returnValue($this->category));
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Collection')->disableOriginalConstructor()->setMethods(['addCategoryFilter', 'getFacetedData', 'getSize'])->getMock();
     $this->layer->expects($this->any())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($filterItem));
     $escaper = $this->getMockBuilder('\\Magento\\Framework\\Escaper')->disableOriginalConstructor()->setMethods(['escapeHtml'])->getMock();
     $escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Category', ['categoryDataProviderFactory' => $dataProviderFactory, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterItemFactory' => $this->filterItemFactory, 'escaper' => $escaper]);
 }
Exemplo n.º 7
0
 protected function setUp()
 {
     /** @var \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory */
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     /** @var \Magento\Catalog\Model\Layer $layer */
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState', 'getProductCollection'])->getMock();
     $this->fulltextCollection = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\ResourceModel\\Fulltext\\Collection')->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'getFacetedData', 'getSize'])->getMock();
     $this->layer->expects($this->atLeastOnce())->method('getProductCollection')->will($this->returnValue($this->fulltextCollection));
     /** @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder */
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterAttributeFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Layer\\Filter\\AttributeFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->frontend = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->disableOriginalConstructor()->setMethods(['getOption', 'getSelectOptions'])->getMock();
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->setMethods(['getParam'])->getMockForAbstractClass();
     $stripTagsFilter = $this->getMockBuilder('\\Magento\\Framework\\Filter\\StripTags')->disableOriginalConstructor()->setMethods(['filter'])->getMock();
     $stripTagsFilter->expects($this->any())->method('filter')->will($this->returnArgument(0));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Attribute', ['filterItemFactory' => $this->filterItemFactory, 'storeManager' => $this->storeManager, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterAttributeFactory' => $this->filterAttributeFactory, 'tagFilter' => $stripTagsFilter]);
 }