| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126 | 
							- <?php
 
- /**
 
-  * Copyright © Magento, Inc. All rights reserved.
 
-  * See COPYING.txt for license details.
 
-  */
 
- namespace Magento\Framework\Search\Test\Unit\Request;
 
- use Magento\Framework\Search\Request\FilterInterface;
 
- use Magento\Framework\Search\Request\QueryInterface;
 
- use Magento\Framework\Search\Request\Query\Filter;
 
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
 
- /**
 
-  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 
-  */
 
- class MapperTest extends \PHPUnit\Framework\TestCase
 
- {
 
-     const ROOT_QUERY = 'someQuery';
 
-     /**
 
-      * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
 
-      */
 
-     private $helper;
 
-     /**
 
-      * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $objectManager;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Query\Match|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $queryMatch;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Query\BoolExpression|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $queryBool;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Query\Filter|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $queryFilter;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Filter\Term|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $filterTerm;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Filter\Wildcard|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $filterWildcard;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Filter\Range|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $filterRange;
 
-     /**
 
-      * @var \Magento\Framework\Search\Request\Filter\Bool|\PHPUnit_Framework_MockObject_MockObject
 
-      */
 
-     private $filterBool;
 
-     protected function setUp()
 
-     {
 
-         $this->helper = new ObjectManager($this);
 
-         $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
 
-         $this->queryMatch = $this->getMockBuilder(\Magento\Framework\Search\Request\Query\Match::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->queryBool = $this->getMockBuilder(\Magento\Framework\Search\Request\Query\BoolExpression::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->queryFilter = $this->getMockBuilder(\Magento\Framework\Search\Request\Query\Filter::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->filterTerm = $this->getMockBuilder(\Magento\Framework\Search\Request\Filter\Term::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->filterRange = $this->getMockBuilder(\Magento\Framework\Search\Request\Filter\Range::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->filterBool = $this->getMockBuilder(\Magento\Framework\Search\Request\Filter\BoolExpression::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-         $this->filterWildcard = $this->getMockBuilder(\Magento\Framework\Search\Request\Filter\Wildcard::class)
 
-             ->disableOriginalConstructor()
 
-             ->getMock();
 
-     }
 
-     /**
 
-      * @param $queries
 
-      * @dataProvider getQueryMatchProvider
 
-      */
 
-     public function testGetQueryMatch($queries)
 
-     {
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->once())->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Match::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'value' => $query['value'],
 
-                         'boost' => isset($query['boost']) ? $query['boost'] : 1,
 
-                         'matches' => $query['match'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryMatch));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryMatch, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Magento\Framework\Exception\StateException
 
-      */
 
-     public function testGetQueryNotUsedStateException()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_MATCH,
 
-                 'name' => 'someName',
 
-                 'value' => 'someValue',
 
-                 'boost' => 3,
 
-                 'match' => 'someMatches',
 
-             ],
 
-             'notUsedQuery' => [
 
-                 'type' => QueryInterface::TYPE_MATCH,
 
-                 'name' => 'someName',
 
-                 'value' => 'someValue',
 
-                 'boost' => 3,
 
-                 'match' => 'someMatches',
 
-             ],
 
-         ];
 
-         $query = $queries['someQuery'];
 
-         $this->objectManager->expects($this->once())->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Match::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'value' => $query['value'],
 
-                         'boost' => isset($query['boost']) ? $query['boost'] : 1,
 
-                         'matches' => $query['match'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryMatch));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryMatch, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Magento\Framework\Exception\StateException
 
-      */
 
-     public function testGetQueryUsedStateException()
 
-     {
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_BOOL,
 
-                         'name' => 'someName',
 
-                         'queryReference' => [
 
-                             [
 
-                                 'clause' => 'someClause',
 
-                                 'ref' => 'someQuery',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                 ],
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryMatch, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @param $queries
 
-      * @dataProvider getQueryFilterQueryReferenceProvider
 
-      */
 
-     public function testGetQueryFilterQueryReference($queries)
 
-     {
 
-         $query = $queries['someQueryMatch'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Match::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'value' => $query['value'],
 
-                         'boost' => 1,
 
-                         'matches' => 'someMatches',
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryMatch));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => isset($query['boost']) ? $query['boost'] : 1,
 
-                         'reference' => $this->queryMatch,
 
-                         'referenceType' => Filter::REFERENCE_QUERY,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Exception
 
-      * @expectedExceptionMessage Reference is not provided
 
-      */
 
-     public function testGetQueryFilterReferenceException()
 
-     {
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => [
 
-                     'someQuery' => [
 
-                         'type' => QueryInterface::TYPE_FILTER,
 
-                     ],
 
-                 ],
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $mapper->getRootQuery();
 
-     }
 
-     /**
 
-      * @param $queries
 
-      * @dataProvider getQueryBoolProvider
 
-      */
 
-     public function testGetQueryBool($queries)
 
-     {
 
-         $query = $queries['someQueryMatch'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Match::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'value' => $query['value'],
 
-                         'boost' => 1,
 
-                         'matches' => 'someMatches',
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryMatch));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\BoolExpression::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => isset($query['boost']) ? $query['boost'] : 1,
 
-                         'someClause' => ['someQueryMatch' => $this->queryMatch],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryBool));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryBool, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * #@expectedException \InvalidArgumentException
 
-      */
 
-     public function testGetQueryInvalidArgumentException()
 
-     {
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => 'invalid_type',
 
-                     ],
 
-                 ],
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $mapper->getRootQuery();
 
-     }
 
-     /**
 
-      * @expectedException \Exception
 
-      */
 
-     public function testGetQueryException()
 
-     {
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => [],
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $mapper->getRootQuery();
 
-     }
 
-     public function testGetFilterTerm()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => FilterInterface::TYPE_TERM,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'value' => 'someValue',
 
-             ],
 
