You are here

public function PoHeaderTest::testPluralsFormula in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php \Drupal\Tests\Component\Gettext\PoHeaderTest::testPluralsFormula()

Tests that plural expressions are evaluated correctly.

Validate that the given plural expressions is evaluated with the correct plural formula.

@dataProvider providerTestPluralsFormula

Parameters

string $plural: The plural expression.

array $expected: Array of expected plural positions keyed by plural value.

File

core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php, line 35
Contains \Drupal\Tests\Component\Gettext\PoHeaderTest.

Class

PoHeaderTest
Unit tests for the Gettext PO file header handling features.

Namespace

Drupal\Tests\Component\Gettext

Code

public function testPluralsFormula($plural, $expected) {
  $p = new PoHeader();
  $parsed = $p
    ->parsePluralForms($plural);
  list($nplurals, $new_plural) = $parsed;
  foreach ($expected as $number => $plural_form) {
    $result = isset($new_plural[$number]) ? $new_plural[$number] : $new_plural['default'];
    $this
      ->assertEquals($result, $plural_form, 'Difference found at ' . $number . ': ' . $plural_form . ' versus ' . $result);
  }
}