You are here

function UserpointsNodeVisitsTestCase::verifyFirstContentOnly in User points Nodes and Comments 7

Verify that points are granted correctly if set to 'Only the first visited content'.

1 call to UserpointsNodeVisitsTestCase::verifyFirstContentOnly()
UserpointsNodeVisitsTestCase::testVisitingContent in userpoints_nc_visits/userpoints_nc_visits.test
Prepare test environment, run different test methods.

File

userpoints_nc_visits/userpoints_nc_visits.test, line 143

Class

UserpointsNodeVisitsTestCase
Generic tests for Userpoints Visits module.

Code

function verifyFirstContentOnly() {
  $edit = array(
    'userpoints_nc_visits_limit' => 'one',
  );
  $this
    ->drupalPost('admin/config/people/userpoints/settings', $edit, t('Save configuration'));
  $content = array(
    'title' => $this
      ->randomName(10),
  );
  $this
    ->drupalPost('node/add/' . $this->type['type'], $content, t('Save'));
  $this
    ->assertText(t('@name @title has been created.', array(
    '@name' => $this->type['name'],
    '@title' => $content['title'],
  )));
  preg_match('|node/(\\d+)|', $this
    ->getUrl(), $matches);
  $nid1 = $matches[1];
  $content = array(
    'title' => $this
      ->randomName(10),
  );
  $this
    ->drupalPost('node/add/' . $this->type['type'], $content, t('Save'));
  $this
    ->assertText(t('@name @title has been created.', array(
    '@name' => $this->type['name'],
    '@title' => $content['title'],
  )));
  preg_match('|node/(\\d+)|', $this
    ->getUrl(), $matches);
  $nid2 = $matches[1];

  // Verify point total, admin should not yet have any points.
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 0);

  // Log in as user 1, visit content.
  $this
    ->drupalLogin($this->user1);
  $this
    ->drupalGet('node/' . $nid1);

  // Verify point total.
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 2);

  // Visit again, points should not have been updated.
  $this
    ->drupalGet('node/' . $nid1);
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 2);

  // Visit second node, points should not update now.
  $this
    ->drupalGet('node/' . $nid2);
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 2);

  // Log in as second user, visit second node, points should go up.
  $this
    ->drupalLogin($this->user2);
  $this
    ->drupalGet('node/' . $nid2);
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 4);

  // Visit first node, points should not go up.
  $this
    ->drupalGet('node/' . $nid1);
  $this
    ->assertEqual(userpoints_get_current_points($this->admin->uid), 4);
}