You are here

function VotingAPITestCase::testMinimalAdd in Voting API 7.3

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

Ensure that the optional fields are truly optional.

File

tests/votingapi.test, line 46
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 = new VotingApi_Vote(array(
    'entity_id' => $nid,
    'value' => $value,
  ));
  try {
    $result = VotingApi_Vote::saveMultiple($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;
  }
}