You are here

public function BytesTest::providerTestToNumber in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/BytesTest.php \Drupal\Tests\Component\Utility\BytesTest::providerTestToNumber()

Provides data for testToNumber().

Return value

array An array of arrays, each containing the argument for \Drupal\Component\Utility\Bytes::toNumber(): size, and the expected return value with the expected type (float).

File

core/tests/Drupal/Tests/Component/Utility/BytesTest.php, line 45

Class

BytesTest
Tests bytes size parsing helper methods.

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestToNumber() : array {
  return [
    [
      '1',
      1.0,
    ],
    [
      '1 byte',
      1.0,
    ],
    [
      '1 KB',
      (double) Bytes::KILOBYTE,
    ],
    [
      '1 MB',
      (double) pow(Bytes::KILOBYTE, 2),
    ],
    [
      '1 GB',
      (double) pow(Bytes::KILOBYTE, 3),
    ],
    [
      '1 TB',
      (double) pow(Bytes::KILOBYTE, 4),
    ],
    [
      '1 PB',
      (double) pow(Bytes::KILOBYTE, 5),
    ],
    [
      '1 EB',
      (double) pow(Bytes::KILOBYTE, 6),
    ],
    // Zettabytes and yottabytes cannot be represented by integers on 64-bit
    // systems, so pow() returns a float.
    [
      '1 ZB',
      pow(Bytes::KILOBYTE, 7),
    ],
    [
      '1 YB',
      pow(Bytes::KILOBYTE, 8),
    ],
    [
      '23476892 bytes',
      23476892.0,
    ],
    // 76 MB.
    [
      '76MRandomStringThatShouldBeIgnoredByParseSize.',
      79691776.0,
    ],
    // 76.24 GB (with typo).
    [
      '76.24 Giggabyte',
      81862076662.0,
    ],
    [
      '1.5',
      2.0,
    ],
    [
      1.5,
      2.0,
    ],
    [
      '2.4',
      2.0,
    ],
    [
      2.4,
      2.0,
    ],
    [
      '',
      0.0,
    ],
    [
      '9223372036854775807',
      9.223372036854776E+18,
    ],
  ];
}