function PoHeaderTest::testPluralsFormula
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php \Drupal\Tests\Component\Gettext\PoHeaderTest::testPluralsFormula()
- 10 core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php \Drupal\Tests\Component\Gettext\PoHeaderTest::testPluralsFormula()
- 11.x 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 30
Class
- PoHeaderTest
- Unit tests for the Gettext PO file header handling features.
Namespace
Drupal\Tests\Component\GettextCode
public function testPluralsFormula($plural, $expected) {
$p = new PoHeader();
$parsed = $p->parsePluralForms($plural);
[
$nplurals,
$new_plural,
] = $parsed;
foreach ($expected as $number => $plural_form) {
$result = $new_plural[$number] ?? $new_plural['default'];
$this->assertEquals($result, $plural_form, 'Difference found at ' . $number . ': ' . $plural_form . ' versus ' . $result);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.