Пример #1
0
 /**
  * Test for method "build"
  */
 public function testBind()
 {
     $requestData = ['dimensions' => ['scope' => ['value' => '$sss$']], 'queries' => ['query' => ['value' => '$query$'], 'empty_query' => ['value' => '$empty_query$'], 'space_query' => ['value' => '$space_query$'], 'zero_value_query' => ['name' => 'zero_value', 'type' => 'filteredQuery']], 'filters' => ['filter' => ['from' => '$from$', 'to' => '$to$', 'value' => '$filter$'], 'zero_value_filter' => ['type' => 'termFilter', 'name' => 'zero_value', 'field' => 'zero_value', 'value' => '$zero_value$']], 'aggregations' => ['price' => ['method' => '$method$']], 'from' => 0, 'size' => 15];
     $bindData = ['dimensions' => ['scope' => 'default'], 'placeholder' => ['$query$' => 'match_query', '$empty_query$' => '  ', '$space_query$' => '  value', '$from$' => 'filter_from', '$to$' => 'filter_to', '$filter$' => 'filter_value', '$method$' => 'filter_method', '$zero_value$' => '0'], 'from' => 1, 'size' => 10];
     $expectedResult = ['dimensions' => ['scope' => ['value' => 'default']], 'queries' => ['query' => ['value' => 'match_query', 'is_bind' => true], 'empty_query' => ['value' => '$empty_query$'], 'space_query' => ['value' => 'value', 'is_bind' => true], 'zero_value_query' => ['name' => 'zero_value', 'type' => 'filteredQuery']], 'filters' => ['filter' => ['from' => 'filter_from', 'to' => 'filter_to', 'value' => 'filter_value', 'is_bind' => true], 'zero_value_filter' => ['type' => 'termFilter', 'name' => 'zero_value', 'field' => 'zero_value', 'value' => '0', 'is_bind' => true]], 'aggregations' => ['price' => ['method' => 'filter_method', 'is_bind' => true]], 'from' => 1, 'size' => 10];
     $result = $this->binder->bind($requestData, $bindData);
     $this->assertEquals($expectedResult, $result);
 }
Пример #2
0
 /**
  * Test for method "build"
  */
 public function testBind()
 {
     $requestData = ['dimensions' => ['scope' => ['value' => '$sss$']], 'queries' => ['query' => ['value' => '$query$']], 'filters' => ['filter' => ['from' => '$from$', 'to' => '$to$', 'value' => '$filter$']], 'aggregations' => ['price' => ['method' => '$method$']], 'from' => 0, 'size' => 15];
     $bindData = ['dimensions' => ['scope' => 'default'], 'placeholder' => ['$query$' => 'match_query', '$from$' => 'filter_from', '$to$' => 'filter_to', '$filter$' => 'filter_value', '$method$' => 'filter_method'], 'from' => 1, 'size' => 10];
     $expectedResult = ['dimensions' => ['scope' => ['value' => 'default']], 'queries' => ['query' => ['value' => 'match_query']], 'filters' => ['filter' => ['from' => 'filter_from', 'to' => 'filter_to', 'value' => 'filter_value']], 'aggregations' => ['price' => ['method' => 'filter_method']], 'from' => 1, 'size' => 10];
     $result = $this->binder->bind($requestData, $bindData);
     $this->assertEquals($result, $expectedResult);
 }
Пример #3
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreate()
 {
     $data = ['dimensions' => ['scope' => ['name' => 'scope', 'value' => 'default']], 'queries' => ['one_match_filters' => ['name' => 'one_match_filters', 'boost' => '2', 'queryReference' => [['clause' => 'must', 'ref' => 'fulltext_search_query'], ['clause' => 'must', 'ref' => 'fulltext_search_query2']], 'type' => 'boolQuery'], 'fulltext_search_query' => ['name' => 'fulltext_search_query', 'boost' => '5', 'value' => '$fulltext_search_query$', 'match' => [['field' => 'data_index', 'boost' => '2']], 'type' => 'matchQuery'], 'fulltext_search_query2' => ['name' => 'fulltext_search_query2', 'filterReference' => [['ref' => 'pid']], 'type' => 'filteredQuery']], 'filters' => ['pid' => ['name' => 'pid', 'filterReference' => [['clause' => 'should', 'ref' => 'pidm'], ['clause' => 'should', 'ref' => 'pidsh']], 'type' => 'boolFilter'], 'pidm' => ['name' => 'pidm', 'field' => 'product_id', 'type' => 'rangeFilter', 'from' => '$pidm_from$', 'to' => '$pidm_to$'], 'pidsh' => ['name' => 'pidsh', 'field' => 'product_id', 'type' => 'termFilter', 'value' => '$pidsh$']], 'from' => '10', 'size' => '10', 'query' => 'one_match_filters', 'index' => 'catalogsearch_fulltext', 'aggregations' => []];
     $requestName = 'rn';
     $this->requestBuilder->bind('fulltext_search_query', 'socks');
     $this->requestBuilder->bind('pidsh', 4);
     $this->requestBuilder->bind('pidm_from', 1);
     $this->requestBuilder->bind('pidm_to', 3);
     $this->requestBuilder->setRequestName($requestName);
     $this->requestBuilder->setSize(10);
     $this->requestBuilder->setFrom(10);
     $this->requestBuilder->bindDimension('scope', 'default');
     $this->binder->expects($this->once())->method('bind')->willReturn($data);
     $this->cleaner->expects($this->once())->method('clean')->willReturn($data);
     $this->requestMapper->expects($this->once())->method('getRootQuery')->willReturn([]);
     $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->requestMapper);
     $this->objectManager->expects($this->at(2))->method('create')->willReturn($this->request);
     $this->config->expects($this->once())->method('get')->with($this->equalTo($requestName))->willReturn($data);
     $result = $this->requestBuilder->create();
     $this->assertInstanceOf('\\Magento\\Framework\\Search\\Request', $result);
 }
