You are here

function CommonSizeTestCase::testCommonParseSize in SimpleTest 7

Check that parse_size() returns the proper byte sizes.

File

tests/common.test, line 352
Tests for common.inc functionality.

Class

CommonSizeTestCase

Code

function testCommonParseSize() {
  foreach ($this->exact_test_cases as $string => $size) {
    $this
      ->assertEqual($parsed_size = parse_size($string), $size, $size . ' == ' . $parsed_size . ' (' . $string . ')');
  }

  // Some custom parsing tests
  $string = '23476892 bytes';
  $this
    ->assertEqual($parsed_size = parse_size($string), $size = 23476892, $string . ' == ' . $parsed_size . ' bytes');
  $string = '76MRandomStringThatShouldBeIgnoredByParseSize.';

  // 76 MB
  $this
    ->assertEqual($parsed_size = parse_size($string), $size = 79691776, $string . ' == ' . $parsed_size . ' bytes');
  $string = '76.24 Giggabyte';

  // Misspeld text -> 76.24 GB
  $this
    ->assertEqual($parsed_size = parse_size($string), $size = 81862076662, $string . ' == ' . $parsed_size . ' bytes');
}