3 namespace Drupal\Tests\Component\Utility;
5 use Drupal\Component\Utility\Bytes;
6 use PHPUnit\Framework\TestCase;
9 * Tests bytes size parsing helper methods.
13 * @coversDefaultClass \Drupal\Component\Utility\Bytes
15 class BytesTest extends TestCase {
18 * Tests \Drupal\Component\Utility\Bytes::toInt().
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().
27 * @dataProvider providerTestToInt
30 public function testToInt($size, $expected_int) {
31 $this->assertEquals($expected_int, Bytes::toInt($size));
35 * Provides data for testToInt.
38 * An array of arrays, each containing the argument for
39 * \Drupal\Component\Utility\Bytes::toInt(): size, and the expected return
42 public function providerTestToInt() {
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],
56 ['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776],
57 // 76.24 GB (with typo).
58 ['76.24 Giggabyte', 81862076662],