You are here

function VotingAPITestCase::testMinimalAdd in Voting API 7.2

Same name and namespace in other branches
  1. 6.2 tests/votingapi.test \VotingAPITestCase::testMinimalAdd()
  2. 7.3 tests/votingapi.test \VotingAPITestCase::testMinimalAdd()

Ensure that the optional fields are truly optional.

File

tests/votingapi.test, line 47
Test file for VotingAPI module.

Class

VotingAPITestCase
@file Test file for VotingAPI module.

Code

function testMinimalAdd() {
  $nid = variable_get('votingapi_nid1', NULL);
  $value = '85';

  // The minimum required fields according to the documentation are
  // entity_id and value.
  $vote = array(
    'entity_id' => $nid,
    'value' => $value,
  );
  try {
    $result = votingapi_add_votes($vote);

    // Test that the result has its fields set appropriately.
    $this
      ->validateVote('testMinimalAdd()', $result, $nid, array(
      $value,
    ));
    $this
      ->assertTrue(REQUEST_TIME - $result[0]['timestamp'] < 2, t('The timestamp should be less than 2 seconds ago.'));
  } catch (Exception $e) {
    $this
      ->fail(t('Could not add a vote with only entity_id and value.'));
    return;
  }
}