Пример #4
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreate()
 {
     $data = ['dimensions' => ['scope' => ['name' => 'scope', 'value' => 'default']], 'queries' => ['filter_search_query' => ['name' => 'filter_search_query', 'filterReference' => [['ref' => 'boolFilter']], 'type' => 'filteredQuery']], 'filters' => ['boolFilter' => ['name' => 'boolFilter', 'filterReference' => [['clause' => 'should', 'ref' => 'from_to'], ['clause' => 'should', 'ref' => 'not_array'], ['clause' => 'should', 'ref' => 'like']], 'type' => 'boolFilter'], 'from_to' => ['name' => 'from_to', 'field' => 'product_id', 'type' => 'rangeFilter', 'from' => '$from_to.from$', 'to' => '$from_to.to$'], 'not_array' => ['name' => 'not_array', 'field' => 'product_id', 'type' => 'termFilter', 'value' => '$not_array$'], 'like' => ['name' => 'like', 'field' => 'product_id', 'type' => 'wildcardFilter', 'value' => '$like$'], 'in' => ['name' => 'in', 'field' => 'product_id', 'type' => 'termFilter', 'value' => '$in$'], 'in_set' => ['name' => 'in_set', 'field' => 'product_id', 'type' => 'termFilter', 'value' => '$in_set$']], 'from' => '10', 'size' => '10', 'query' => 'one_match_filters', 'index' => 'catalogsearch_fulltext', 'aggregations' => []];
     $requestName = 'rn';
     $bindData = ['dimensions' => ['scope' => 'default'], 'placeholder' => ['$from_to.from$' => 10, '$from_to.to$' => 20, '$not_array$' => 130, '$like$' => 'search_text', '$in$' => 23, '$in_set$' => [12, 23, 34, 45]], 'requestName' => $requestName, 'from' => 10, 'size' => 10];
     $this->requestBuilder->bindRequestValue('from_to', ['from' => 10, 'to' => 20]);
     $this->requestBuilder->bindRequestValue('not_array', 130);
     $this->requestBuilder->bindRequestValue('like', ['like' => '%search_text%']);
     $this->requestBuilder->bindRequestValue('in', ['in' => 23]);
     $this->requestBuilder->bindRequestValue('in_set', ['in_set' => [12, 23, 34, 45]]);
     $this->requestBuilder->setRequestName($requestName);
     $this->requestBuilder->setSize(10);
     $this->requestBuilder->setFrom(10);
     $this->requestBuilder->bindDimension('scope', 'default');
     $this->binder->expects($this->once())->method('bind')->withConsecutive([$data, $bindData])->willReturn($data);
     $this->cleaner->expects($this->once())->method('clean')->willReturn($data);
     $this->requestMapper->expects($this->once())->method('getRootQuery')->willReturn([]);
     $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->requestMapper);
     $this->objectManager->expects($this->at(2))->method('create')->willReturn($this->request);
     $this->config->expects($this->once())->method('get')->with($this->equalTo($requestName))->willReturn($data);
     $result = $this->requestBuilder->create();
     $this->assertInstanceOf('\\Magento\\Framework\\Search\\Request', $result);
 }
Пример #5
0
 /**
  * Create request object
  *
  * @return RequestInterface
  */
 public function create()
 {
     if (!isset($this->data['requestName'])) {
         throw new \InvalidArgumentException("Request name not defined.");
     }
     $requestName = $this->data['requestName'];
     /** @var array $data */
     $data = $this->config->get($requestName);
     if ($data === null) {
         throw new \InvalidArgumentException("Request name '{$requestName}' doesn't exist.");
     }
     $data = $this->binder->bind($data, $this->data);
     $data = $this->cleaner->clean($data);
     $this->clear();
     return $this->convert($data);
 }