|
1
|
|
|
<?php |
|
2
|
|
|
class ar_urlTest extends AriadneBaseTest { |
|
3
|
|
|
|
|
4
|
|
|
function testparseUrl() |
|
5
|
|
|
{ |
|
6
|
|
|
$starturl = 'http://www.ariadne-cms.org/?frop=1'; |
|
7
|
|
|
$url = ar::url( $starturl ); |
|
8
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
9
|
|
|
$this->assertEquals( $starturl, ''.$url ); |
|
10
|
|
|
|
|
11
|
|
|
$starturl = 'http://www.ariadne-cms.org/?frop=1&frml=2'; |
|
12
|
|
|
$url = ar::url( $starturl ); |
|
13
|
|
|
$url->fragment = 'test123'; |
|
|
|
|
|
|
14
|
|
|
$this->assertEquals( $starturl .'#test123', ''.$url); |
|
15
|
|
|
|
|
16
|
|
|
$starturl = 'http://www.ariadne-cms.org/view.html?foo=some+thing'; |
|
17
|
|
|
$url = ar::url( $starturl ); |
|
18
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
19
|
|
|
$this->assertInstanceOf( 'ar_urlQuery', $url->query ); |
|
20
|
|
|
$this->assertEquals( $starturl, ''.$url ); |
|
21
|
|
|
$this->assertEquals( $url->query['foo'], 'some thing' ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
function testparseUrlQueryMultipleElements() |
|
25
|
|
|
{ |
|
26
|
|
|
$starturl = 'http://www.ariadne-cms.org/?test=test&test=frop'; |
|
27
|
|
|
$url = ar::url( $starturl ); |
|
28
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
29
|
|
|
$this->assertInstanceOf( 'ar_urlQuery', $url->query ); |
|
30
|
|
|
$this->assertEquals( 'frop', ''.$url->query['test'], "PHP url parser, the second instance has precedence"); |
|
31
|
|
|
$this->assertNotEquals( $starturl, ''.$url ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
function testparseUrlQueryUnnumberedElements() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$starturl = 'http://www.ariadne-cms.org/?test[]=test&test[]=frop'; |
|
37
|
|
|
$url = ar::url( $starturl ); |
|
38
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
39
|
|
|
$this->assertInstanceOf( 'ar_urlQuery', $url->query ); |
|
40
|
|
|
$this->assertEquals( ['test', 'frop'], $url->query['test'], "Auto indexed array from query"); |
|
41
|
|
|
$this->assertEquals( (string)$url, (string)ar::url($url) ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
function testparseUrlQueryNumberedElements() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$starturl = 'http://www.ariadne-cms.org/?test[1]=test&test[0]=frop'; |
|
47
|
|
|
$url = ar::url( $starturl ); |
|
48
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
49
|
|
|
$this->assertInstanceOf( 'ar_urlQuery', $url->query ); |
|
50
|
|
|
$this->assertEquals( ['frop', 'test'], $url->query['test'], "manual index array from query"); |
|
51
|
|
|
$this->assertEquals( (string)$url, (string)ar::url($url) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function testModQuery() |
|
55
|
|
|
{ |
|
56
|
|
|
$base = 'http://host/path/to?test='; |
|
57
|
|
|
$url = ar::url($base .'1'); |
|
58
|
|
|
$url->query['test'] = "3"; |
|
59
|
|
|
$this->assertEquals( $base .'3', (string)$url ); |
|
60
|
|
|
|
|
61
|
|
|
$url->query['test'] = ['foo', 'bar']; |
|
62
|
|
|
$this->assertEquals( 'http://host/path/to?test%5B0%5D=foo&test%5B1%5D=bar', (string)$url ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
function testParseAuthority() |
|
66
|
|
|
{ |
|
67
|
|
|
$starturl = 'http://foo:[email protected]:80/'; |
|
68
|
|
|
$url = ar::url( $starturl ); |
|
69
|
|
|
$this->assertInstanceOf( 'ar_url', $url ); |
|
70
|
|
|
$this->assertEquals( $starturl, $url.'' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function testCopyQuery() |
|
74
|
|
|
{ |
|
75
|
|
|
$url1 = ar::url('http://host/path/to?test=1'); |
|
76
|
|
|
$url2 = ar::url('http://host/path/to?test=2'); |
|
77
|
|
|
$this->assertNotEquals( $url1, $url2); |
|
78
|
|
|
|
|
79
|
|
|
$url2->query = $url1->query; |
|
|
|
|
|
|
80
|
|
|
$this->assertEquals( $url1, $url2); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function testCopyAndModQuery() |
|
84
|
|
|
{ |
|
85
|
|
|
$url1 = ar::url('http://host/path/to?test=1'); |
|
86
|
|
|
$url2 = ar::url('http://host/path/to?test=2'); |
|
87
|
|
|
$this->assertNotEquals( $url1, $url2); |
|
88
|
|
|
|
|
89
|
|
|
$url2->query = $url1->query; |
|
|
|
|
|
|
90
|
|
|
$this->assertEquals( $url1, $url2); |
|
91
|
|
|
|
|
92
|
|
|
$url2->query['test'] = '3'; |
|
93
|
|
|
$this->assertEquals( '3', $url2->query['test']); |
|
94
|
|
|
$this->assertEquals( '1', $url1->query['test']); |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
function testParseCommonURLS() |
|
100
|
|
|
{ |
|
101
|
|
|
$commonUrls = [ |
|
102
|
|
|
'ftp://ftp.is.co.za/rfc/rfc1808.txt', |
|
103
|
|
|
'http://www.ietf.org/rfc/rfc2396.txt', |
|
104
|
|
|
'ldap://[2001:db8::7]/c=GB?objectClass?one', |
|
105
|
|
|
'mailto:[email protected]', |
|
106
|
|
|
'news:comp.infosystems.www.servers.unix', |
|
107
|
|
|
'tel:+1-816-555-1212', |
|
108
|
|
|
'telnet://192.0.2.16:80/', |
|
109
|
|
|
'urn:oasis:names:specification:docbook:dtd:xml:4.1.2', |
|
110
|
|
|
'//google.com', |
|
111
|
|
|
'../../relative/', |
|
112
|
|
|
'file:///C:/' |
|
113
|
|
|
]; |
|
114
|
|
|
foreach ($commonUrls as $sourceUrl) { |
|
115
|
|
|
$url = ar::url( $sourceUrl ); |
|
116
|
|
|
$this->assertEquals( $sourceUrl, ''.$url ); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.