You are here

function RestfulDataProviderCToolsPluginsTestCase::testDataProvider in RESTful 7

Test the data provider.

File

tests/RestfulDataProviderCToolsPluginsTestCase.test, line 25
Contains \RestfulDataProviderCToolsPluginsTestCase.

Class

RestfulDataProviderCToolsPluginsTestCase
@file Contains \RestfulDataProviderCToolsPluginsTestCase.

Code

function testDataProvider() {
  $handler = restful_get_restful_handler('discovery');

  // Assert sorting and filtering works as expected.
  $request = array(
    // Get all resources.
    'filter' => array(
      'resource' => array(
        'value' => 'articles',
        'operator' => '=',
      ),
    ),
  );
  $result = $handler
    ->get('', $request);

  // Assert sorting and filtering works as expected.
  $request = array(
    // Get all resources.
    'all' => TRUE,
    'sort' => '-name',
    'filter' => array(
      'minor_version' => array(
        'value' => '4',
        'operator' => '>=',
      ),
    ),
  );
  $result = $handler
    ->get('', $request);
  $this
    ->assertEqual(count($result), 4, 'Discovery filtered resources correctly.');
  $this
    ->assertTrue($result[0]['name'] = 'articles_1_7' && ($result[1]['name'] = 'articles_1_6' && ($result[2]['name'] = 'articles_1_5' && ($result[2]['name'] = 'articles_1_4'))), 'Discovery sorted resources correctly.');

  // Assert only latest resources are shown by default.
  $handler = restful_get_restful_handler('discovery');

  // Assert sorting and filtering works as expected.
  $request = array(
    // Get all resources.
    'filter' => array(
      'resource' => array(
        'value' => 'articles',
        'operator' => '=',
      ),
    ),
  );
  $result = $handler
    ->get('', $request);
  $this
    ->assertEqual(count($result), 1, 'Latest resources shown by default.');
  $request['all'] = TRUE;
  $result = $handler
    ->get('', $request);
  $this
    ->assertTrue(count($result) > 1, 'All resources shown by passing the "all" query string.');
}