ParsingTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once('PHPUnit/Framework.php');
  3. //require_once('gettext.php');
  4. class ParsingTest extends PHPUnit_Framework_TestCase
  5. {
  6. public function test_extract_plural_forms_header_from_po_header()
  7. {
  8. $parser = new gettext_reader(NULL);
  9. // It defaults to a "Western-style" plural header.
  10. $this->assertEquals(
  11. 'nplurals=2; plural=n == 1 ? 0 : 1;',
  12. $parser->extract_plural_forms_header_from_po_header(""));
  13. // Extracting it from the middle of the header works.
  14. $this->assertEquals(
  15. 'nplurals=1; plural=0;',
  16. $parser->extract_plural_forms_header_from_po_header(
  17. "Content-type: text/html; charset=UTF-8\n"
  18. ."Plural-Forms: nplurals=1; plural=0;\n"
  19. ."Last-Translator: nobody\n"
  20. ));
  21. // It's also case-insensitive.
  22. $this->assertEquals(
  23. 'nplurals=1; plural=0;',
  24. $parser->extract_plural_forms_header_from_po_header(
  25. "PLURAL-forms: nplurals=1; plural=0;\n"
  26. ));
  27. // It falls back to default if it's not on a separate line.
  28. $this->assertEquals(
  29. 'nplurals=2; plural=n == 1 ? 0 : 1;',
  30. $parser->extract_plural_forms_header_from_po_header(
  31. "Content-type: text/html; charset=UTF-8" // note the missing \n here
  32. ."Plural-Forms: nplurals=1; plural=0;\n"
  33. ."Last-Translator: nobody\n"
  34. ));
  35. }
  36. /**
  37. * @dataProvider data_provider_test_npgettext
  38. */
  39. public function test_npgettext($number, $expected) {
  40. $parser = new gettext_reader(NULL);
  41. $result = $parser->npgettext("context",
  42. "%d pig went to the market\n",
  43. "%d pigs went to the market\n",
  44. $number);
  45. $this->assertSame($expected, $result);
  46. }
  47. public static function data_provider_test_npgettext() {
  48. return array(
  49. array(1, "%d pig went to the market\n"),
  50. array(2, "%d pigs went to the market\n"),
  51. );
  52. }
  53. }
  54. ?>