function TranslationManagerTest::providerTestFormatPlural

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php \Drupal\Tests\Core\StringTranslation\TranslationManagerTest::providerTestFormatPlural()
  2. 9 core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php \Drupal\Tests\Core\StringTranslation\TranslationManagerTest::providerTestFormatPlural()
  3. 8.9.x core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php \Drupal\Tests\Core\StringTranslation\TranslationManagerTest::providerTestFormatPlural()
  4. main core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php \Drupal\Tests\Core\StringTranslation\TranslationManagerTest::providerTestFormatPlural()

Provides some test data for formatPlural()

Return value

array An array of test data for formatPlural().

File

core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php, line 43

Class

TranslationManagerTest
Tests Drupal\Core\StringTranslation\TranslationManager.

Namespace

Drupal\Tests\Core\StringTranslation

Code

public static function providerTestFormatPlural() : array {
  return [
    [
      1,
      'Singular',
      '@count plural',
      [],
      [],
      'Singular',
    ],
    [
      2,
      'Singular',
      '@count plural',
      [],
      [],
      '2 plural',
    ],
    [
      2,
      'Singular',
      '@count @arg',
      [
        '@arg' => '<script>',
      ],
      [],
      '2 &lt;script&gt;',
    ],
    [
      2,
      'Singular',
      '@count %arg',
      [
        '%arg' => '<script>',
      ],
      [],
      '2 <em class="placeholder">&lt;script&gt;</em>',
    ],
    [
      1,
      'Singular',
      '@count plural',
      [],
      [
        'langcode' => NULL,
      ],
      'Singular',
    ],
    [
      1,
      'Singular',
      '@count plural',
      [],
      [
        'langcode' => 'es',
      ],
      'Singular',
    ],
    // The count is documented as int|float, and formatPlural() itself is not
    // typed, so callers also pass numeric strings. A count must never be
    // truncated for display, and only a count that is exactly one may use
    // the singular form. Both forms carry @count here, so that a wrongly
    // selected form and a truncated count are each visible in the result.
[
      1,
      '@count hour',
      '@count hours',
      [],
      [],
      '1 hour',
    ],
    [
      '1',
      '@count hour',
      '@count hours',
      [],
      [],
      '1 hour',
    ],
    [
      1.0,
      '@count hour',
      '@count hours',
      [],
      [],
      '1 hour',
    ],
    [
      '1.0',
      '@count hour',
      '@count hours',
      [],
      [],
      '1.0 hour',
    ],
    [
      2,
      '@count hour',
      '@count hours',
      [],
      [],
      '2 hours',
    ],
    [
      '2',
      '@count hour',
      '@count hours',
      [],
      [],
      '2 hours',
    ],
    [
      0.6,
      '@count hour',
      '@count hours',
      [],
      [],
      '0.6 hours',
    ],
    [
      '0.6',
      '@count hour',
      '@count hours',
      [],
      [],
      '0.6 hours',
    ],
    [
      1.5,
      '@count hour',
      '@count hours',
      [],
      [],
      '1.5 hours',
    ],
    [
      '1.5',
      '@count hour',
      '@count hours',
      [],
      [],
      '1.5 hours',
    ],
    [
      -1.5,
      '@count hour',
      '@count hours',
      [],
      [],
      '-1.5 hours',
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.