|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Apicart\Utils\Tests\Http; |
|
4
|
|
|
|
|
5
|
|
|
use Apicart\Utils\Http\Url; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class UrlTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
public const URL = 'https://user:[email protected]:1234/en/index.php?name=value#fragment'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var Url |
|
15
|
|
|
*/ |
|
16
|
|
|
private $url; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function setUp(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->url = new Url(self::URL); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
public function testToString(): void |
|
29
|
|
|
{ |
|
30
|
|
|
self::assertSame('https://www.apicart.net:1234/en/index.php?name=value#fragment', (string) $this->url); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function testGetScheme(): void |
|
35
|
|
|
{ |
|
36
|
|
|
self::assertSame('https', $this->url->getScheme()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function testGetUser(): void |
|
41
|
|
|
{ |
|
42
|
|
|
self::assertSame('user', $this->url->getUser()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testGetPassword(): void |
|
47
|
|
|
{ |
|
48
|
|
|
self::assertSame('password', $this->url->getPassword()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testGetHost(): void |
|
53
|
|
|
{ |
|
54
|
|
|
self::assertSame('www.apicart.net', $this->url->getHost()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function testGetDomain(): void |
|
59
|
|
|
{ |
|
60
|
|
|
self::assertSame('apicart.net', $this->url->getDomain()); |
|
61
|
|
|
self::assertSame('www.apicart.net', $this->url->getDomain(3)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testGetPort(): void |
|
66
|
|
|
{ |
|
67
|
|
|
self::assertSame(1234, $this->url->getPort()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testGetPath(): void |
|
72
|
|
|
{ |
|
73
|
|
|
self::assertSame('/en/index.php', $this->url->getPath()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
public function testGetQuery(): void |
|
78
|
|
|
{ |
|
79
|
|
|
self::assertSame('name=value', $this->url->getQuery()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function testGetQueryParameter(): void |
|
84
|
|
|
{ |
|
85
|
|
|
self::assertSame('value', $this->url->getQueryParameter('name')); |
|
86
|
|
|
self::assertSame('bar', $this->url->getQueryParameter('foo', 'bar')); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testGetFragment(): void |
|
91
|
|
|
{ |
|
92
|
|
|
self::assertSame('fragment', $this->url->getFragment()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
public function testGetAbsoluteUrl(): void |
|
97
|
|
|
{ |
|
98
|
|
|
self::assertSame('https://www.apicart.net:1234/en/index.php?name=value#fragment', $this->url->getAbsoluteUrl()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
public function testGetAuthority(): void |
|
103
|
|
|
{ |
|
104
|
|
|
self::assertSame('www.apicart.net:1234', $this->url->getAuthority()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
public function testGetHostUrl(): void |
|
109
|
|
|
{ |
|
110
|
|
|
self::assertSame('https://www.apicart.net:1234', $this->url->getHostUrl()); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
public function testGetBasePath(): void |
|
115
|
|
|
{ |
|
116
|
|
|
self::assertSame('/en/', $this->url->getBasePath()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
public function testGetBaseUrl(): void |
|
121
|
|
|
{ |
|
122
|
|
|
self::assertSame('https://www.apicart.net:1234/en/', $this->url->getBaseUrl()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
public function testGetRelativeUrl(): void |
|
127
|
|
|
{ |
|
128
|
|
|
self::assertSame('index.php?name=value#fragment', $this->url->getRelativeUrl()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
public function testIsEqual(): void |
|
133
|
|
|
{ |
|
134
|
|
|
self::assertTrue($this->url->isEqual(self::URL)); |
|
135
|
|
|
self::assertFalse($this->url->isEqual('http://apicart.net')); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function testJsonSerialize(): void |
|
140
|
|
|
{ |
|
141
|
|
|
$json = json_encode($this->url); |
|
142
|
|
|
self::assertSame('"https:\/\/www.apicart.net:1234\/en\/index.php?name=value#fragment"', $json); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|