-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDomainHelperTest.php
More file actions
112 lines (104 loc) · 3.32 KB
/
Copy pathDomainHelperTest.php
File metadata and controls
112 lines (104 loc) · 3.32 KB
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
<?php
namespace Tests\Jobs;
use App\Helper\DomainHelper;
use Tests\TestCase;
class DomainHelperTest extends TestCase {
/**
* @return string[][]
*/
public static function provideUnicodeDomains(): array {
return [
'Example IDNA encoding' => [
'bücher.example',
'xn--bcher-kva.example',
],
'Example IDNA encoding #2 - Latin-1' => [
'então.carolinadoran.com',
'xn--ento-ioa.carolinadoran.com',
],
'Example IDNA encoding #3 - Greek' => [
'άλφα.wikibase.cloud',
'xn--hxak3a7b.wikibase.cloud',
],
'Example IDNA encoding #4 - Japanese' => [
'ドメイン名例.wikibase.cloud',
'xn--eckwd4c7cu47r2wf.wikibase.cloud',
],
'Example IDNA encoding #5 - Emoji' => [
'😃.wikibase.cloud',
'xn--h28h.wikibase.cloud',
],
'No double-encoding of "münchen.wikibase.cloud"' => [
'xn--mnchen-3ya.wikibase.cloud',
'xn--mnchen-3ya.wikibase.cloud',
],
'No double-encoding of "então.carolinadoran.com"' => [
'xn--ento-ioa.carolinadoran.com',
'xn--ento-ioa.carolinadoran.com',
],
'Output gets converted to lower case' => [
'EXAMPLE',
'example',
],
];
}
/**
* @return string[][]
*/
public static function provideAsciiDomains(): array {
return [
'Example IDNA decoding' => [
'xn--bcher-kva.example',
'bücher.example',
],
'Example IDNA decoding #2 - Latin-1' => [
'xn--ento-ioa.carolinadoran.com',
'então.carolinadoran.com',
],
'Example IDNA decoding #3 - Greek' => [
'xn--hxak3a7b.wikibase.cloud',
'άλφα.wikibase.cloud',
],
'Example IDNA decoding #4 - Japanese' => [
'xn--eckwd4c7cu47r2wf.wikibase.cloud',
'ドメイン名例.wikibase.cloud',
],
'Example IDNA decoding #5 - Emoji' => [
'xn--h28h.wikibase.cloud',
'😃.wikibase.cloud',
],
'Domain in unicode stays the same' => [
'münchen.wikibase.cloud',
'münchen.wikibase.cloud',
],
'Domain in unicode stays the same #2' => [
'então.carolinadoran.com',
'então.carolinadoran.com',
],
'Output gets converted to lower case' => [
'EXAMPLE',
'example',
],
];
}
/**
* @dataProvider provideUnicodeDomains
*/
public function testEncoding($input, $expectedOutput) {
$encoded = DomainHelper::encode($input);
$this->assertSame(
$encoded,
$expectedOutput
);
}
/**
* @dataProvider provideAsciiDomains
*/
public function testDecoding($input, $expectedOutput) {
$decoded = DomainHelper::decode($input);
$this->assertSame(
$decoded,
$expectedOutput
);
}
}