1.20.x batch.test | BatchPercentagesUnitTestCase::testBatchPercentages() |
Test the _batch_api_percentage() function.
File
- modules/
simpletest/ tests/ batch.test, line 371 - Tests for the Batch API.
Class
- BatchPercentagesUnitTestCase
- Tests the function _batch_api_percentage() to make sure that the rounding works properly in all cases.
Code
function testBatchPercentages() {
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)));
}
}
}