Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\Component\Utility;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Bytes;
|
Chris@0
|
6 use PHPUnit\Framework\TestCase;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests bytes size parsing helper methods.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group Utility
|
Chris@0
|
12 *
|
Chris@0
|
13 * @coversDefaultClass \Drupal\Component\Utility\Bytes
|
Chris@0
|
14 */
|
Chris@0
|
15 class BytesTest extends TestCase {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Tests \Drupal\Component\Utility\Bytes::toInt().
|
Chris@0
|
19 *
|
Chris@0
|
20 * @param int $size
|
Chris@0
|
21 * The value for the size argument for
|
Chris@0
|
22 * \Drupal\Component\Utility\Bytes::toInt().
|
Chris@0
|
23 * @param int $expected_int
|
Chris@0
|
24 * The expected return value from
|
Chris@0
|
25 * \Drupal\Component\Utility\Bytes::toInt().
|
Chris@0
|
26 *
|
Chris@0
|
27 * @dataProvider providerTestToInt
|
Chris@0
|
28 * @covers ::toInt
|
Chris@0
|
29 */
|
Chris@0
|
30 public function testToInt($size, $expected_int) {
|
Chris@0
|
31 $this->assertEquals($expected_int, Bytes::toInt($size));
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Provides data for testToInt.
|
Chris@0
|
36 *
|
Chris@0
|
37 * @return array
|
Chris@0
|
38 * An array of arrays, each containing the argument for
|
Chris@0
|
39 * \Drupal\Component\Utility\Bytes::toInt(): size, and the expected return
|
Chris@0
|
40 * value.
|
Chris@0
|
41 */
|
Chris@0
|
42 public function providerTestToInt() {
|
Chris@0
|
43 return [
|
Chris@0
|
44 ['1', 1],
|
Chris@0
|
45 ['1 byte', 1],
|
Chris@0
|
46 ['1 KB' , Bytes::KILOBYTE],
|
Chris@0
|
47 ['1 MB' , pow(Bytes::KILOBYTE, 2)],
|
Chris@0
|
48 ['1 GB' , pow(Bytes::KILOBYTE, 3)],
|
Chris@0
|
49 ['1 TB' , pow(Bytes::KILOBYTE, 4)],
|
Chris@0
|
50 ['1 PB' , pow(Bytes::KILOBYTE, 5)],
|
Chris@0
|
51 ['1 EB' , pow(Bytes::KILOBYTE, 6)],
|
Chris@0
|
52 ['1 ZB' , pow(Bytes::KILOBYTE, 7)],
|
Chris@0
|
53 ['1 YB' , pow(Bytes::KILOBYTE, 8)],
|
Chris@0
|
54 ['23476892 bytes', 23476892],
|
Chris@0
|
55 // 76 MB.
|
Chris@0
|
56 ['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776],
|
Chris@0
|
57 // 76.24 GB (with typo).
|
Chris@0
|
58 ['76.24 Giggabyte', 81862076662],
|
Chris@0
|
59 ];
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 }
|