public function testApply() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $request = $objectManager->get('Magento\\TestFramework\\Request'); $request->setParam('cat', 3); $this->_model->apply($request, \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Framework\\View\\Element\\Text')); /** @var $category \Magento\Catalog\Model\Category */ $category = $objectManager->get('Magento\\Framework\\Registry')->registry('current_category_filter'); $this->assertInstanceOf('Magento\\Catalog\\Model\\Category', $category); $this->assertEquals(3, $category->getId()); return $this->_model; }
public function testApply() { $categoryId = 123; $requestVar = 'test_request_var'; $this->target->setRequestVar($requestVar); $this->request->expects($this->any())->method('getParam')->will($this->returnCallback(function ($field) use($requestVar, $categoryId) { $this->assertTrue(in_array($field, [$requestVar, 'id'])); return $categoryId; })); $this->dataProvider->expects($this->once())->method('setCategoryId')->with($categoryId)->will($this->returnSelf()); $this->category->expects($this->once())->method('getId')->will($this->returnValue($categoryId)); $this->collection->expects($this->once())->method('addCategoryFilter')->with($this->category)->will($this->returnSelf()); $this->target->apply($this->request); }