I18nTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
  2. /**
  3. * Tests Kohana i18n class
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.i18n
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. * @author Kohana Team
  12. * @author Jeremy Bush <[email protected]>
  13. * @copyright (c) 2008-2012 Kohana Team
  14. * @license http://kohanaframework.org/license
  15. */
  16. class Kohana_I18nTest extends Unittest_TestCase {
  17. /**
  18. * Default values for the environment, see setEnvironment
  19. * @var array
  20. */
  21. // @codingStandardsIgnoreStart
  22. protected $environmentDefault = array(
  23. 'I18n::$lang' => 'en-us',
  24. );
  25. // @codingStandardsIgnoreEnd
  26. /**
  27. * Provides test data for test_lang()
  28. *
  29. * @return array
  30. */
  31. public function provider_lang()
  32. {
  33. return array(
  34. // $input, $expected_result
  35. array(NULL, 'en-us'),
  36. array('es-es', 'es-es'),
  37. );
  38. }
  39. /**
  40. * Tests I18n::lang()
  41. *
  42. * @test
  43. * @dataProvider provider_lang
  44. * @param boolean $input Input for I18n::lang
  45. * @param boolean $expected Output for I18n::lang
  46. */
  47. public function test_lang($input, $expected_result)
  48. {
  49. $this->assertSame($expected_result, I18n::lang($input));
  50. $this->assertSame($expected_result, I18n::lang());
  51. }
  52. /**
  53. * Provides test data for test_get()
  54. *
  55. * @return array
  56. */
  57. public function provider_get()
  58. {
  59. return array(
  60. // $value, $result
  61. array('en-us', 'Hello, world!', 'Hello, world!'),
  62. array('es-es', 'Hello, world!', '¡Hola, mundo!'),
  63. array('fr-fr', 'Hello, world!', 'Bonjour, monde!'),
  64. );
  65. }
  66. /**
  67. * Tests i18n::get()
  68. *
  69. * @test
  70. * @dataProvider provider_get
  71. * @param boolean $input Input for File::mime
  72. * @param boolean $expected Output for File::mime
  73. */
  74. public function test_get($lang, $input, $expected)
  75. {
  76. I18n::lang($lang);
  77. $this->assertSame($expected, I18n::get($input));
  78. // Test immediate translation, issue #3085
  79. I18n::lang('en-us');
  80. $this->assertSame($expected, I18n::get($input, $lang));
  81. }
  82. }