/** * @covers \Magento\Backend\Helper\Data::prepareFilterString */ public function testPrepareFilterString() { $expected = ['key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3']; $filterString = base64_encode('key1=' . rawurlencode('val1') . '&key2=' . rawurlencode('val2') . '&key3=val3'); $actual = $this->_helper->prepareFilterString($filterString); $this->assertEquals($expected, $actual); }
/** * Apply sorting and filtering to collection * * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _prepareCollection() { if ($this->getCollection()) { $this->_preparePage(); $columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort); $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir); $filter = $this->getParam($this->getVarNameFilter(), null); if (is_null($filter)) { $filter = $this->_defaultFilter; } if (is_string($filter)) { $data = $this->_backendHelper->prepareFilterString($filter); $data = array_merge($data, (array) $this->getRequest()->getPost($this->getVarNameFilter())); $this->_setFilterValues($data); } elseif ($filter && is_array($filter)) { $this->_setFilterValues($filter); } elseif (0 !== sizeof($this->_defaultFilter)) { $this->_setFilterValues($this->_defaultFilter); } if ($this->getColumn($columnId) && $this->getColumn($columnId)->getIndex()) { $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; $this->getColumn($columnId)->setDir($dir); $this->_setCollectionOrder($this->getColumn($columnId)); } } return $this; }
/** * @param array $inputString * @param array $expected * * @dataProvider getPrepareFilterStringValuesDataProvider */ public function testPrepareFilterStringValues(array $inputString, array $expected) { $inputString = base64_encode(http_build_query($inputString)); $actual = $this->_helper->prepareFilterString($inputString); $this->assertEquals($expected, $actual); }