Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / test / libraries / php-gettext / Parsing_test.php
blobc4fc4610594029e4c2508dc36ef058261a82baab
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for gettext parsing.
6 * @package phpMyAdmin-test
7 */
8 //require_once('gettext.php');
10 class ParsingTest extends PHPUnit_Framework_TestCase
12 public function test_extract_plural_forms_header_from_po_header()
14 $parser = new gettext_reader(NULL);
15 // It defaults to a "Western-style" plural header.
16 $this->assertEquals(
17 'nplurals=2; plural=n == 1 ? 0 : 1;',
18 $parser->extract_plural_forms_header_from_po_header(""));
20 // Extracting it from the middle of the header works.
21 $this->assertEquals(
22 'nplurals=1; plural=0;',
23 $parser->extract_plural_forms_header_from_po_header(
24 "Content-type: text/html; charset=UTF-8\n"
25 ."Plural-Forms: nplurals=1; plural=0;\n"
26 ."Last-Translator: nobody\n"
27 ));
29 // It's also case-insensitive.
30 $this->assertEquals(
31 'nplurals=1; plural=0;',
32 $parser->extract_plural_forms_header_from_po_header(
33 "PLURAL-forms: nplurals=1; plural=0;\n"
34 ));
36 // It falls back to default if it's not on a separate line.
37 $this->assertEquals(
38 'nplurals=2; plural=n == 1 ? 0 : 1;',
39 $parser->extract_plural_forms_header_from_po_header(
40 "Content-type: text/html; charset=UTF-8" // note the missing \n here
41 ."Plural-Forms: nplurals=1; plural=0;\n"
42 ."Last-Translator: nobody\n"
43 ));
46 /**
47 * @dataProvider data_provider_test_npgettext
49 public function test_npgettext($number, $expected) {
50 $parser = new gettext_reader(NULL);
51 $result = $parser->npgettext("context",
52 "%d pig went to the market\n",
53 "%d pigs went to the market\n",
54 $number);
55 $this->assertSame($expected, $result);
57 public static function data_provider_test_npgettext() {
58 return array(
59 array(1, "%d pig went to the market\n"),
60 array(2, "%d pigs went to the market\n"),