You are here

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

Ensure that flags are rendered propertly when user has unflag permission.

Covers AuthcacheFlagFlagFragment

File

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

Class

AuthcacheFlagTest
Tests for markup substitution.

Code

public function testAuthcacheFlagFlagFragmentWithUnflag() {
  $this
    ->drupalLogin($this->member2);
  $partial = _authcache_flag_partial_id($this->nodeFlag);
  $url = authcache_p13n_request_get_callback('asm/flags', array(
    $partial => array(
      $this->node1->nid,
      $this->node2->nid,
    ),
  ));
  $this
    ->assertTrue($url);

  // Fetch (both nodes unflagged).
  $result = $this
    ->drupalGetAJAX($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assert(isset($result[$partial]));
  $this
    ->assertEqual(array(
    $this->node1->nid,
    $this->node2->nid,
  ), array_keys($result[$partial]));
  $this
    ->drupalSetContent($result[$partial][$this->node1->nid]);
  $this
    ->assertLink('Flag this item', 0, 'The flag link appears in the first fragment.');
  $this
    ->drupalSetContent($result[$partial][$this->node2->nid]);
  $this
    ->assertLink('Flag this item', 0, 'The flag link appears in the second fragment.');

  // Click the link to flag the second node.
  $this
    ->clickLink(t('Flag this item'));

  // Refetch (first node unflagged, second node flagged).
  $result = $this
    ->drupalGetAJAX($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assert(isset($result[$partial]));
  $this
    ->assertEqual(array(
    $this->node1->nid,
    $this->node2->nid,
  ), array_keys($result[$partial]));
  $this
    ->drupalSetContent($result[$partial][$this->node1->nid]);
  $this
    ->assertLink('Flag this item', 0, 'The flag link appears in the first fragment.');
  $this
    ->drupalSetContent($result[$partial][$this->node2->nid]);
  $this
    ->assertLink('Unflag this item', 0, 'The unflag link appears on the page after flagging.');

  // Click the link to flag the second node.
  $this
    ->clickLink(t('Unflag this item'));

  // Refetch (first node unflagged, second node flagged).
  $result = $this
    ->drupalGetAJAX($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assert(isset($result[$partial]));
  $this
    ->assertEqual(array(
    $this->node1->nid,
    $this->node2->nid,
  ), array_keys($result[$partial]));
  $this
    ->drupalSetContent($result[$partial][$this->node1->nid]);
  $this
    ->assertLink('Flag this item', 0, 'The flag link appears in the first fragment.');
  $this
    ->drupalSetContent($result[$partial][$this->node2->nid]);
  $this
    ->assertLink('Flag this item', 0, 'The flag link appears in the second fragment.');
}