You are here

protected function ServicesHistoricalTestCase::testHistorical in Services Tools 7.3

Same name in this branch
  1. 7.3 services_historical/services_historical.test \ServicesHistoricalTestCase::testHistorical()
  2. 7.3 services_historical/services_tools_example/services_tools_example.test \ServicesHistoricalTestCase::testHistorical()

Test historical service functionality.

File

services_historical/services_historical.test, line 32
Provide test for services_historical functionality.

Class

ServicesHistoricalTestCase
@file Provide test for services_historical functionality.

Code

protected function testHistorical() {
  $url = url('example/1.0', array(
    'absolute' => TRUE,
  ));
  $data = 'Services are fun!';

  // Setup drupal_http_request() options.
  $options = array(
    'headers' => array(
      'Content-Type' => 'application/json',
    ),
    'method' => 'POST',
    'data' => json_encode($data),
  );

  // Perform HTTP request.
  $response = drupal_http_request($url . '/paste', $options);
  if ($this
    ->assertEqual($response->code, 200, 'Created a paste')) {
    $paste = json_decode($response->data, TRUE);
    $this
      ->assertEqual($paste['id'], 0);
    $this
      ->assertEqual($paste['text'], $data);
  }
  $url = url('example/1.1', array(
    'absolute' => TRUE,
  ));
  $data = array(
    'text' => 'Services are fun!',
    'title' => 'Some cool title',
  );

  // Setup drupal_http_request() options.
  $options = array(
    'headers' => array(
      'Content-Type' => 'application/json',
    ),
    'method' => 'POST',
    'data' => json_encode($data),
  );

  // Perform HTTP request.
  $response = drupal_http_request($url . '/paste', $options);
  if ($this
    ->assertEqual($response->code, 200, 'Created a paste')) {
    $paste = json_decode($response->data, TRUE);
    $this
      ->assertEqual($paste['id'], 1);
    $this
      ->assertEqual($paste['text'], $data['text']);
    $this
      ->assertEqual($paste['title'], $data['title']);
  }
  $url = url('example/1.2', array(
    'absolute' => TRUE,
  ));

  // Perform HTTP request.
  $response = drupal_http_request($url . '/paste', $options);
  if ($this
    ->assertEqual($response->code, 200, 'Created a paste')) {
    $paste = json_decode($response->data, TRUE);
    $this
      ->assertEqual($paste['id'], 2);
    $this
      ->assertEqual($paste['text'], $data['text']);
    $this
      ->assertEqual($paste['title'], $data['title']);
  }
  $id = 2;

  // Setup drupal_http_request() options.
  $options = array(
    'headers' => array(
      'Content-Type' => 'application/json',
    ),
    'data' => json_encode($id),
  );

  // Perform HTTP request.
  $response = drupal_http_request($url . '/paste/' . $id, $options);
  if ($this
    ->assertEqual($response->code, 200, 'Retrived a paste')) {
    $paste = json_decode($response->data, TRUE);
    $this
      ->assertEqual($paste['id'], $id);
    $this
      ->assertEqual($paste['text'], $data['text']);
    $this
      ->assertEqual($paste['title'], $data['title']);
  }
}