Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12741821
URLTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
URLTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Tests\HTTP
;
use
Keruald\OmniTools\HTTP\URL
;
use
PHPUnit\Framework\TestCase
;
class
URLTest
extends
TestCase
{
/**
* @dataProvider provideURLsAndComponents
*/
public
function
testGetDomain
(
$url
,
$expectedDomain
)
:
void
{
$url
=
new
URL
(
$url
);
$this
->
assertEquals
(
$expectedDomain
,
$url
->
getDomain
());
}
/**
* @dataProvider provideURLsAndComponents
*/
public
function
testGetProtocol
(
$url
,
$_
,
$expectedProtocol
)
:
void
{
$url
=
new
URL
(
$url
);
$this
->
assertEquals
(
$expectedProtocol
,
$url
->
getProtocol
());
}
/**
* @dataProvider provideURLsAndComponents
*/
public
function
testGetQuery
(
$url
,
$_
,
$__
,
$expectedQuery
)
:
void
{
$url
=
new
URL
(
$url
);
$this
->
assertEquals
(
$expectedQuery
,
$url
->
getQuery
());
}
public
function
testSetProtocol
()
:
void
{
$url
=
new
URL
(
"https://acme.tld/foo"
);
$url
->
setProtocol
(
"xizzy"
);
$this
->
assertEquals
(
"xizzy"
,
$url
->
getProtocol
());
}
public
function
testSetDomain
()
:
void
{
$url
=
new
URL
(
"https://acme.tld/foo"
);
$url
->
setDomain
(
"xizzy"
);
$this
->
assertEquals
(
"xizzy"
,
$url
->
getDomain
());
}
public
function
testSetQuery
()
:
void
{
$url
=
new
URL
(
"https://acme.tld/foo"
);
$url
->
setQuery
(
"/xizzy"
);
$this
->
assertEquals
(
"/xizzy"
,
$url
->
getQuery
());
}
public
function
testSetQueryWithSlashForgotten
()
:
void
{
$url
=
new
URL
(
"https://acme.tld/foo"
);
$url
->
setQuery
(
"xizzy"
);
$this
->
assertEquals
(
"/xizzy"
,
$url
->
getQuery
());
}
/**
* @dataProvider provideURLsAndComponents
*/
public
function
testCompose
(
$url
,
$domain
,
$protocol
,
$query
,
$expectedUrl
=
null
)
{
$this
->
assertEquals
(
$expectedUrl
??
$url
,
URL
::
compose
(
$protocol
,
$domain
,
$query
)->
__toString
()
);
}
public
function
provideURLsAndComponents
()
:
iterable
{
// base URL, domain, protocol, query[, expected URL]
// When omitted, the expected URL is the base URL.
yield
[
"http://foo/bar"
,
"foo"
,
"http"
,
"/bar"
];
yield
[
"https://xn--dghrefn-mxa.nasqueron.org/"
,
"dæghrefn.nasqueron.org"
,
"https"
,
"/"
];
yield
[
"://foo/bar"
,
"foo"
,
""
,
"/bar"
];
yield
[
"/bar"
,
""
,
""
,
"/bar"
];
yield
[
"http://foo/bar%20quux"
,
"foo"
,
"http"
,
"/bar quux"
];
yield
[
"https://foo/"
,
"foo"
,
"https"
,
"/"
];
yield
[
"https://foo"
,
"foo"
,
"https"
,
"/"
,
"https://foo/"
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 16, 13:34 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3142822
Default Alt Text
URLTest.php (2 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment