You are here

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

When page is delivered from cache, history should be recorded / reported.

File

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

Class

AuthcacheNodeHistoryTest
Tests for markup substitution.

Code

public function testNodeHistorySettingCacheHit() {
  $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.
  $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.
  $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);
}