forked from appwrite/appwrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathURLTest.php
More file actions
106 lines (86 loc) · 3.06 KB
/
Copy pathURLTest.php
File metadata and controls
106 lines (86 loc) · 3.06 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
<?php
namespace Appwrite\Tests;
use Appwrite\URL\URL;
use PHPUnit\Framework\TestCase;
class URLTest extends TestCase
{
public function testParse()
{
$url = URL::parse('https://appwrite.io:8080/path?query=string¶m=value');
$this->assertIsArray($url);
$this->assertEquals('https', $url['scheme']);
$this->assertEquals('appwrite.io', $url['host']);
$this->assertEquals('8080', $url['port']);
$this->assertEquals('/path', $url['path']);
$this->assertEquals('query=string¶m=value', $url['query']);
$url = URL::parse('https://appwrite.io');
$this->assertIsArray($url);
$this->assertEquals('https', $url['scheme']);
$this->assertEquals('appwrite.io', $url['host']);
$this->assertEquals(null, $url['port']);
$this->assertEquals('', $url['path']);
$this->assertEquals('', $url['query']);
}
public function testUnparse()
{
$url = URL::unparse([
'scheme' => 'https',
'host' => 'appwrite.io',
'port' => 8080,
'path' => '/path',
'query' => 'query=string¶m=value',
]);
$this->assertIsString($url);
$this->assertEquals('https://appwrite.io:8080/path?query=string¶m=value', $url);
$url = URL::unparse([
'scheme' => 'https',
'host' => 'appwrite.io',
'port' => null,
'path' => '/path',
'query' => 'query=string¶m=value',
]);
$this->assertIsString($url);
$this->assertEquals('https://appwrite.io/path?query=string¶m=value', $url);
$url = URL::unparse([
'scheme' => 'https',
'host' => 'appwrite.io',
'port' => null,
'path' => '',
'query' => '',
]);
$this->assertIsString($url);
$this->assertEquals('https://appwrite.io/', $url);
$url = URL::unparse([
'scheme' => 'https',
'host' => 'appwrite.io',
'port' => null,
'path' => '',
'fragment' => 'bottom',
]);
$this->assertIsString($url);
$this->assertEquals('https://appwrite.io/#bottom', $url);
$url = URL::unparse([
'scheme' => 'https',
'user' => 'eldad',
'pass' => 'fux',
'host' => 'appwrite.io',
'port' => null,
'path' => '',
'fragment' => 'bottom',
]);
$this->assertIsString($url);
}
public function testParseQuery()
{
$result = URL::parseQuery('param1=value1¶m2=value2');
$this->assertIsArray($result);
$this->assertEquals(['param1' => 'value1', 'param2' => 'value2'], $result);
}
public function testUnParseQuery()
{
$result = URL::unparseQuery(['param1' => 'value1', 'param2' => 'value2']);
$this->assertIsString($result);
$this->assertEquals('param1=value1¶m2=value2', $result);
}
}