comparison core/tests/Drupal/Tests/Component/Utility/BytesTest.php @ 0:4c8ae668cc8c

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