-         ];
 
-         $filter = $filters['someFilter'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\Term::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'field' => $filter['field'],
 
-                         'value' => $filter['value'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterTerm));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => 1,
 
-                         'reference' => $this->filterTerm,
 
-                         'referenceType' => Filter::REFERENCE_FILTER,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     public function testGetFilterWildcard()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => FilterInterface::TYPE_WILDCARD,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'value' => 'someValue',
 
-             ],
 
-         ];
 
-         $filter = $filters['someFilter'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\Wildcard::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'field' => $filter['field'],
 
-                         'value' => $filter['value'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterTerm));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => 1,
 
-                         'reference' => $this->filterTerm,
 
-                         'referenceType' => Filter::REFERENCE_FILTER,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     public function testGetFilterRange()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => FilterInterface::TYPE_RANGE,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'from' => 'from',
 
-                 'to' => 'to',
 
-             ],
 
-         ];
 
-         $filter = $filters['someFilter'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\Range::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'field' => $filter['field'],
 
-                         'from' => $filter['from'],
 
-                         'to' => $filter['to'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterRange));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => 1,
 
-                         'reference' => $this->filterRange,
 
-                         'referenceType' => Filter::REFERENCE_FILTER,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     public function testGetFilterBool()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => FilterInterface::TYPE_BOOL,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilterTerm',
 
-                         'clause' => 'someClause',
 
-                     ],
 
-                 ],
 
-             ],
 
-             'someFilterTerm' => [
 
-                 'type' => FilterInterface::TYPE_TERM,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'value' => 'someValue',
 
-             ],
 
-         ];
 
-         $filter = $filters['someFilterTerm'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\Term::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'field' => $filter['field'],
 
-                         'value' => $filter['value'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterTerm));
 
-         $filter = $filters['someFilter'];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\BoolExpression::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'someClause' => ['someFilterTerm' => $this->filterTerm],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterBool));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(2))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => 1,
 
-                         'reference' => $this->filterBool,
 
-                         'referenceType' => Filter::REFERENCE_FILTER,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Magento\Framework\Exception\StateException
 
-      */
 
-     public function testGetFilterNotUsedStateException()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => FilterInterface::TYPE_TERM,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'value' => 'someValue',
 
-             ],
 
-             'notUsedFilter' => [
 
-                 'type' => FilterInterface::TYPE_TERM,
 
-                 'name' => 'someName',
 
-                 'field' => 'someField',
 
-                 'value' => 'someValue',
 
-             ],
 
-         ];
 
-         $filter = $filters['someFilter'];
 
-         $this->objectManager->expects($this->at(0))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Filter\Term::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $filter['name'],
 
-                         'field' => $filter['field'],
 
-                         'value' => $filter['value'],
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->filterTerm));
 
-         $query = $queries[self::ROOT_QUERY];
 
-         $this->objectManager->expects($this->at(1))->method('create')
 
-             ->with(
 
-                 $this->equalTo(\Magento\Framework\Search\Request\Query\Filter::class),
 
-                 $this->equalTo(
 
-                     [
 
-                         'name' => $query['name'],
 
-                         'boost' => 1,
 
-                         'reference' => $this->filterTerm,
 
-                         'referenceType' => Filter::REFERENCE_FILTER,
 
-                     ]
 
-                 )
 
-             )
 
-             ->will($this->returnValue($this->queryFilter));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Magento\Framework\Exception\StateException
 
-      */
 
-     public function testGetFilterUsedStateException()
 
