1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
<?php
namespace Algo26\IdnaConvert\Test\integration;
use Algo26\IdnaConvert\Exception\InvalidCharacterException;
use Algo26\IdnaConvert\Exception\InvalidIdnVersionException;
use Algo26\IdnaConvert\ToUnicode;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
#[CoversClass('\Algo26\IdnaConvert\ToUnicode')]
class ToUnicodeTest extends TestCase
{
/**
* @throws InvalidIdnVersionException
*/
#[DataProvider('providerUtf8')]
public function testDecodeUtf8($encoded, $expectDecoded)
{
$idnaConvert = new ToUnicode();
$encoded = $idnaConvert->convert($encoded);
$this->assertEquals(
$expectDecoded,
$encoded,
sprintf(
'Strings "%s" and "%s" do not match',
$expectDecoded,
$encoded
)
);
}
#[DataProvider('providerException')]
public function testDecodeUtf8Exception($encoded)
{
self::expectException(InvalidCharacterException::class);
$idnaConvert = new ToUnicode();
$idnaConvert->convert($encoded);
}
/**
* @throws InvalidIdnVersionException
*/
#[DataProvider('providerEmailAddress')]
public function testDecodeEmailAddress($encoded, $expectDecoded)
{
$idnaConvert = new ToUnicode();
$encoded = $idnaConvert->convertEmailAddress($encoded);
$this->assertEquals(
$expectDecoded,
$encoded,
sprintf(
'Strings "%s" and "%s" do not match',
$expectDecoded,
$encoded
)
);
}
/**
* @throws InvalidIdnVersionException
*/
#[DataProvider('providerUrl')]
public function testDecodeUrl($encoded, $expectDecoded)
{
$idnaConvert = new ToUnicode();
$encoded = $idnaConvert->convertUrl($encoded);
$this->assertEquals(
$expectDecoded,
$encoded,
sprintf(
'Strings "%s" and "%s" do not match',
$expectDecoded,
$encoded
)
);
}
/**
* @return array
*/
public static function providerUtf8(): array
{
return [
['xn--mller-kva', 'müller'],
['xn--weienbach-i1a', 'weißenbach'],
['xn----9mcj9fole', 'يوم-جيد'],
['xn----2hckbod3a', 'יום-טוב'],
['xn--idndomainaouexample-owb39ane.example', 'idndomainäaöoüuexample.example'],
['xn--ko-eka.example', 'öko.example'],
['xn--6ca0bl71b4a.example', 'æšŧüø.example'],
['xn--4cabegsede9b0e.example', 'ìåíèäæìúíò.example'],
['xn--d1abegsede9b0e.example', 'мениджмънт.example'],
['3+1', '3+1'],
['www.xn--bckermller-q5a70a.example', 'www.bäckermüller.example'],
['xn--cfa', 'ı'],
['xn--ekiszlk-d1a0dy4d', 'ekşisözlük'],
['xn--rdetforstrrefrdselssikkerhed-znc6bz8b', 'rådetforstørrefærdselssikkerhed'],
['xn--kakavalc-0kb76b.example', 'kaşkavalcı.example'],
['xn--uxan.example', 'πι.example'],
['xn--ksigowo-c5a1nq1a.example', 'księgowość.example'],
['xn--80aebfcdsb1blidpdoq4e1i.example', 'регистрациядоменов.example'],
['xn--eqr31enth05q.xn--55qx5d', '国际域名.公司'],
['xn--1caqmypyo.example', 'áéíóöúü.example'],
['xn--1caqmypyo29d8i.example', 'áéíóöőúüű.example'],
['xn--vk1bq81c.example', '대출.example'],
['xn--t-mfutbzh', 'tシャツ'],
['www.xn--clcul3aaa2lcuc4kf.example', 'www.குண்டுபாப்பா.example'],
['xn--3e0b707e', '한국'],
['xn--xu5bx2sncw5i.example', '파티하임.example'],
['xn--o39aa', '가가'],
['xn----5gc8bsteqom5gm.xn--5dbik1ed.xn--9dbalbu5cfl', 'מילון-ראשׁי.תיבות.וקיצורים'],
['xn--rjajzusknak-r7a3h5b', 'írjajézuskának'],
['xn--q3cq3aix1l2a', 'น้ําหอม'],
['xn--q3ca5bk4b5k', 'สํานวน'],
['xn--chambres-dhtes-bpb.example', 'chambres-dhôtes.example'],
['xn--72cba0e8bxb3cu4kb6d6b.example', 'น้ําใสใจจริง.example'],
['xn--bren-mgen-fsse-5hb70axd.example', 'bären-mögen-füsse.example'],
['xn--da-hia.example', 'daß.example'],
['xn--dmin-moa0i.example', 'dömäin.example'],
['xn--aaa-pla.example', 'äaaa.example'],
['xn--aaa-qla.example', 'aäaa.example'],
['xn--aaa-rla.example', 'aaäa.example'],
['xn--aaa-sla.example', 'aaaä.example'],
['xn--dj-kia8a.vu.example', 'déjà.vu.example'],
['xn--efran-2sa.example', 'efraín.example'],
['xn--and-6ma2c.example', 'ñandú.example'],
['foo.xn--bcdf-9na9b.example', 'foo.âbcdéf.example'],
['xn--4gbrim.xn----ymcbaaajlc6dj7bxne2c.xn--wgbh1c', 'موقع.وزارة-الاتصالات.مصر'],
['xn--fuball-cta.example', 'fußball.example'],
['xn--18-uldcat6ad6bydd', 'היפא18פאטאם'],
['xn--18-dtd1bdi0h3ask', 'فرس18النهر'],
];
}
public static function providerException(): array
{
return [
['xn--style-321'],
['xn--54_461_1'],
['xn--54_52932'],
['xn--54?312'],
['xn--250[143'],
['xn--250;143'],
["xn--9\n1595402"],
['xn--898:0106'],
['xn--algo26'],
['xn--algo26-cc'],
];
}
public static function providerEmailAddress(): array
{
return [
['some.user@xn--d1abegsede9b0e.example', 'some.user@мениджмънт.example'],
['some.user@xn--uxan.example', 'some.user@πι.example'],
['söme.üser@xn--da-hia.example', 'söme.üser@daß.example'],
['some.user@foo.xn--bcdf-9na9b.example', 'some.user@foo.âbcdéf.example'],
];
}
public static function providerUrl(): array
{
return [
[
'https://user:password@xn--d1abegsede9b0e.example/home/international/test.html',
'https://user:password@мениджмънт.example/home/international/test.html',
],
[
'https://üser:päßword@xn--uxan.example/gnörz/lörz/',
'https://üser:päßword@πι.example/gnörz/lörz/',
],
[
'https://user:password@xn--da-hia.example/',
'https://user:password@daß.example/',
],
[
'https://user:password@foo.xn--bcdf-9na9b.example',
'https://user:password@foo.âbcdéf.example',
],
[
'http://xn--and-6ma2c.example',
'http://ñandú.example',
],
[
'file:///some/path/xn--somewhere/',
'file:///some/path/xn--somewhere/',
],
];
}
}
|