function SizeUnitTest::testCommonParseSize

Checks that parse_size() returns the proper byte sizes.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php, line 68
Definition of Drupal\system\Tests\Common\SizeUnitTest.

Class

SizeUnitTest
Tests file size parsing and formatting functions.

Namespace

Drupal\system\Tests\Common

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