You are here

public function AuthcacheAjaxTestCase::testAjaxAssembly in Authenticated User Page Caching (Authcache) 7.2

Cover authcache_ajax assembly and partial.

File

modules/authcache_ajax/tests/authcache_ajax.test, line 120
Tests for Ajax markup generator

Class

AuthcacheAjaxTestCase
Test authcache ajax

Code

public function testAjaxAssembly() {
  $page = array(
    '#theme' => 'authcache_p13n_partial',
    '#assembly' => 'ajax-test-assembly',
    '#partial' => 'ajax-test-partial',
    '#param' => $this
      ->randomName(8),
    '#fallback' => 'cancel',
    '#original' => $this
      ->randomName(8),
  );

  // Make sure JavaScript is turned off in simpletest browser.
  $this
    ->drupalGet('authcache-ajax-test-set-has-js/0');

  // Test whether fallback markup is rendered on the page.
  $stub = $this->stubmod
    ->hook('page', $page);
  $this
    ->drupalGet('authcache-ajax-test-page');
  $this
    ->assertStub($stub, HookStub::once());
  $this
    ->assertText($page['#original']);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertFalse(isset($settings['authcacheP13nAjaxAssemblies']));
  $elements = $this
    ->xpath('//span[@class="authcache-p13n-asm-ajax-test-assembly"]');
  $this
    ->assertEqual(0, count($elements));

  // Make sure JavaScript is turned on in simpletest browser.
  $this
    ->drupalGet('authcache-ajax-test-set-has-js/1');

  // Test whether <span> placeholder tag is rendered on page.
  $stub = $this->stubmod
    ->hook('page', $page);
  $this
    ->drupalGet('authcache-ajax-test-page');
  $this
    ->assertStub($stub, HookStub::once());
  $this
    ->assertNoText($page['#original']);
  $settings = $this
    ->drupalGetSettings();
  $this
    ->assertTrue(isset($settings['authcacheP13nAjaxAssemblies']));
  $elements = $this
    ->xpath('//span[@class="authcache-p13n-asm-ajax-test-assembly"]');
  $this
    ->assertEqual(1, count($elements));
}