1.20.x common.test CommonSizeUnitTestCase::testCommonParseSize()

Check that parse_size() returns the proper byte sizes.

File

modules/simpletest/tests/common.test, line 575
Tests for common.inc functionality.

Class

CommonSizeUnitTestCase
Tests file size parsing and formatting functions.

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'
  );
}