3 namespace Drupal\KernelTests\Core\Common;
5 use Drupal\Component\Utility\Bytes;
6 use Drupal\KernelTests\KernelTestBase;
9 * Parse a predefined amount of bytes and compare the output with the expected
14 class SizeTest extends KernelTestBase {
17 * Checks that format_size() returns the expected string.
19 * @dataProvider providerTestCommonFormatSize
21 public function testCommonFormatSize($expected, $input) {
22 $size = format_size($input, NULL);
23 $this->assertEquals($expected, $size);
27 * Provides a list of byte size to test.
29 public function providerTestCommonFormatSize() {
30 $kb = Bytes::KILOBYTE;
37 ['1023 bytes', $kb - 1],
39 ['1 MB', pow($kb, 2)],
40 ['1 GB', pow($kb, 3)],
41 ['1 TB', pow($kb, 4)],
42 ['1 PB', pow($kb, 5)],
43 ['1 EB', pow($kb, 6)],
44 ['1 ZB', pow($kb, 7)],
45 ['1 YB', pow($kb, 8)],
46 ['1024 YB', pow($kb, 9)],
47 // Rounded to 1 MB - not 1000 or 1024 kilobytes
48 ['1 MB', ($kb * $kb) - 1],
49 ['-1 MB', -(($kb * $kb) - 1)],
52 ['3.77 GB', 4053371676],
54 ['59.72 PB', 67234178751368124],
56 ['194.67 YB', 235346823821125814962843827],