-     {
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_FILTER,
 
-                         'name' => 'someName',
 
-                         'filterReference' => [
 
-                             [
 
-                                 'ref' => 'someFilter',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                 ],
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'filters' => [
 
-                     'someFilter' => [
 
-                         'type' => FilterInterface::TYPE_BOOL,
 
-                         'name' => 'someName',
 
-                         'filterReference' => [
 
-                             [
 
-                                 'ref' => 'someFilter',
 
-                                 'clause' => 'someClause',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                 ],
 
-                 'aggregation' => [],
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryMatch, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \InvalidArgumentException
 
-      * @expectedExceptionMessage Invalid filter type
 
-      */
 
-     public function testGetFilterInvalidArgumentException()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someFilter',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         $filters = [
 
-             'someFilter' => [
 
-                 'type' => 'invalid_type',
 
-             ],
 
-         ];
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [],
 
-                 'filters' => $filters
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryFilter, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @expectedException \Exception
 
-      */
 
-     public function testGetFilterException()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_FILTER,
 
-                 'name' => 'someName',
 
-                 'boost' => 3,
 
-                 'filterReference' => [
 
-                     [
 
-                         'ref' => 'someQueryMatch',
 
-                         'clause' => 'someClause',
 
-                     ],
 
-                 ],
 
-             ],
 
-         ];
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'filters' => []
 
-             ]
 
-         );
 
-         $this->assertEquals($this->queryBool, $mapper->getRootQuery());
 
-     }
 
-     /**
 
-      * @return array
 
-      */
 
-     public function getQueryMatchProvider()
 
-     {
 
-         return [
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'name' => 'someName',
 
-                         'value' => 'someValue',
 
-                         'boost' => 3,
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ],
 
-             ],
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'name' => 'someName',
 
-                         'value' => 'someValue',
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ]
 
-             ]
 
-         ];
 
-     }
 
-     /**
 
-      * @return array
 
-      */
 
-     public function getQueryFilterQueryReferenceProvider()
 
-     {
 
-         return [
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_FILTER,
 
-                         'name' => 'someName',
 
-                         'boost' => 3,
 
-                         'queryReference' => [
 
-                             [
 
-                                 'ref' => 'someQueryMatch',
 
-                                 'clause' => 'someClause',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                     'someQueryMatch' => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'value' => 'someValue',
 
-                         'name' => 'someName',
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ],
 
-             ],
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_FILTER,
 
-                         'name' => 'someName',
 
-                         'queryReference' => [
 
-                             [
 
-                                 'ref' => 'someQueryMatch',
 
-                                 'clause' => 'someClause',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                     'someQueryMatch' => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'value' => 'someValue',
 
-                         'name' => 'someName',
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ]
 
-             ]
 
-         ];
 
-     }
 
-     /**
 
-      * @return array
 
-      */
 
-     public function getQueryBoolProvider()
 
-     {
 
-         return [
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_BOOL,
 
-                         'name' => 'someName',
 
-                         'boost' => 3,
 
-                         'queryReference' => [
 
-                             [
 
-                                 'ref' => 'someQueryMatch',
 
-                                 'clause' => 'someClause',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                     'someQueryMatch' => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'value' => 'someValue',
 
-                         'name' => 'someName',
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ],
 
-             ],
 
-             [
 
-                 [
 
-                     self::ROOT_QUERY => [
 
-                         'type' => QueryInterface::TYPE_BOOL,
 
-                         'name' => 'someName',
 
-                         'queryReference' => [
 
-                             [
 
-                                 'ref' => 'someQueryMatch',
 
-                                 'clause' => 'someClause',
 
-                             ],
 
-                         ],
 
-                     ],
 
-                     'someQueryMatch' => [
 
-                         'type' => QueryInterface::TYPE_MATCH,
 
-                         'value' => 'someValue',
 
-                         'name' => 'someName',
 
-                         'match' => 'someMatches',
 
-                     ],
 
-                 ]
 
-             ]
 
-         ];
 
-     }
 
-     public function testGetBucketsTermBucket()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_MATCH,
 
-                 'value' => 'someValue',
 
-                 'name' => 'someName',
 
-                 'match' => 'someMatches',
 
-             ],
 
-         ];
 
-         $bucket = [
 
-             "name" => "category_bucket",
 
-             "field" => "category",
 
-             "metric" => [
 
-                 ["type" => "sum"],
 
-                 ["type" => "count"],
 
-                 ["type" => "min"],
 
-                 ["type" => "max"],
 
-             ],
 
-             "type" => "termBucket",
 
-         ];
 
-         $metricClass = \Magento\Framework\Search\Request\Aggregation\Metric::class;
 
