function CommonSizeTestCase::testCommonParseSize
Check that parse_size() returns the proper byte sizes.
File
-
modules/
simpletest/ tests/ common.test, line 644
Class
- CommonSizeTestCase
- 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');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.