Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function build(RequestFilterInterface $filter)
 {
     switch ($filter->getType()) {
         case RequestFilterInterface::TYPE_BOOL:
             /** @var \Magento\Framework\Search\Request\Filter\Bool $filter */
             $queries = [];
             $must = $this->buildFilters($filter->getMust(), Select::SQL_AND);
             if (!empty($must)) {
                 $queries[] = $must;
             }
             $should = $this->buildFilters($filter->getShould(), Select::SQL_OR);
             if (!empty($should)) {
                 $queries[] = $this->wrapBrackets($should);
             }
             $mustNot = $this->buildFilters($filter->getMustNot(), Select::SQL_AND);
             if (!empty($mustNot)) {
                 $queries[] = '!' . $this->wrapBrackets($mustNot);
             }
             $query = $this->generateQuery($queries, Select::SQL_AND);
             break;
         case RequestFilterInterface::TYPE_TERM:
             /** @var \Magento\Framework\Search\Request\Filter\Term $filter */
             $query = $this->term->buildFilter($filter);
             break;
         case RequestFilterInterface::TYPE_RANGE:
             /** @var \Magento\Framework\Search\Request\Filter\Range $filter */
             $query = $this->range->buildFilter($filter);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unknown filter type \'%s\'', $filter->getType()));
     }
     return $this->wrapBrackets($query);
 }
Exemple #2
0
 /**
  * @param string $field
  * @param string $from
  * @param string $to
  * @param bool $isNegation
  * @param string $expectedResult
  * @dataProvider buildQueryDataProvider
  */
 public function testBuildQuery($field, $from, $to, $isNegation, $expectedResult)
 {
     $this->requestFilter->expects($this->any())->method('getField')->will($this->returnValue($field));
     $this->requestFilter->expects($this->atLeastOnce())->method('getFrom')->will($this->returnValue($from));
     $this->requestFilter->expects($this->atLeastOnce())->method('getTo')->will($this->returnValue($to));
     $actualResult = $this->filter->buildFilter($this->requestFilter, $isNegation);
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @param string $field
  * @param string $from
  * @param string $to
  * @param string $expectedResult
  * @dataProvider buildQueryDataProvider
  */
 public function testBuildQuery($field, $from, $to, $expectedResult)
 {
     $this->requestFilter->expects($this->once())->method('getField')->will($this->returnValue($field));
     $this->requestFilter->expects($this->once())->method('getFrom')->will($this->returnValue($from));
     $this->requestFilter->expects($this->once())->method('getTo')->will($this->returnValue($to));
     $this->adapter->expects($this->any())->method('quote')->will($this->returnCallback(function ($value) {
         return '\'' . $value . '\'';
     }));
     $actualResult = $this->filter->buildFilter($this->requestFilter);
     $this->assertEquals($expectedResult, $actualResult);
 }