/**
  * @test
  * @vcr should_create_and_delete_user_and_return_empty_array.json
  */
 public function should_create_and_delete_user_and_return_empty_array()
 {
     VCR::turnOn();
     VCR::insertCassette('should_create_user_and_return_user_id.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $user = $client->api('user')->userCreate($this->test_user_params());
     $this->assertObjectHasAttribute('uid', $user);
     $this->assertNotNull($user->uid);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_add_role_to_user.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results2 = $client->api('user')->userAddRole($user, 'authenticated user');
     $this->assertEquals('Role successfully added', $results2['message']);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_create_and_delete_user_and_return_empty_array.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results3 = $client->api('user')->userDelete($user);
     $this->assertEmpty($results3);
     VCR::eject();
     VCR::turnOff();
 }
 /**
  * @test
  * @vcr should_pass_basic_auth_and_drupal_auth_with_username_and_password.json
  */
 public function should_pass_basic_auth_and_drupal_auth_with_username_and_password()
 {
     VCR::turnOn();
     VCR::insertCassette('should_pass_basic_auth_and_drupal_auth_with_username_and_password.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results = $client->api('nodes')->createNode($this->test_node_params());
     $this->assertObjectHasAttribute('nid', $results);
     VCR::eject();
     VCR::turnOff();
 }
 protected function instantiateNewClient()
 {
     $drupalPassword = $this->remote_site_password ? $this->remote_site_password : getenv('DRUPAL_REMOTE_CLIENT_PASSWORD');
     $drupalUser = $this->remote_site_username ? $this->remote_site_username : getenv('DRUPAL_REMOTE_CLIENT_USERNAME');
     $drupalUrl = $this->base_url_for_remote_client ? $this->base_url_for_remote_client : getenv('DRUPAL_REMOTE_CLIENT_URL');
     $drupalRemoteClient = new Client();
     $drupalRemoteClient->setOption('base_url', $drupalUrl);
     $drupalRemoteClient->authenticate($drupalUser, $drupalPassword, 'http_drupal_login', $this->request_cookie);
     //  @TODO - Make logging optional
     $drupalRemoteClient->logging();
     return $drupalRemoteClient;
 }
 /**
  * @test
  * @vcr should_take_exception_when_too_many_terms_are_provided.json
  * @expectedException \Kirschbaum\DrupalBehatRemoteAPIDriver\Exception\RuntimeException
  * @expectedExceptionMessage The field_tags field on the remote site requires no more than 1 terms. 2 were provided.
  */
 public function should_take_exception_when_too_many_terms_are_provided()
 {
     // Having trouble with URL encoding match: https://github.com/php-vcr/php-vcr/issues/66
     VCR::configure()->addRequestMatcher('url', function ($first, $second) {
         return $second->getPath() == $first->getPath();
     });
     VCR::turnOn();
     VCR::insertCassette('should_take_exception_when_too_many_terms_are_provided.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $nodeRequest = $client->api('nodes');
     $node = $this->test_node_params();
     $node->field_tags = 'Tag one, Tag two';
     $results = $nodeRequest->createNode($node);
     VCR::eject();
     VCR::turnOff();
 }
 /**
  * Send a DELETE request with JSON-encoded parameters.
  *
  * @param string $path              Request path.
  * @param array $parameters         POST parameters to be JSON encoded.
  * @param array $requestHeaders     Request headers.
  */
 protected function delete($path, array $parameters = array(), $requestHeaders = array())
 {
     $response = $this->client->getHttpClient()->delete($path, $this->createJsonBody($parameters), $requestHeaders);
     return ResponseMediator::getContent($response);
 }
 /**
  * @test
  * @vcr should_delete_term_and_return_empty_array.json
  */
 public function should_delete_term_and_return_empty_array()
 {
     VCR::turnOn();
     VCR::insertCassette('should_create_term_and_return_object_with_term_id.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $term = $client->api('term')->termCreate($this->test_term_params());
     $this->assertObjectHasAttribute('tid', $term);
     VCR::eject();
     VCR::turnOff();
     VCR::turnOn();
     VCR::insertCassette('should_delete_term_and_return_empty_array.json');
     $client = new Client();
     $client->setOption('base_url', $this->url);
     $client->authenticate($this->username, $this->password, 'http_drupal_login');
     $results = $client->api('term')->termDelete($term);
     $this->assertEmpty($results);
     VCR::eject();
     VCR::turnOff();
 }