class SizeTest

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Common/SizeTest.php \Drupal\KernelTests\Core\Common\SizeTest

Tests format_size().

@group Common

Hierarchy

  • class \Drupal\KernelTests\Core\Common\SizeTest

Expanded class hierarchy of SizeTest

File

core/tests/Drupal/KernelTests/Core/Common/SizeTest.php, line 13

Namespace

Drupal\KernelTests\Core\Common
View source
class SizeTest extends KernelTestBase {
  
  /**
   * Checks that format_size() returns the expected string.
   *
   * @dataProvider providerTestCommonFormatSize
   */
  public function testCommonFormatSize($expected, $input) {
    $size = format_size($input, NULL);
    $this->assertEquals($expected, $size);
  }
  
  /**
   * Provides a list of byte size to test.
   */
  public function providerTestCommonFormatSize() {
    $kb = Bytes::KILOBYTE;
    return [
      [
        '0 bytes',
        0,
      ],
      [
        '1 byte',
        1,
      ],
      [
        '-1 bytes',
        -1,
      ],
      [
        '2 bytes',
        2,
      ],
      [
        '-2 bytes',
        -2,
      ],
      [
        '1023 bytes',
        $kb - 1,
      ],
      [
        '1 KB',
        $kb,
      ],
      [
        '1 MB',
        pow($kb, 2),
      ],
      [
        '1 GB',
        pow($kb, 3),
      ],
      [
        '1 TB',
        pow($kb, 4),
      ],
      [
        '1 PB',
        pow($kb, 5),
      ],
      [
        '1 EB',
        pow($kb, 6),
      ],
      [
        '1 ZB',
        pow($kb, 7),
      ],
      [
        '1 YB',
        pow($kb, 8),
      ],
      [
        '1024 YB',
        pow($kb, 9),
      ],
      // Rounded to 1 MB - not 1000 or 1024 kilobytes
[
        '1 MB',
        $kb * $kb - 1,
      ],
      [
        '-1 MB',
        -($kb * $kb - 1),
      ],
      // Decimal Megabytes
[
        '3.46 MB',
        3623651,
      ],
      [
        '3.77 GB',
        4053371676,
      ],
      // Decimal Petabytes
[
        '59.72 PB',
        67234178751368124,
      ],
      // Decimal Yottabytes
[
        '194.67 YB',
        2.3534682382112583E+26,
      ],
    ];
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
AssertLegacyTrait::assert Deprecated protected function
AssertLegacyTrait::assertEqual Deprecated protected function
AssertLegacyTrait::assertIdentical Deprecated protected function
AssertLegacyTrait::assertIdenticalObject Deprecated protected function
AssertLegacyTrait::assertNotEqual Deprecated protected function
AssertLegacyTrait::assertNotIdentical Deprecated protected function
AssertLegacyTrait::pass Deprecated protected function
AssertLegacyTrait::verbose Deprecated protected function
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
SizeTest::providerTestCommonFormatSize public function Provides a list of byte size to test.
SizeTest::testCommonFormatSize public function Checks that format_size() returns the expected string.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.