Test _block_rehash().
function testBlockRehash() {
module_enable(array(
'block_test',
));
$this
->assertTrue(module_exists('block_test'), 'Test block module enabled.');
// Our new block should be inserted in the database when we visit the
// block management page.
$this
->drupalGet('admin/structure/block');
// Our test block's caching should default to DRUPAL_CACHE_PER_ROLE.
$current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")
->fetchField();
$this
->assertEqual($current_caching, DRUPAL_CACHE_PER_ROLE, 'Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.');
// Disable caching for this block.
state()
->set('block_test.caching', DRUPAL_NO_CACHE);
// Flushing all caches should call _block_rehash().
$this
->resetAll();
// Verify that the database is updated with the new caching mode.
$current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")
->fetchField();
$this
->assertEqual($current_caching, DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE.");
}