You are here

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

Cover authcache_esi assembly and partial.

File

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

Class

AuthcacheEsiTestCase
Test authcache esi

Code

public function testEsiAssembly() {
  $page = array(
    '#theme' => 'authcache_p13n_partial',
    '#assembly' => 'esi-test-assembly',
    '#partial' => 'esi-test-partial',
    '#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('//iframe/*[local-name(.) = "include"]');
  $this
    ->assertEqual(0, count($elements));
  $elements = $this
    ->xpath('//span[@class="authcache-p13n-asm-esi-test-assembly"]');
  $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('//iframe/*[local-name(.) = "include"]');
  $this
    ->assertEqual(1, count($elements));
  $elements = $this
    ->xpath('//span[@class="authcache-p13n-asm-esi-test-assembly"]');
  $this
    ->assertEqual(1, count($elements));
}