Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Test Uri\Rfc3986\UriBuilder basic - success - absolute URI with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setScheme('http')
->setHost('example.net')
->setPath('/newPath')
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('http://example.net/newPath', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(26) "http://example.net/newPath"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(4) "http"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.net"
["port"]=>
NULL
["path"]=>
string(8) "/newPath"
["query"]=>
NULL
["fragment"]=>
NULL
}
bool(true)
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Test Uri\Rfc3986\UriBuilder basic - success - empty relative reference with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(4) "user"
["password"]=>
string(4) "pass"
["host"]=>
string(11) "example.com"
["port"]=>
int(123)
["path"]=>
string(10) "/base/path"
["query"]=>
string(8) "oldQuery"
["fragment"]=>
NULL
}
bool(true)
bool(true)
37 changes: 37 additions & 0 deletions ext/uri/tests/rfc3986/builder/fragment_success_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setFragment() - success - empty string
--FILE--
<?php

$uri = new Uri\Rfc3986\UriBuilder()
->setFragment('')
->build();

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('#'), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(1) "#"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
NULL
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
NULL
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
string(0) ""
}
bool(true)
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setFragment() - success - empty string with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://example.com/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setFragment('')
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('#', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(39) "https://example.com/base/path?oldQuery#"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(10) "/base/path"
["query"]=>
string(8) "oldQuery"
["fragment"]=>
string(0) ""
}
bool(true)
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setFragment() - success - null with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setFragment('newFragment')
->setFragment(null) // confirm unset
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(4) "user"
["password"]=>
string(4) "pass"
["host"]=>
string(11) "example.com"
["port"]=>
int(123)
["path"]=>
string(10) "/base/path"
["query"]=>
string(8) "oldQuery"
["fragment"]=>
NULL
}
bool(true)
bool(true)
39 changes: 39 additions & 0 deletions ext/uri/tests/rfc3986/builder/fragment_success_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setFragment() - success - with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setFragment('newFragment')
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('#newFragment', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(64) "https://user:pass@example.com:123/base/path?oldQuery#newFragment"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(4) "user"
["password"]=>
string(4) "pass"
["host"]=>
string(11) "example.com"
["port"]=>
int(123)
["path"]=>
string(10) "/base/path"
["query"]=>
string(8) "oldQuery"
["fragment"]=>
string(11) "newFragment"
}
bool(true)
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setFragment() - success - with network-path reference
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setHost('example.net')
->setPath('/newPath')
->setFragment('newFragment')
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('//example.net/newPath#newFragment', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(39) "https://example.net/newPath#newFragment"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.net"
["port"]=>
NULL
["path"]=>
string(8) "/newPath"
["query"]=>
NULL
["fragment"]=>
string(11) "newFragment"
}
bool(true)
bool(true)
39 changes: 39 additions & 0 deletions ext/uri/tests/rfc3986/builder/host_success_empty_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setHost() - success - empty host with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setHost('')
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('//', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(8) "https://"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(0) ""
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
NULL
}
bool(true)
bool(true)
40 changes: 40 additions & 0 deletions ext/uri/tests/rfc3986/builder/host_success_null_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setHost() - success - null with base URI
--FILE--
<?php

$base = new Uri\Rfc3986\Uri('https://user:pass@example.com:123/base/path?oldQuery#oldFragment');

$uri = new Uri\Rfc3986\UriBuilder()
->setHost('example.net')
->setHost(null) // confirm unset
->build($base);

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));
var_dump($uri->equals(new Uri\Rfc3986\Uri('', $base), Uri\UriComparisonMode::IncludeFragment));

?>
--EXPECTF--
string(52) "https://user:pass@example.com:123/base/path?oldQuery"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(4) "user"
["password"]=>
string(4) "pass"
["host"]=>
string(11) "example.com"
["port"]=>
int(123)
["path"]=>
string(10) "/base/path"
["query"]=>
string(8) "oldQuery"
["fragment"]=>
NULL
}
bool(true)
bool(true)
Loading
Loading