Example #1
0
 public function testGetItems()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $request = $objectManager->get('Magento\\TestFramework\\Request');
     $request->setParam('cat', 3);
     $this->_model->apply($request);
     /** @var $category \Magento\Catalog\Model\Category */
     $category = $objectManager->get('Magento\\Framework\\Registry')->registry(self::CURRENT_CATEGORY_FILTER);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Category', $category);
     $this->assertEquals(3, $category->getId());
     $items = $this->_model->getItems();
     $this->assertInternalType('array', $items);
     $this->assertEquals(2, count($items));
     /** @var $item \Magento\Catalog\Model\Layer\Filter\Item */
     $item = $items[0];
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Layer\\Filter\\Item', $item);
     $this->assertSame($this->_model, $item->getFilter());
     $this->assertEquals('Category 1.1', $item->getLabel());
     $this->assertEquals(4, $item->getValue());
     $this->assertEquals(2, $item->getCount());
     $item = $items[1];
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Layer\\Filter\\Item', $item);
     $this->assertEquals('Category 1.2', $item->getLabel());
     $this->assertEquals(13, $item->getValue());
     $this->assertEquals(2, $item->getCount());
 }
Example #2
0
 public function testApply()
 {
     $categoryId = 123;
     $requestVar = 'test_request_var';
     $this->target->setRequestVar($requestVar);
     $this->request->expects($this->exactly(2))->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->fulltextCollection->expects($this->once())->method('addCategoryFilter')->with($this->category)->will($this->returnSelf());
     $this->target->apply($this->request);
 }