View source
<?php
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');
}
function testDataProvider() {
$handler = restful_get_restful_handler('discovery');
$request = array(
'filter' => array(
'resource' => array(
'value' => 'articles',
'operator' => '=',
),
),
);
$result = $handler
->get('', $request);
$request = array(
'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.');
$handler = restful_get_restful_handler('discovery');
$request = array(
'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.');
}
}