You are here

public function AuthcacheFlagTest::testUserMarkupSubstitution in Authenticated User Page Caching (Authcache) 7.2

Test that the flag markup is substituted by a partial.

Covers authcache_flag_entity_view_alter()

File

modules/authcache_flag/authcache_flag.test, line 332
Test cases for the Authcache Flag module.

Class

AuthcacheFlagTest
Tests for markup substitution.

Code

public function testUserMarkupSubstitution() {
  $this->stubmod
    ->hook('authcache_p13n_client', array(
    'authcache_p13n_test' => array(
      'title' => t('Test Client'),
      'enabled' => TRUE,
    ),
  ));
  $this
    ->drupalLogin($this->member1);

  // M1: Visit the front page populated with two node having one flag each.
  $assembly_markup = $this
    ->randomName(8);
  $assembly_stub = HookStub::on('theme_authcache_p13n_assembly__authcache_p13n_test', $assembly_markup);
  $partial_markup = $this
    ->randomName(8);
  $partial_stub = HookStub::on('theme_authcache_p13n_partial__authcache_p13n_test', $partial_markup);
  $this
    ->drupalGet('user/' . $this->member2->uid);
  $this
    ->assertStub($assembly_stub, HookStub::times(1));
  $this
    ->assertStub($partial_stub, HookStub::times(1));

  // Load flag and change it such that it will be displayed as a pseudo field.
  $flag = flag_get_flag($this->userFlag->name);
  $flag->show_in_links = array();
  $flag->show_as_field = 1;
  $flag->show_on_profile = 0;
  $this->userFlag = $this
    ->saveFlag($flag);

  // M1: Visit a full node view.
  $assembly_markup = $this
    ->randomName(8);
  $assembly_stub = HookStub::on('theme_authcache_p13n_assembly__authcache_p13n_test', $assembly_markup);
  $partial_markup = $this
    ->randomName(8);
  $partial_stub = HookStub::on('theme_authcache_p13n_partial__authcache_p13n_test', $partial_markup);
  $this
    ->drupalGet('user/' . $this->member2->uid);
  $this
    ->assertStub($assembly_stub, HookStub::times(1));
  $this
    ->assertStub($partial_stub, HookStub::times(1));

  // Load flag and change it such that it will be displayed as a user profile
  // field.
  $flag = flag_get_flag($this->userFlag->name);
  $flag->show_in_links = array();
  $flag->show_as_field = 0;
  $flag->show_on_profile = 1;
  $this->userFlag = $this
    ->saveFlag($flag);

  // M1: Visit a full node view.
  $assembly_markup = $this
    ->randomName(8);
  $assembly_stub = HookStub::on('theme_authcache_p13n_assembly__authcache_p13n_test', $assembly_markup);
  $partial_markup = $this
    ->randomName(8);
  $partial_stub = HookStub::on('theme_authcache_p13n_partial__authcache_p13n_test', $partial_markup);
  $this
    ->drupalGet('user/' . $this->member2->uid);
  $this
    ->assertStub($assembly_stub, HookStub::times(1));
  $this
    ->assertStub($partial_stub, HookStub::times(1));
}