You are here

public function ViewsContentCacheTest::testarticleContentAdded in Views content cache 7.3

Test that when a node is added the appropriate cache segment is updated.

File

tests/views_content_cache.test, line 20
Provides the Views content cache tests.

Class

ViewsContentCacheTest
@file Provides the Views content cache tests.

Code

public function testarticleContentAdded() {
  $cid = array(
    'node' => array(
      'article',
    ),
  );

  //$this->verbose(views_content_cache_update_get($cid));
  $this
    ->assertFalse(views_content_cache_update_get($cid, TRUE), t('Ensure that the no timestamp has been set against the article cache segment.'));
  $timestamp_before = REQUEST_TIME;
  $this->node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // We intentionally use time() instead of REQUEST_TIME here.
  $timestamp_after = time();

  // Now need to make sure that views content cache recorded the correct time:
  $cid = array(
    'node' => array(
      'article',
    ),
  );
  $updated = views_content_cache_update_get($cid, TRUE);
  $result = $updated <= $timestamp_after && $updated >= $timestamp_before;
  $this
    ->assertTrue($result, t('Ensure that the timestamp against the article cache segment is updated.'));

  // Make sure the page segment was untouched:
  $this
    ->assertFalse(views_content_cache_update_get(array(
    'node' => array(
      'page',
    ),
  ), TRUE), t('Ensure that the no timestamp has been set against the page cache segment.'));

  // Now make sure that the segment will get updated, not just inserted.
  sleep(2);
  $timestamp_before = time();
  $this->node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // We intentionally use time() instead of REQUEST_TIME here.
  $timestamp_after = time();

  // Now need to make sure that views content cache recorded the correct time:
  $cid = array(
    'node' => array(
      'article',
    ),
  );
  $updated = views_content_cache_update_get($cid, TRUE);
  $result = $updated <= $timestamp_after && $updated >= $timestamp_before;
  $this
    ->assertTrue($result, t('Ensure that the timestamp against the article cache segment is updated.'));
}