You are here

RestfulDataProviderCToolsPluginsTestCase.test in RESTful 7

File

tests/RestfulDataProviderCToolsPluginsTestCase.test
View source
<?php

/**
 * @file
 * Contains \RestfulDataProviderCToolsPluginsTestCase.
 */
class RestfulDataProviderCToolsPluginsTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'CTools plugins',
      'description' => 'Test the CTools plugins data provider.',
      'group' => 'RESTful',
    );
  }
  function setUp() {
    parent::setUp('restful_example');
  }

  /**
   * Test the data provider.
   */
  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.');
  }

}