You are here

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

Cover theme_authcache_p13n_fragment__authcache_ajax().

File

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

Class

AuthcacheAjaxTestCase
Test authcache ajax

Code

public function testAjaxFragment() {
  $page = array(
    '#theme' => 'authcache_p13n_fragment',
    '#fragment' => 'ajax-test-fragment',
    '#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']);
  $elements = $this
    ->xpath('//span[@class="authcache-ajax-frag"]');
  $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']);
  $elements = $this
    ->xpath('//span[@class="authcache-ajax-frag"]');
  $this
    ->assertEqual(1, count($elements));
}