i18n.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class i18nTest extends PHPUnit_Framework_TestCase
  3. {
  4. private $_translations = array();
  5. public function setUp()
  6. {
  7. /* Setup Routine */
  8. $this->_translations = json_decode(
  9. file_get_contents(PATH . 'i18n' . DIRECTORY_SEPARATOR . 'de.json'),
  10. true
  11. );
  12. }
  13. public function tearDown()
  14. {
  15. /* Tear Down Routine */
  16. }
  17. public function testTranslationFallback()
  18. {
  19. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar';
  20. $messageId = 'It does not matter if the message ID exists';
  21. i18n::loadTranslations();
  22. $this->assertEquals($messageId, i18n::_($messageId), 'fallback to en');
  23. }
  24. public function testBrowserLanguageDetection()
  25. {
  26. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
  27. i18n::loadTranslations();
  28. $this->assertEquals($this->_translations['en'], i18n::_('en'), 'browser language de');
  29. }
  30. public function testVariableInjection()
  31. {
  32. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar';
  33. i18n::loadTranslations();
  34. $this->assertEquals('some string + 1', i18n::_('some %s + %d', 'string', 1), 'browser language de');
  35. }
  36. }