class ByteSizeMarkupTest
@coversDefaultClass \Drupal\Core\StringTranslation\ByteSizeMarkup
      
    
@group StringTranslation
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase- class \Drupal\Tests\Core\StringTranslation\ByteSizeMarkupTest extends \Drupal\Tests\UnitTestCase
 
Expanded class hierarchy of ByteSizeMarkupTest
File
- 
              core/tests/ Drupal/ Tests/ Core/ StringTranslation/ ByteSizeMarkupTest.php, line 17 
Namespace
Drupal\Tests\Core\StringTranslationView source
class ByteSizeMarkupTest extends UnitTestCase {
  
  /**
   * @covers ::create
   * @dataProvider providerTestCommonFormatSize
   */
  public function testCommonFormatSize($expected, $input) : void {
    $size = ByteSizeMarkup::create($input, NULL, $this->getStringTranslationStub());
    $this->assertInstanceOf(TranslatableMarkup::class, $size);
    $this->assertEquals($expected, $size);
  }
  
  /**
   * Provides a list of byte size to test.
   */
  public static function providerTestCommonFormatSize() {
    $kb = Bytes::KILOBYTE;
    return [
      [
        '0 bytes',
        0,
      ],
      // @todo https://www.drupal.org/node/3161118 Prevent display of fractional
      //   bytes for size less then 1KB.
[
        '0.1 bytes',
        0.1,
      ],
      [
        '0.6 bytes',
        0.6,
      ],
      [
        '1 byte',
        1,
      ],
      [
        '-1 bytes',
        -1,
      ],
      [
        '2 bytes',
        2,
      ],
      [
        '-2 bytes',
        -2,
      ],
      [
        '1023 bytes',
        $kb - 1,
      ],
      [
        '1 KB',
        $kb,
      ],
      [
        '1 MB',
        pow($kb, 2),
      ],
      [
        '1 GB',
        pow($kb, 3),
      ],
      [
        '1 TB',
        pow($kb, 4),
      ],
      [
        '1 PB',
        pow($kb, 5),
      ],
      [
        '1 EB',
        pow($kb, 6),
      ],
      [
        '1 ZB',
        pow($kb, 7),
      ],
      [
        '1 YB',
        pow($kb, 8),
      ],
      [
        '1024 YB',
        pow($kb, 9),
      ],
      // Rounded to 1 MB - not 1000 or 1024 kilobytes
[
        '1 MB',
        $kb * $kb - 1,
      ],
      [
        '-1 MB',
        -($kb * $kb - 1),
      ],
      // Decimal Megabytes
[
        '3.46 MB',
        3623651,
      ],
      [
        '3.77 GB',
        4053371676,
      ],
      // Decimal Petabytes
[
        '59.72 PB',
        67234178751368124,
      ],
      // Decimal Yottabytes
[
        '194.67 YB',
        2.3534682382112583E+26,
      ],
    ];
  }
  
  /**
   * @covers ::create
   */
  public function testTranslatableMarkupObject() : void {
    $result = ByteSizeMarkup::create(1, NULL, $this->getStringTranslationStub());
    $this->assertInstanceOf(PluralTranslatableMarkup::class, $result);
    $this->assertEquals("1 byte\x03@count bytes", $result->getUntranslatedString());
    $result = ByteSizeMarkup::create(1048576, 'fr', $this->getStringTranslationStub());
    $this->assertInstanceOf(TranslatableMarkup::class, $result);
    $this->assertEquals("@size MB", $result->getUntranslatedString());
    $this->assertEquals('fr', $result->getOption('langcode'));
  }
}Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides | 
|---|---|---|---|---|---|
| ByteSizeMarkupTest::providerTestCommonFormatSize | public static | function | Provides a list of byte size to test. | ||
| ByteSizeMarkupTest::testCommonFormatSize | public | function | @covers ::create[[api-linebreak]] @dataProvider providerTestCommonFormatSize | ||
| ByteSizeMarkupTest::testTranslatableMarkupObject | public | function | @covers ::create[[api-linebreak]] | ||
| PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | ||
| PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | ||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
| RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | |
| UnitTestCase::$root | protected | property | The app root. | 1 | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed 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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
| UnitTestCase::setUp | protected | function | 357 | ||
| UnitTestCase::setUpBeforeClass | public static | function | |||
| UnitTestCase::__get | public | function | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
