Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[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       ['1 byte', 1],
33       ['2 bytes', 2],
34       ['1 KB', $kb],
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],
44       // Decimal Megabytes
45       ['3.46 MB', 3623651],
46       // Decimal Petabytes
47       ['59.72 PB', 67234178751368124],
48       // Decimal Yottabytes
49       ['194.67 YB', 235346823821125814962843827],
50     ];
51   }
52
53 }