protected function ServicesHistoricalTestCase::testHistorical in Services Tools 7.3
Same name in this branch
- 7.3 services_historical/services_historical.test \ServicesHistoricalTestCase::testHistorical()
- 7.3 services_historical/services_tools_example/services_tools_example.test \ServicesHistoricalTestCase::testHistorical()
Tests for services_tools_example.module.
File
- services_historical/
services_tools_example/ services_tools_example.test, line 32 - Provide test for services_historical functionality.
Class
- ServicesHistoricalTestCase
- @file Provide test for services_historical functionality.
Code
protected function testHistorical() {
global $base_url;
$url = $base_url . '/example/1.0';
$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 = $base_url . '/example/1.1';
$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 = $base_url . '/example/1.2';
// 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']);
}
}