Net_IDNA2Test.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. require_once 'Net/IDNA2.php';
  3. class Net_IDNA2Test extends PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * Initialise tests
  7. *
  8. * @return void
  9. */
  10. public function setUp()
  11. {
  12. $this->idn = new Net_IDNA2();
  13. }
  14. /**
  15. * Test if a complete URL consisting also of port-number etc. will be decoded just fine, test 1
  16. *
  17. * @return void
  18. */
  19. public function testShouldDecodePortNumbersFragmentsAndUrisCorrectly1()
  20. {
  21. $result = $this->idn->decode('http://www.xn--ml-6kctd8d6a.org:8080/test.php?arg1=1&arg2=2#fragment');
  22. $this->assertSame("http://www.\xD0\xB5\xD1\x85\xD0\xB0m\xD1\x80l\xD0\xB5.org:8080/test.php?arg1=1&arg2=2#fragment", $result);
  23. }
  24. /**
  25. * Test if a complete URL consisting also of port-number etc. will be decoded just fine, test 2
  26. *
  27. * @return void
  28. */
  29. public function testShouldDecodePortNumbersFragmentsAndUrisCorrectly2()
  30. {
  31. $result = $this->idn->decode('http://xn--tst-qla.example.com:8080/test.php?arg1=1&arg2=2#fragment');
  32. $this->assertSame("http://täst.example.com:8080/test.php?arg1=1&arg2=2#fragment", $result);
  33. }
  34. /**
  35. * Test encoding of German letter Eszett according to the original standard (IDNA2003)
  36. *
  37. * @return void
  38. */
  39. public function testEncodingForGermanEszettUsingIDNA2003()
  40. {
  41. // make sure to use 2003-encoding
  42. $this->idn->setParams('version', '2003');
  43. $result = $this->idn->encode('http://www.straße.example.com/');
  44. $this->assertSame("http://www.strasse.example.com/", $result);
  45. }
  46. /**
  47. * Test encoding of German letter Eszett according to the "new" standard (IDNA2005/IDNAbis)
  48. *
  49. * @return void
  50. */
  51. public function testEncodingForGermanEszettUsingIDNA2008()
  52. {
  53. // make sure to use 2008-encoding
  54. $this->idn->setParams('version', '2008');
  55. $result = $this->idn->encode('http://www.straße.example.com/');
  56. // switch back for other testcases
  57. $this->idn->setParams('version', '2003');
  58. $this->assertSame("http://www.xn--strae-oqa.example.com/", $result);
  59. }
  60. }