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