You are here

function BlockHashTestCase::testBlockRehash in Drupal 7

Tests that block rehashing does not write to the database too often.

File

modules/block/block.test, line 922
Tests for block.module.

Class

BlockHashTestCase
Tests that block rehashing works correctly.

Code

function testBlockRehash() {

  // No hook_block_info_alter(), no save.
  $this
    ->doRehash();
  module_enable(array(
    'block_test',
  ), FALSE);

  // Save the new blocks, check that the new blocks exist by checking weight.
  _block_rehash();
  $this
    ->assertWeight(0);

  // Now hook_block_info_alter() exists but no blocks are saved on a second
  // rehash.
  $this
    ->doRehash();
  $this
    ->assertWeight(0);

  // Now hook_block_info_alter() exists and is changing one block which
  // should be saved.
  $GLOBALS['conf']['block_test_info_alter'] = 1;
  $this
    ->doRehash(TRUE);
  $this
    ->assertWeight(10000);

  // Now hook_block_info_alter() exists but already changed the block's
  // weight before, so it should not be saved again.
  $this
    ->doRehash();
  $this
    ->assertWeight(10000);
}