LocaleTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Html2Pdf Library - Tests
  4. *
  5. * HTML => PDF converter
  6. * distributed under the OSL-3.0 License
  7. *
  8. * @package Html2pdf
  9. * @author Laurent MINGUET <webmaster@html2pdf.fr>
  10. * @copyright 2023 Laurent MINGUET
  11. */
  12. namespace Spipu\Html2Pdf\Tests;
  13. use PHPUnit_Framework_TestCase;
  14. use Spipu\Html2Pdf\Locale;
  15. use Spipu\Html2Pdf\Exception\LocaleException;
  16. /**
  17. * Class LocaleTest
  18. */
  19. class LocaleTest extends PHPUnit_Framework_TestCase
  20. {
  21. /**
  22. * test bad code
  23. *
  24. * @return void
  25. */
  26. public function testBadCode()
  27. {
  28. $this->expectException(LocaleException::class);
  29. Locale::clean();
  30. try {
  31. Locale::load('$aa');
  32. } catch (LocaleException $e) {
  33. $this->assertSame('$aa', $e->getLocalCode());
  34. throw $e;
  35. }
  36. }
  37. /**
  38. * test unknown code
  39. *
  40. * @return void
  41. */
  42. public function testUnknownCode()
  43. {
  44. $this->expectException(LocaleException::class);
  45. Locale::clean();
  46. try {
  47. Locale::load('aa');
  48. } catch (LocaleException $e) {
  49. $this->assertSame('aa', $e->getLocalCode());
  50. throw $e;
  51. }
  52. }
  53. /**
  54. * test good code
  55. *
  56. * @return void
  57. */
  58. public function testGoodCode()
  59. {
  60. Locale::clean();
  61. Locale::load('en');
  62. $this->assertSame('Page [[page_cu]]/[[page_nb]]', Locale::get('pdf04'));
  63. $this->assertSame('bad_return', Locale::get('bad_code', 'bad_return'));
  64. Locale::clean();
  65. $this->assertSame('bad_return', Locale::get('pdf04', 'bad_return'));
  66. }
  67. }