예제 #1
0
 /**
  * Tests search() success.
  *
  * @covers ::login
  * @covers ::upload
  * @covers ::doRequest
  *
  * @test
  */
 public function searchCorrectlyPassesParametersToRequest()
 {
     $mock_login_response = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Response')->disableOriginalConstructor()->getMock();
     $mock_login_response->expects($this->once())->method('getStatusCode')->willReturn(200);
     $mock_login_response->expects($this->once())->method('getBody')->willReturn(file_get_contents('expected/login-expected-good-response.json', TRUE));
     // This sucks, returnValueMap wasn't working though.
     $this->client->expects($this->at(0))->method('request')->with('POST', self::EXAMPLE_LOGIN_URL, $this->defaultLoginOptions)->willReturn($mock_login_response);
     $mock_search_response = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Response')->disableOriginalConstructor()->getMock();
     $mock_search_response->expects($this->once())->method('getStatusCode')->willReturn(200);
     $search_response_body = file_get_contents('expected/search-expected-good-response.json', TRUE);
     $mock_search_response->expects($this->once())->method('getBody')->willReturn($search_response_body);
     $options = $this->defaultOptions;
     $body = ['page' => 2, 'hitsperpage' => 10, 'showfilters' => "true", 'query' => ['terms' => [['field' => 'name', 'operator' => 'matches', 'value' => 'test*']]]];
     $options['json'] = $body;
     $this->client->expects($this->at(1))->method('request')->with('POST', self::EXAMPLE_SEARCH_URL, $options)->willReturn($mock_search_response);
     $decoded_body = $this->serializer->decode($search_response_body);
     $filters = [['field' => 'name', 'operator' => 'matches', 'value' => 'test*']];
     $this->assertEquals($decoded_body, $this->emdbClient->search(2, 10, $filters));
 }
예제 #2
0
 /**
  * Queries EnterMedia for assets matching search filter.
  *
  * @param int $page
  *   The page to return.
  * @param array $filters
  *   An array of filters.
  *
  * @return array
  *   A search response array.
  */
 private function getSearchResults($page, array $filters = [])
 {
     $num_per_page = 8;
     $search_response = $this->client->search($page, $num_per_page, $filters);
     return $search_response;
 }