You are here

function VarnishAdminTestCase::testCacheClearButton in Varnish 6

Test the clear cache button in the admin UI.

File

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

Class

VarnishAdminTestCase

Code

function testCacheClearButton() {

  // Expire all cached pages.
  varnish_purge_all_pages();

  // Tell Varnish Module to not expire anything.
  variable_set('varnish_cache_clear', 0);

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

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

  // Go to the page again. The node should not exist.
  $this
    ->drupalGet('node');
  $this
    ->assertNoText($node->title, t('The node is not present on the front page.'));

  // Log in as administrator.
  $this
    ->drupalLogin($this->admin_user);

  // Go to the performance form.
  $this
    ->drupalGet('admin/settings/performance');

  // Click the clear cache button.
  $this
    ->drupalPost('admin/settings/performance', array(), t('Clear cached data'));
  $this
    ->drupalLogout();

  // Go to the node listing. The node should be present.
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title, t('The node is present after using the clear cache button.'));
}