-         $bucketClass = \Magento\Framework\Search\Request\Aggregation\TermBucket::class;
 
-         $queryClass = \Magento\Framework\Search\Request\Query\Match::class;
 
-         $queryArguments = [
 
-             'name' => $queries[self::ROOT_QUERY]['name'],
 
-             'value' => $queries[self::ROOT_QUERY]['value'],
 
-             'boost' => 1,
 
-             'matches' => $queries[self::ROOT_QUERY]['match'],
 
-         ];
 
-         $arguments = [
 
-             'name' => $bucket['name'],
 
-             'field' => $bucket['field'],
 
-             'metrics' => [null, null, null, null],
 
-         ];
 
-         $this->objectManager->expects($this->any())->method('create')
 
-             ->withConsecutive(
 
-                 [$this->equalTo($queryClass), $this->equalTo($queryArguments)],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][0]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][1]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][2]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][3]['type']])],
 
-                 [$this->equalTo($bucketClass), $this->equalTo($arguments)]
 
-             )
 
-             ->will($this->returnValue(null));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [$bucket]
 
-             ]
 
-         );
 
-         $mapper->getBuckets();
 
-     }
 
-     public function testGetBucketsRangeBucket()
 
-     {
 
-         $queries = [
 
-             self::ROOT_QUERY => [
 
-                 'type' => QueryInterface::TYPE_MATCH,
 
-                 'value' => 'someValue',
 
-                 'name' => 'someName',
 
-                 'match' => 'someMatches',
 
-             ],
 
-         ];
 
-         $bucket = [
 
-             "name" => "price_bucket",
 
-             "field" => "price",
 
-             "metric" => [
 
-                 ["type" => "sum"],
 
-                 ["type" => "count"],
 
-                 ["type" => "min"],
 
-                 ["type" => "max"],
 
-             ],
 
-             "range" => [
 
-                 ["from" => "", "to" => "50"],
 
-                 ["from" => "50", "to" => "100"],
 
-                 ["from" => "100", "to" => ""],
 
-             ],
 
-             "type" => "rangeBucket",
 
-         ];
 
-         $metricClass = \Magento\Framework\Search\Request\Aggregation\Metric::class;
 
-         $bucketClass = \Magento\Framework\Search\Request\Aggregation\RangeBucket::class;
 
-         $rangeClass = \Magento\Framework\Search\Request\Aggregation\Range::class;
 
-         $queryClass = \Magento\Framework\Search\Request\Query\Match::class;
 
-         $queryArguments = [
 
-             'name' => $queries[self::ROOT_QUERY]['name'],
 
-             'value' => $queries[self::ROOT_QUERY]['value'],
 
-             'boost' => 1,
 
-             'matches' => $queries[self::ROOT_QUERY]['match'],
 
-         ];
 
-         $arguments = [
 
-             'name' => $bucket['name'],
 
-             'field' => $bucket['field'],
 
-             'metrics' => [null, null, null, null],
 
-             'ranges' => [null, null, null],
 
-         ];
 
-         $this->objectManager->expects($this->any())->method('create')
 
-             ->withConsecutive(
 
-                 [$this->equalTo($queryClass), $this->equalTo($queryArguments)],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][0]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][1]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][2]['type']])],
 
-                 [$this->equalTo($metricClass), $this->equalTo(['type' => $bucket['metric'][3]['type']])],
 
-                 [
 
-                     $this->equalTo($rangeClass),
 
-                     $this->equalTo(['from' => $bucket['range'][0]['from'], 'to' => $bucket['range'][0]['to']])
 
-                 ],
 
-                 [
 
-                     $this->equalTo($rangeClass),
 
-                     $this->equalTo(['from' => $bucket['range'][1]['from'], 'to' => $bucket['range'][1]['to']])
 
-                 ],
 
-                 [
 
-                     $this->equalTo($rangeClass),
 
-                     $this->equalTo(['from' => $bucket['range'][2]['from'], 'to' => $bucket['range'][2]['to']])
 
-                 ],
 
-                 [
 
-                     $this->equalTo($bucketClass),
 
-                     $this->equalTo($arguments)
 
-                 ]
 
-             )
 
-             ->will($this->returnValue(null));
 
-         /** @var \Magento\Framework\Search\Request\Mapper $mapper */
 
-         $mapper = $this->helper->getObject(
 
-             \Magento\Framework\Search\Request\Mapper::class,
 
-             [
 
-                 'objectManager' => $this->objectManager,
 
-                 'queries' => $queries,
 
-                 'rootQueryName' => self::ROOT_QUERY,
 
-                 'aggregation' => [$bucket]
 
-             ]
 
-         );
 
-         $mapper->getBuckets();
 
-     }
 
- }
 
 
  |