function BlockHashTestCase::testBlockRehash

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

File

modules/block/block.test, line 923

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.