You are here

class BytesTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/BytesTest.php \Drupal\Tests\Component\Utility\BytesTest

Tests bytes size parsing helper methods.

@group Utility

@coversDefaultClass \Drupal\Component\Utility\Bytes

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
    • class \Drupal\Tests\Component\Utility\BytesTest

Expanded class hierarchy of BytesTest

File

core/tests/Drupal/Tests/Component/Utility/BytesTest.php, line 20
Contains \Drupal\Tests\Component\Utility\BytesTest.

Namespace

Drupal\Tests\Component\Utility
View source
class BytesTest extends UnitTestCase {

  /**
   * Tests \Drupal\Component\Utility\Bytes::toInt().
   *
   * @param int $size
   *   The value for the size argument for
   *   \Drupal\Component\Utility\Bytes::toInt().
   * @param int $expected_int
   *   The expected return value from
   *   \Drupal\Component\Utility\Bytes::toInt().
   *
   * @dataProvider providerTestToInt
   * @covers ::toInt
   */
  public function testToInt($size, $expected_int) {
    $this
      ->assertEquals($expected_int, Bytes::toInt($size));
  }

  /**
   * Provides data for testToInt.
   *
   * @return array
   *   An array of arrays, each containing the argument for
   *   \Drupal\Component\Utility\Bytes::toInt(): size, and the expected return
   *   value.
   */
  public function providerTestToInt() {
    return array(
      array(
        '1',
        1,
      ),
      array(
        '1 byte',
        1,
      ),
      array(
        '1 KB',
        Bytes::KILOBYTE,
      ),
      array(
        '1 MB',
        pow(Bytes::KILOBYTE, 2),
      ),
      array(
        '1 GB',
        pow(Bytes::KILOBYTE, 3),
      ),
      array(
        '1 TB',
        pow(Bytes::KILOBYTE, 4),
      ),
      array(
        '1 PB',
        pow(Bytes::KILOBYTE, 5),
      ),
      array(
        '1 EB',
        pow(Bytes::KILOBYTE, 6),
      ),
      array(
        '1 ZB',
        pow(Bytes::KILOBYTE, 7),
      ),
      array(
        '1 YB',
        pow(Bytes::KILOBYTE, 8),
      ),
      array(
        '23476892 bytes',
        23476892,
      ),
      array(
        '76MRandomStringThatShouldBeIgnoredByParseSize.',
        79691776,
      ),
      // 76 MB
      array(
        '76.24 Giggabyte',
        81862076662,
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BytesTest::providerTestToInt public function Provides data for testToInt.
BytesTest::testToInt public function Tests \Drupal\Component\Utility\Bytes::toInt().
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 259