public function RestfulDbQueryTestCase::__testRenderCache in RESTful 7.2
Test the render cache.
File
- tests/
RestfulDbQueryTestCase.test, line 243 - Contains RestfulDbQueryTestCase.
Class
Code
public function __testRenderCache() {
$resource_manager = restful()
->getResourceManager();
$account = $this
->drupalCreateUser();
// Populate the table with some values.
$mock_data = array(
'str_field' => $this
->randomName(),
'int_field' => intval(mt_rand(1, 100)),
);
$mock_data['serialized_field'] = serialize($mock_data);
$id = db_insert($this->tableName)
->fields($mock_data)
->execute();
$id = intval($id);
// Get the handler.
/* @var \Drupal\restful\Plugin\resource\Decorators\CacheDecoratedResourceInterface $handler */
$handler = $resource_manager
->getPlugin('db_query_test:1.0');
$handler
->setAccount($account);
$cache = $handler
->getCacheController();
// Populate the cache entry.
$handler
->setRequest(Request::create('api/db_query_test/v1.0/' . $id));
$handler
->setPath($id);
$handler
->process();
$version = $handler
->getVersion();
$cid = 'v' . $version['major'] . '.' . $version['minor'] . '::db_query_test::uu' . $account->uid . '::patb:restful_test_db_query::cl:id::id:' . $id;
$cache_data = $cache
->get($cid);
$this
->assertNotNull($cache_data->data, 'Cache data is present.');
$this
->assertEqual($cache_data->data[0]['string'], $mock_data['str_field'], 'The record was retrieved successfully.');
$this
->assertEqual($cache_data->data[0]['integer'], $mock_data['int_field'], 'The record was retrieved successfully.');
$this
->assertEqual($cache_data->data[0]['serialized'], $mock_data['serialized_field'], 'The record was retrieved successfully.');
}