You are here

function RESTClientTestCase::testRequests in RESTClient 7.2

File

./restclient.test, line 26
Tests for restclient module

Class

RESTClientTestCase
@file Tests for restclient module

Code

function testRequests() {

  // Check administrative page permissions
  // Regular user
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet('admin/config/services/restclient');
  $this
    ->assertResponse('403', t('User blocked from accessing administrative pages'));
  $this
    ->drupalLogout();

  // Admin user
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet('admin/config/services/restclient');
  $this
    ->assertResponse('200', t('Admin access administrative pages'));
  $this
    ->drupalLogout();

  // Test GET request
  $response = restclient_get('/', array(
    'endpoint' => 'http://localhost',
  ));
  $this
    ->assertEqual(200, $response->code, t('GET request completed successfully'), 'REST API');

  // Test parameter insertion
  $expected_request = 'GET /node';
  $response = restclient_get('/%node', array(
    'endpoint' => 'http://localhost',
    'parameters' => array(
      '%node' => 'node',
    ),
  ));
  $this
    ->assertTrue(FALSE !== strpos($response->request, $expected_request), t('HTTP Request matches expected value.'), 'REST API');
  $this
    ->assertEqual(200, $response->code, t('GET request with parameters completed successfully'), 'REST API');
}