function BlockCacheTestCase::testCachePerUser

7.x block.test BlockCacheTestCase::testCachePerUser()

Test DRUPAL_CACHE_PER_USER.

File

drupal-7.x/modules/block/block.test, line 613
Tests for block.module.

Class

BlockCacheTestCase
Test block caching.

Code

function testCachePerUser() {
  $this->setCacheMode(DRUPAL_CACHE_PER_USER);
  $current_content = $this->randomName();
  variable_set('block_test_content', $current_content);
  $this->drupalLogin($this->normal_user);

  $this->drupalGet('');
  $this->assertText($current_content, 'Block content displays.');

  $old_content = $current_content;
  $current_content = $this->randomName();
  variable_set('block_test_content', $current_content);

  $this->drupalGet('');
  $this->assertText($old_content, 'Block is served from per-user cache.');

  $this->drupalLogin($this->normal_user_alt);
  $this->drupalGet('');
  $this->assertText($current_content, 'Per-user block cache is not served for other users.');

  $this->drupalLogin($this->normal_user);
  $this->drupalGet('');
  $this->assertText($old_content, 'Per-user block cache is persistent.');
}