You are here

function VarnishCacheInvalidationCase::testNodeCacheExpiration in Varnish 6

Test that makes sure the Node Cache Expiration works as intended.

File

./varnish.test, line 210
Tests the basic functionality of Varnish.

Class

VarnishCacheInvalidationCase

Code

function testNodeCacheExpiration() {
  varnish_purge_all_pages();

  // Tell Varnish Module to follow the same rules as the
  // drupal cache expiration logic does.
  variable_set('varnish_cache_clear', VARNISH_DEFAULT_CLEAR);

  // Cache the standard node listing.
  $this
    ->drupalGet('node');

  // Create a node.
  $node = $this
    ->drupalCreateNode(array(
    'promote' => 1,
  ));

  // Make sure the node shows up in the standard node listing.
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title, t('The node title was found.'));

  // Cache the node in varnish by going to the node.
  $content = $this
    ->drupalGet('node/' . $node->nid);

  // The title should be what we expect, otherwise, something
  // is horribly wrong.
  $this
    ->assertText($node->title, t('The node title was found on the
      node page.'));

  // Change the node title
  $node->title = $this
    ->randomName(8);
  node_save($node);

  // Go to the node again. The title should have been changed.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($node->title, t('The node title did change when
      varnish is set to not invalidate the cache.'));

  // Go to the node listing. The title should have been updated.
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title, t('The changed node title was
      found on the node listing.'));

  // Delete the node. It should disappear from the node listing.
  node_delete($node->nid);
  $this
    ->drupalGet('node');
  $this
    ->assertNoText($node->title, t('The node title of the deleted node
      did not show up in the node listing.'));
}