You are here

function BatchAPIPercentagesTestCase::testBatchAPIPercentages in SimpleTest 7

Test the _batch_api_percentage() function with the data stored in the testCases class variable.

File

tests/batch.test, line 70
Unit tests for the Drupal Batch API.

Class

BatchAPIPercentagesTestCase
Tests the function _batch_api_percentage() to make sure that the rounding works properly in all cases.

Code

function testBatchAPIPercentages() {
  foreach ($this->testCases as $expected_result => $arguments) {

    // PHP sometimes casts numeric strings that are array keys to integers,
    // cast them back here.
    $expected_result = (string) $expected_result;
    $total = $arguments['total'];
    $current = $arguments['current'];
    $actual_result = _batch_api_percentage($total, $current);
    if ($actual_result === $expected_result) {
      $this
        ->pass(t('Expected the batch api percentage at the state @numerator/@denominator to be @expected%, and got @actual%.', array(
        '@numerator' => $current,
        '@denominator' => $total,
        '@expected' => $expected_result,
        '@actual' => $actual_result,
      )));
    }
    else {
      $this
        ->fail(t('Expected the batch api percentage at the state @numerator/@denominator to be @expected%, but got @actual%.', array(
        '@numerator' => $current,
        '@denominator' => $total,
        '@expected' => $expected_result,
        '@actual' => $actual_result,
      )));
    }
  }
}