public function assertPairs($expected_pairs)
 {
     $result = $this->connection->select('key_value_sorted', 't')->fields('t', array('name', 'value'))->condition('collection', $this->collection)->condition('name', array_keys($expected_pairs), 'IN')->execute()->fetchAllAssoc('name');
     $expected_count = count($expected_pairs);
     $this->assertIdentical(count($result), $expected_count, "Query affected {$expected_count} records.");
     foreach ($expected_pairs as $key => $value) {
         $this->assertIdentical($this->serializer->decode($result[$key]->value), $value, "Key {$key} have value {$value}");
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getRange($start, $stop = NULL)
 {
     $query = $this->connection->select($this->table, 't')->fields('t', array('value'))->condition('collection', $this->collection)->condition('name', $start, '>=');
     if ($stop !== NULL) {
         $query->condition('name', $stop, '<=');
     }
     $result = $query->orderBy('name', 'ASC')->execute();
     $values = array();
     foreach ($result as $item) {
         $values[] = $this->serializer->decode($item->value);
     }
     return $values;
 }
 /**
  * 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));
 }
 /**
  * {@inheritdoc}
  */
 public function upload(EmbridgeAssetEntityInterface $asset, array $metadata = [])
 {
     $this->login();
     $file_path = $this->fileSystem->realpath($asset->getSourcePath());
     $filename = $asset->getFilename();
     // Sanitize metadata values.
     $metadata = array_filter($metadata, 'is_scalar');
     if (isset($metadata['libraries'])) {
         // The libraries value won't stick unless it is a string.
         $metadata['libraries'] = (string) $metadata['libraries'];
     }
     // Build the main request data.
     $json_values = ['description' => $filename];
     $json_values = array_merge($json_values, $metadata);
     $json_request = $this->jsonEncoder->encode($json_values);
     $body = ['multipart' => [['name' => 'jsonrequest', 'contents' => $json_request], ['name' => 'file', 'contents' => file_get_contents($file_path), 'filename' => $filename]]];
     $response_body = $this->doRequest(self::EMBRIDGE_UPLOAD_PATH_DEFAULT, $body);
     $asset->setAssetId($response_body['data']['id']);
     $asset->setSourcePath($response_body['data']['sourcepath']);
     return $asset;
 }
 /**
  * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setIfNotExists().
  */
 public function setIfNotExists($key, $value)
 {
     $result = $this->connection->merge($this->table)->insertFields(array('collection' => $this->collection, 'name' => $key, 'value' => $this->serializer->encode($value)))->condition('collection', $this->collection)->condition('name', $key)->execute();
     return $result == Merge::STATUS_INSERT;
 }
Beispiel #6
0
 public static function getFileExtension()
 {
     return static::$mock->getFileExtension();
 }
 /**
  * Returns the file URI of the library definition file for a given library ID.
  *
  * @param $id
  *   The ID of the external library.
  *
  * @return string
  *   The file URI of the file the library definition resides in.
  */
 protected function getFileUri($id)
 {
     $filename = $id . '.' . $this->serializer->getFileExtension();
     return "{$this->baseUri}/{$filename}";
 }
 /**
  * Returns the file URI of the library definition file for a given library ID.
  *
  * @param $id
  *   The ID of the external library.
  *
  * @return string
  *   The file URI of the file the library definition resides in.
  */
 protected function getFileUri($id)
 {
     $filename = $id . '.' . $this->serializer->getFileExtension();
     return "library-definitions://{$filename}";
 }