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;
35 ['1 MB', pow($kb, 2)],
36 ['1 GB', pow($kb, 3)],
37 ['1 TB', pow($kb, 4)],
38 ['1 PB', pow($kb, 5)],
39 ['1 EB', pow($kb, 6)],
40 ['1 ZB', pow($kb, 7)],
41 ['1 YB', pow($kb, 8)],
42 // Rounded to 1 MB - not 1000 or 1024 kilobyte
43 ['1 MB', ($kb * $kb) - 1],
47 ['59.72 PB', 67234178751368124],
49 ['194.67 YB', 235346823821125814962843827],