advancedSearchCheckerMock = $this->createMock(AdvancedSearchChecker::class); $this->identifierSearcher = $this->createMock(IdentifierSearcher::class); $this->defaultSearch = $this->createMock(SearchInterface::class); $this->advancedSearch = $this->createMock(SearchInterface::class); $this->searchQueryFactoryMock = $this->createMock(SearchQueryFactory::class); $this->resultSetResponseNormalizerMock = $this->createMock(ResultSetResponseNormalizer::class); $this->resultSetMock = $this->createMock(ResultSet::class); $this->requestMock = $this->createMock(ServerRequestInterface::class); $this->requestMock->method('getQueryParams')->willReturn( [ 'params' => [ 'query' => 'test', 'structure' => 'exampleRootNode', ], ] ); $this->subject = new SearchProxy( [ SearchProxy::OPTION_DEFAULT_SEARCH_CLASS => $this->defaultSearch, SearchProxy::OPTION_ADVANCED_SEARCH_CLASS => $this->advancedSearch, ] ); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ AdvancedSearchChecker::class => $this->advancedSearchCheckerMock, SearchQueryFactory::class => $this->searchQueryFactoryMock, ResultSetResponseNormalizer::class => $this->resultSetResponseNormalizerMock, IdentifierSearcher::class => $this->identifierSearcher ] ) ); } public function testSearchByIdentifier(): void { $this->identifierSearcher ->method('search') ->willReturn(new ResultSet([], 1)); $this->resultSetResponseNormalizerMock ->expects($this->once()) ->method('normalize') ->willReturn([]); $this->assertSame([], $this->subject->search($this->requestMock)); } public function testSearchByDefaultSearch(): void { $this->advancedSearchCheckerMock ->expects($this->once()) ->method('isEnabled') ->willReturn(false); $this->defaultSearch ->method('query') ->willReturn(new ResultSet([], 1)); $this->resultSetResponseNormalizerMock ->expects($this->once()) ->method('normalize') ->willReturn([]); $this->assertSame([], $this->subject->search($this->requestMock)); } public function testForceGenerisSearch(): void { $query = new SearchQuery( '', '', GenerisRdf::CLASS_ROLE, 0, 10, 0 ); $this->searchQueryFactoryMock ->method('create') ->willReturn($query); $this->defaultSearch ->method('query') ->willReturn($this->resultSetMock); $this->resultSetResponseNormalizerMock ->expects($this->once()) ->method('normalize') ->willReturn([]); $this->assertSame([], $this->subject->search($this->requestMock)); } public function testSearchWithAdvancedSearchAndNoPagination(): void { $this->requestMock ->method('getQueryParams') ->willReturn([]); $this->advancedSearchCheckerMock ->expects($this->once()) ->method('isEnabled') ->willReturn(true); $this->advancedSearch ->method('query') ->willReturn($this->resultSetMock); $this->resultSetResponseNormalizerMock ->expects($this->once()) ->method('normalize') ->willReturn([]); $this->assertSame([], $this->subject->search($this->requestMock)); } public function testSearchWithAdvancedSearchAndPagination(): void { $this->requestMock ->method('getQueryParams') ->willReturn( [ 'rows' => 10, 'page' => 1, ] ); $this->advancedSearchCheckerMock ->expects($this->once()) ->method('isEnabled') ->willReturn(true); $this->advancedSearch ->method('query') ->willReturn($this->resultSetMock); $this->resultSetResponseNormalizerMock ->expects($this->once()) ->method('normalize') ->willReturn([]); $result = $this->subject->search($this->requestMock); $this->assertIsArray($result); } public function testIsForcingDefaultSearch(): void { $options = $this->subject->getOption(SearchProxy::OPTION_GENERIS_SEARCH_WHITELIST, []); $generisSearchWhitelist = array_merge(SearchProxy::GENERIS_SEARCH_DEFAULT_WHITELIST, $options); $this->assertTrue(in_array(GenerisRdf::CLASS_ROLE, $generisSearchWhitelist)); } }