You are here

public function AuthcacheEsiTestCase::testEsiFragment in Authenticated User Page Caching (Authcache) 7.2

Cover theme_authcache_p13n_fragment__authcache_esi().

File

modules/authcache_esi/tests/authcache_esi.test, line 54
Tests for ESI markup generator

Class

AuthcacheEsiTestCase
Test authcache esi

Code

public function testEsiFragment() {
  $page = array(
    '#theme' => 'authcache_p13n_fragment',
    '#fragment' => 'esi-test-fragment',
    '#param' => $this
      ->randomName(8),
    '#fallback' => 'cancel',
    '#original' => $this
      ->randomName(8),
  );

  // Test whether fallback markup is rendered on the page.
  $stub = $this->stubmod
    ->hook('page', $page);
  $this
    ->drupalGet('authcache-esi-test-page');
  $this
    ->assertStub($stub, HookStub::once());
  $this
    ->assertText($page['#original']);
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Authcache-Do-ESI'), t('Header %header must be absent when fallback markup is rendered', array(
    '%header' => 'X-Authcache-Do-ESI',
  )));
  $elements = $this
    ->xpath('//*[local-name(.) = "include"]');
  $this
    ->assertEqual(0, count($elements));

  // Test whether <span> placeholder tag is rendered on page.
  $stub = $this->stubmod
    ->hook('page', $page);
  $this
    ->drupalGet('authcache-esi-test-page', array(), array(
    'X-Authcache-Do-ESI: 1',
  ));
  $this
    ->assertStub($stub, HookStub::once());
  $this
    ->assertNoText($page['#original']);
  $this
    ->assertTrue($this
    ->drupalGetHeader('X-Authcache-Do-ESI'), t('Header %header must be present when ESI tag is rendered', array(
    '%header' => 'X-Authcache-Do-ESI',
  )));
  $elements = $this
    ->xpath('//*[local-name(.) = "include"]');
  $this
    ->assertEqual(1, count($elements));
}