3 namespace Drupal\Tests\Component\Gettext;
5 use Drupal\Component\Gettext\PoHeader;
6 use PHPUnit\Framework\TestCase;
9 * Unit tests for the Gettext PO file header handling features.
11 * @see Drupal\Component\Gettext\PoHeader.
15 class PoHeaderTest extends TestCase {
18 * Tests that plural expressions are evaluated correctly.
20 * Validate that the given plural expressions is evaluated with the correct
23 * @param string $plural
24 * The plural expression.
25 * @param array $expected
26 * Array of expected plural positions keyed by plural value.
28 * @dataProvider providerTestPluralsFormula
30 public function testPluralsFormula($plural, $expected) {
32 $parsed = $p->parsePluralForms($plural);
33 list($nplurals, $new_plural) = $parsed;
34 foreach ($expected as $number => $plural_form) {
35 $result = isset($new_plural[$number]) ? $new_plural[$number] : $new_plural['default'];
36 $this->assertEquals($result, $plural_form, 'Difference found at ' . $number . ': ' . $plural_form . ' versus ' . $result);
41 * Data provider for testPluralsFormula.
43 * Gets pairs of plural expressions and expected plural positions keyed by
47 * Pairs of plural expressions and expected plural positions keyed by plural
50 public function providerTestPluralsFormula() {
53 'nplurals=1; plural=0;',
57 'nplurals=2; plural=(n > 1);',
58 [0 => 0, 1 => 0, 'default' => 1],
61 'nplurals=2; plural=(n!=1);',
62 [1 => 0, 'default' => 1],
65 'nplurals=2; plural=(((n==1)||((n%10)==1))?(0):1);',
91 'nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
169 'nplurals=3; plural=((n==1)?(0):(((n>=2)&&(n<=4))?(1):2));',
179 'nplurals=3; plural=((n==1)?(0):(((n==0)||(((n%100)>0)&&((n%100)<20)))?(1):2));',
224 'nplurals=3; plural=((n==1)?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
285 'nplurals=4; plural=(((n==1)||(n==11))?(0):(((n==2)||(n==12))?(1):(((n>2)&&(n<20))?(2):3)));',
310 'nplurals=4; plural=(((n%100)==1)?(0):(((n%100)==2)?(1):((((n%100)==3)||((n%100)==4))?(2):3)));',
324 'nplurals=5; plural=((n==1)?(0):((n==2)?(1):((n<7)?(2):((n<11)?(3):4))));',
341 'nplurals=6; plural=((n==1)?(0):((n==0)?(1):((n==2)?(2):((((n%100)>=3)&&((n%100)<=10))?(3):((((n%100)>=11)&&((n%100)<=99))?(4):5)))));',