public function testSearch()
 {
     $requestName = 'requestName';
     $scope = 333;
     $filterField = 'filterField';
     $filterValue = 'filterValue';
     $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->disableOriginalConstructor()->getMock();
     $filter->expects($this->once())->method('getField')->willReturn($filterField);
     $filter->expects($this->once())->method('getValue')->willReturn($filterValue);
     $filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->disableOriginalConstructor()->getMock();
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchCriteriaInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $searchCriteria->expects($this->once())->method('getRequestName')->willReturn($requestName);
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $searchResult = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchResult')->disableOriginalConstructor()->getMockForAbstractClass();
     $request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $response = $this->getMockBuilder('Magento\\Framework\\Search\\ResponseInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->requestBuilder->expects($this->once())->method('setRequestName')->with($requestName);
     $this->requestBuilder->expects($this->once())->method('bindDimension')->with('scope', $scope);
     $this->requestBuilder->expects($this->any())->method('bind');
     $this->requestBuilder->expects($this->once())->method('create')->willReturn($request);
     $this->searchEngine->expects($this->once())->method('search')->with($request)->willReturn($response);
     $this->searchResponseBuilder->expects($this->once())->method('build')->with($response)->willReturn($searchResult);
     $this->scopeResolver->expects($this->once())->method('getScope')->willReturn($scope);
     $searchResult = $this->model->search($searchCriteria);
     $this->assertInstanceOf('Magento\\Framework\\Api\\Search\\SearchResultInterface', $searchResult);
 }
Beispiel #2
0
 public function testSearch()
 {
     $requestName = 'requestName';
     $scopeId = 333;
     $filters = [$this->createFilterMock('array_filter', ['arrayValue1', 'arrayValue2']), $this->createFilterMock('simple_filter', 'filterValue'), $this->createFilterMock('from_filter', ['from' => 30]), $this->createFilterMock('to_filter', ['to' => 100]), $this->createFilterMock('range_filter', ['from' => 60, 'to' => 82])];
     $scope = $this->getMockBuilder('Magento\\Framework\\App\\ScopeInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->disableOriginalConstructor()->getMock();
     $filterGroup->expects($this->once())->method('getFilters')->willReturn($filters);
     $searchCriteria = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchCriteriaInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $searchCriteria->expects($this->once())->method('getRequestName')->willReturn($requestName);
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $searchResult = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\SearchResult')->disableOriginalConstructor()->getMockForAbstractClass();
     $request = $this->getMockBuilder('Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $response = $this->getMockBuilder('Magento\\Framework\\Search\\ResponseInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->requestBuilder->expects($this->once())->method('setRequestName')->with($requestName);
     $this->requestBuilder->expects($this->once())->method('bindDimension')->with('scope', $scopeId);
     $this->requestBuilder->expects($this->exactly(6))->method('bind');
     $this->requestBuilder->expects($this->once())->method('create')->willReturn($request);
     $this->searchEngine->expects($this->once())->method('search')->with($request)->willReturn($response);
     $this->searchResponseBuilder->expects($this->once())->method('build')->with($response)->willReturn($searchResult);
     $this->scopeResolver->expects($this->once())->method('getScope')->willReturn($scope);
     $scope->expects($this->once())->method('getId')->willReturn($scopeId);
     $searchResult = $this->model->search($searchCriteria);
     $this->assertInstanceOf('Magento\\Framework\\Api\\Search\\SearchResultInterface', $searchResult);
 }