Pull merge.
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Common / SizeTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Common;
4
5 use Drupal\Component\Utility\Bytes;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Parse a predefined amount of bytes and compare the output with the expected
10  * value.
11  *
12  * @group Common
13  */
14 class SizeTest extends KernelTestBase {
15
16   /**
17    * Checks that format_size() returns the expected string.
18    *
19    * @dataProvider providerTestCommonFormatSize
20    */
21   public function testCommonFormatSize($expected, $input) {
22     $size = format_size($input, NULL);
23     $this->assertEquals($expected, $size);
24   }
25
26   /**
27    * Provides a list of byte size to test.
28    */
29   public function providerTestCommonFormatSize() {
30     $kb = Bytes::KILOBYTE;
31     return [
32       ['0 bytes', 0],
33       ['1 byte', 1],
34       ['-1 bytes', -1],
35       ['2 bytes', 2],
36       ['-2 bytes', -2],
37       ['1023 bytes', $kb - 1],
38       ['1 KB', $kb],
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)],
50       // Decimal Megabytes
51       ['3.46 MB', 3623651],
52       ['3.77 GB', 4053371676],
53       // Decimal Petabytes
54       ['59.72 PB', 67234178751368124],
55       // Decimal Yottabytes
56       ['194.67 YB', 235346823821125814962843827],
57     ];
58   }
59
60 }