Index: modules/block/block.test =================================================================== RCS file: /var/www/CoreDev/core/drupal/modules/block/block.test,v retrieving revision 1.2 diff -u -p -r1.2 block.test --- modules/block/block.test 30 May 2008 07:30:49 -0000 1.2 +++ modules/block/block.test 30 Jun 2008 23:04:23 -0000 @@ -1,5 +1,5 @@ assertText(t('The block configuration has been saved.'), t('Block title set.')); } } + +class BlockCachingTestCase extends DrupalWebTestCase { + + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Block caching'), + 'description' => t('Test various aspects of the block caching system.'), + 'group' => t('Block'), + ); + } + + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp("block_test"); + + // Create and login user + $admin_user = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($admin_user); + } + + /** + * Validate the behavior of the block caching layer. + */ + function testCaching() { + variable_set('block_cache', 1); + variable_set('block_test_content', $this->randomName(20)); + + // Display the test block + $edit = array(); + $edit['block_test_test_block[region]'] = 'left'; + $this->drupalPost('admin/build/block', $edit, t('Save blocks')); + + // Confirm that the test block is displayed + $this->assertText(variable_get('block_test_content', ''), t('(NO_CACHE) Test block successfully being displayed on the page.')); + + // Try changing the test block contents + variable_set('block_test_content', $this->randomName(20)); + $this->drupalGet(''); + $this->assertText(variable_get('block_test_content', ''), t('(NO_CACHE) Test block content successfully changed.')); + + // Change the caching of the test block + variable_set('block_test_caching', BLOCK_CACHE_GLOBAL); + $this->drupalPost('admin/build/block', array(), t('Save blocks')); + + // Try changing the test block contents + $this->drupalGet(''); + $this->assertText(variable_get('block_test_content', ''), t('(CACHE_GLOBAL) Test block content is still there.')); + variable_set('block_test_content', $data = $this->randomName(20)); + $this->drupalGet(''); + $this->assertNoText(variable_get('block_test_content', ''), t('(CACHE_GLOBAL) Test block content has been cached.')); + + // Empty caches + cache_clear_all(NULL, 'cache_block'); + $this->drupalGet(''); + $this->assertText(variable_get('block_test_content', ''), t('(CACHE_GLOBAL) Test block content changed after cache_clear_all().')); + + // Back to no caching + variable_set('block_test_caching', BLOCK_NO_CACHE); + $this->drupalPost('admin/build/block', array(), t('Save blocks')); + + // Try changing the test block contents + $this->drupalGet(''); + $this->assertText(variable_get('block_test_content', ''), t('(NO_CACHE) Test block content is still there.')); + variable_set('block_test_content', $this->randomName(20)); + $this->drupalGet(''); + $this->assertText(variable_get('block_test_content', ''), t('(NO_CACHE) Test block content successfully changed.')); + } +} + Index: modules/block/tests/block_test.info =================================================================== RCS file: modules/block/tests/block_test.info diff -N modules/block/tests/block_test.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/block/tests/block_test.info 30 Jun 2008 20:55:28 -0000 @@ -0,0 +1,7 @@ +name = "Block Test" +description = "Support module for testing the Block module." +package = Testing +version = VERSION +core = 7.x +files[] = block_test.module +hidden = TRUE Index: modules/block/tests/block_test.module =================================================================== RCS file: modules/block/tests/block_test.module diff -N modules/block/tests/block_test.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/block/tests/block_test.module 30 Jun 2008 21:28:26 -0000 @@ -0,0 +1,26 @@ + t('Test block'), + 'cache' => variable_get('block_test_caching', BLOCK_NO_CACHE), + ); + return $blocks; + } + else if ($op == 'view' && $delta == 'test_block') { + return array( + 'subject' => t('Test block'), + 'content' => variable_get('block_test_content', ''), + ); + } +}