You are here

public function AuthcacheNodeHistoryTest::testNodeHistorySettingCacheMiss in Authenticated User Page Caching (Authcache) 7.2

When page is rebuilt during the request.

This covers the $_SESSION['authcache_node_history_last_viewed']-hack.

File

modules/authcache_node_history/authcache_node_history.test, line 188
Test cases for the Authcache Node History module.

Class

AuthcacheNodeHistoryTest
Tests for markup substitution.

Code

public function testNodeHistorySettingCacheMiss() {
  $init_ts = rand(0, REQUEST_TIME - 60);
  $this
    ->setNodeHistoryEntry($this->member->uid, $init_ts);
  $this
    ->drupalLogin($this->member);
  $url = authcache_p13n_request_get_callback('setting/node-history', array(
    'nh' => array(
      'n' => array(
        $this->node->nid,
      ),
      'u' => array(
        $this->node->nid,
      ),
    ),
  ));
  $this
    ->assertTrue($url);

  // First request should report seeded timestamp.
  $this
    ->drupalGet('node/' . $this->node->nid);
  $result = $this
    ->drupalGetAjax($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assertResponse(200);
  $expect = array(
    'authcacheNodeHistory' => array(
      array(
        'nid' => $this->node->nid,
        'ts' => $init_ts,
      ),
    ),
  );
  $this
    ->assertEqual($expect, $result);

  // Second request should report later timestamp.
  $this
    ->drupalGet('node/' . $this->node->nid);
  $result = $this
    ->drupalGetAjax($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual($result['authcacheNodeHistory'][0]['nid'], $this->node->nid);
  $this
    ->assertTrue($result['authcacheNodeHistory'][0]['ts'] > $init_ts);
}