You are here

function StatisticsAdvancedTestCase::testNodeCounter in Statistics Advanced 6

File

./statistics_advanced.test, line 29
Unit tests for the statistics_advanced module.

Class

StatisticsAdvancedTestCase
Test basic statistics advanced functionality.

Code

function testNodeCounter() {

  // Set anonymous user permissions to view post access counter.

  //db_query("DELETE FROM {permission} WHERE rid = %d", DRUPAL_ANONYMOUS_RID);

  //db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", DRUPAL_ANONYMOUS_RID, 'access content, view post access counter');
  db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", array(
    ':rid' => DRUPAL_ANONYMOUS_RID,
    ':perms' => 'access content, view post access counter',
  ));
  $hits = 0;
  $node = $this
    ->drupalCreateNode();

  // Test one unique and one repeat view from an anonymous user.
  $this
    ->assertNodeCount($node->nid, ++$hits);
  $this
    ->assertNodeCount($node->nid, $hits);

  // Test one unique and one repeat view from a logged-in user.
  $user1 = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($user1);
  $this
    ->assertNodeCount($node->nid, ++$hits);
  $this
    ->assertNodeCount($node->nid, $hits);

  // Update node->changed.

  //db_query("UPDATE {node} SET changed = %d WHERE nid = %d", array(':changed' => time(), ':nid' => $node->nid));

  //$this->assertNodeCount($node->nid, ++$hits);

  // Test repeat view from the same user when logged out.
  $this
    ->drupalLogout();
  $this
    ->assertNodeCount($node->nid, $hits);
  $this
    ->assertNodeCount($node->nid, $hits);

  // Log in as a new user, but do not visit any content.
  $user2 = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($user2);
  $this
    ->drupalLogout();

  // Test one unique and one repeate view as logged out new user.
  $this
    ->assertNodeCount($node->nid, ++$hits);
  $this
    ->assertNodeCount($node->nid, $hits);

  // Test that anonymous views when access log is disabled should always increment.
  variable_set('statistics_enable_access_log', 0);

  //db_query("DELETE FROM {accesslog}");
  $this
    ->assertNodeCount($node->nid, ++$hits);
  $this
    ->assertNodeCount($node->nid, ++$hits);
}