diff --git a/ext/uri/tests/004.phpt b/ext/uri/tests/004.phpt deleted file mode 100644 index a7c2e190683a..000000000000 --- a/ext/uri/tests/004.phpt +++ /dev/null @@ -1,83 +0,0 @@ ---TEST-- -Parse invalid URLs ---FILE-- -getMessage() . "\n"; -} - -var_dump(Uri\WhatWg\Url::parse("")); - -var_dump(Uri\Rfc3986\Uri::parse("192.168/contact.html")); -var_dump(Uri\WhatWg\Url::parse("192.168/contact.html", null)); - -var_dump(Uri\Rfc3986\Uri::parse("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's")); -var_dump(Uri\WhatWg\Url::parse("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's", null)); - -?> ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - NULL - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - NULL - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -The specified URI is malformed (MissingSchemeNonRelativeUrl) -NULL -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - NULL - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(20) "192.168/contact.html" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -NULL -NULL -NULL diff --git a/ext/uri/tests/006.phpt b/ext/uri/tests/006.phpt deleted file mode 100644 index e7fa79a8b837..000000000000 --- a/ext/uri/tests/006.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -Test successful manual Uri child instance creation ---FILE-- - ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - string(8) "username" - ["password"]=> - string(8) "password" - ["host"]=> - string(11) "example.com" - ["port"]=> - int(8080) - ["path"]=> - string(5) "/path" - ["query"]=> - string(3) "q=r" - ["fragment"]=> - string(8) "fragment" -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - string(8) "username" - ["password"]=> - string(8) "password" - ["host"]=> - string(11) "example.com" - ["port"]=> - int(8080) - ["path"]=> - string(5) "/path" - ["query"]=> - string(3) "q=r" - ["fragment"]=> - string(8) "fragment" -} diff --git a/ext/uri/tests/007.phpt b/ext/uri/tests/007.phpt deleted file mode 100644 index db051e553fb1..000000000000 --- a/ext/uri/tests/007.phpt +++ /dev/null @@ -1,68 +0,0 @@ ---TEST-- -Test URI creation errors ---FILE-- -getMessage() . "\n"; -} - -try { - new Uri\WhatWg\Url("https://example.com:8080@username:password/path?q=r#fragment"); -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; - var_dump($e->errors); -} - -$failures = []; -$url = new Uri\WhatWg\Url(" https://example.org ", null, $failures); -var_dump($url->toAsciiString()); -var_dump($failures); - -?> ---EXPECTF-- -The specified URI is malformed -The specified URI is malformed (PortInvalid) -array(%d) { - [0]=> - object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(26) "password/path?q=r#fragment" - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::PortInvalid) - ["failure"]=> - bool(true) - } - [1]=> - object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(36) "@username:password/path?q=r#fragment" - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::InvalidCredentials) - ["failure"]=> - bool(false) - } -} -string(20) "https://example.org/" -array(2) { - [0]=> - object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(1) " " - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit) - ["failure"]=> - bool(false) - } - [1]=> - object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(21) " https://example.org " - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit) - ["failure"]=> - bool(false) - } -} diff --git a/ext/uri/tests/012.phpt b/ext/uri/tests/012.phpt deleted file mode 100644 index e033223a6426..000000000000 --- a/ext/uri/tests/012.phpt +++ /dev/null @@ -1,85 +0,0 @@ ---TEST-- -Test parsing of various schemes ---FILE-- - ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - string(6) "mailto" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(15) "Joe@Example.COM" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(6) "mailto" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(15) "Joe@Example.COM" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - string(4) "file" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(0) "" - ["port"]=> - NULL - ["path"]=> - string(30) "/E:/Documents%20and%20Settings" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(4) "file" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(0) "" - ["port"]=> - NULL - ["path"]=> - string(30) "/E:/Documents%20and%20Settings" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/014.phpt b/ext/uri/tests/014.phpt deleted file mode 100644 index 2966e2a9dcf1..000000000000 --- a/ext/uri/tests/014.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Test recomposition of URIs ---FILE-- -toRawString()); - -var_dump(Uri\WhatWg\Url::parse("http://example.com?foo=Hell%C3%B3+W%C3%B6rld")->toAsciiString()); - -?> ---EXPECT-- -string(44) "http://example.com?foo=Hell%C3%B3+W%C3%B6rld" -string(45) "http://example.com/?foo=Hell%C3%B3+W%C3%B6rld" diff --git a/ext/uri/tests/015.phpt b/ext/uri/tests/015.phpt deleted file mode 100644 index cf6c09703d2e..000000000000 --- a/ext/uri/tests/015.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Test instantiation without calling constructor ---EXTENSIONS-- -reflection -uri ---FILE-- -newInstanceWithoutConstructor(); -} catch (ReflectionException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $reflectionClass = new ReflectionClass(Uri\WhatWg\Url::class); - $reflectionClass->newInstanceWithoutConstructor(); -} catch (ReflectionException $e) { - echo $e->getMessage() . "\n"; -} - -?> ---EXPECT-- -Class Uri\Rfc3986\Uri is an internal class marked as final that cannot be instantiated without invoking its constructor -Class Uri\WhatWg\Url is an internal class marked as final that cannot be instantiated without invoking its constructor diff --git a/ext/uri/tests/018.phpt b/ext/uri/tests/018.phpt deleted file mode 100644 index 7a7be9b3c19f..000000000000 --- a/ext/uri/tests/018.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Test property mutation ---FILE-- - ---EXPECTF-- -object(Uri\Rfc3986\Uri)#1 (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\Rfc3986\Uri)#2 (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#3 (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(1) "/" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#4 (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(1) "/" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/023.phpt b/ext/uri/tests/023.phpt deleted file mode 100644 index d52fa3405322..000000000000 --- a/ext/uri/tests/023.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -Test property mutation - scheme ---FILE-- -getRawScheme()); -var_dump($uri1->getScheme()); - -$uri2 = $uri1->withScheme("http"); -var_dump($uri2->getRawScheme()); -var_dump($uri2->getScheme()); - -$uri3 = $uri2->withScheme(null); -var_dump($uri3->getRawScheme()); -var_dump($uri3->getScheme()); - -try { - $uri3->withScheme(""); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri3->withScheme("http%73"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = Uri\WhatWg\Url::parse("https://example.com"); -$url2 = $url1->withScheme("http"); - -var_dump($url1->getScheme()); -var_dump($url2->getScheme()); - -try { - $url2->withScheme(""); -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $url2->withScheme("http%73"); -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -?> ---EXPECT-- -string(5) "https" -string(5) "https" -string(4) "http" -string(4) "http" -NULL -NULL -The specified scheme is malformed -The specified scheme is malformed -string(5) "https" -string(4) "http" -The specified scheme is malformed -The specified scheme is malformed diff --git a/ext/uri/tests/024.phpt b/ext/uri/tests/024.phpt deleted file mode 100644 index 4147ff3ae124..000000000000 --- a/ext/uri/tests/024.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Test property mutation - username ---FILE-- -withUsername("user"); -$url3 = $url2->withUsername(null); -$url4 = $url3->withUsername("%75s%2Fr"); // us/r -$url5 = $url4->withUsername("u:s/r"); - -$url6 = Uri\WhatWg\Url::parse("file:///foo/bar/"); -$url6 = $url6->withUsername("user"); - -var_dump($url2->getUsername()); -var_dump($url3->getUsername()); -var_dump($url4->getUsername()); -var_dump($url5->getUsername()); -var_dump($url6->getUsername()); - -?> ---EXPECT-- -string(4) "user" -NULL -string(8) "%75s%2Fr" -string(9) "u%3As%2Fr" -NULL diff --git a/ext/uri/tests/025.phpt b/ext/uri/tests/025.phpt deleted file mode 100644 index a6dd505fcca1..000000000000 --- a/ext/uri/tests/025.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Test property mutation - password ---FILE-- -withPassword("pass"); -$url3 = $url2->withPassword(null); -$url4 = $url3->withPassword("p%61ss"); -$url5 = $url4->withPassword("p:s/"); - -$url6 = Uri\WhatWg\Url::parse("file:///foo/bar/"); -$url6 = $url6->withUsername("pass"); - -var_dump($url2->getPassword()); -var_dump($url3->getPassword()); -var_dump($url4->getPassword()); -var_dump($url5->getPassword()); -var_dump($url6->getPassword()); - -?> ---EXPECT-- -string(4) "pass" -NULL -string(6) "p%61ss" -string(8) "p%3As%2F" -NULL diff --git a/ext/uri/tests/026.phpt b/ext/uri/tests/026.phpt deleted file mode 100644 index e46c30055cb6..000000000000 --- a/ext/uri/tests/026.phpt +++ /dev/null @@ -1,137 +0,0 @@ ---TEST-- -Test property mutation - host ---FILE-- -getRawHost()); -var_dump($uri1->getHost()); - -$uri2 = $uri1->withHost("test.com"); -var_dump($uri2->getRawHost()); -var_dump($uri2->getHost()); - -$uri3 = $uri2->withHost("t%65st.com"); // test.com -var_dump($uri3->getRawHost()); -var_dump($uri3->getHost()); - -$uri4 = $uri3->withHost(null); -var_dump($uri4->getRawHost()); -var_dump($uri4->getHost()); - -$uri5 = $uri4->withHost("192.168.0.1"); -var_dump($uri5->getRawHost()); -var_dump($uri5->getHost()); - -$uri6 = $uri5->withHost("[2001:db8:3333:4444:5555:6666:7777:8888]"); -var_dump($uri6->getRawHost()); -var_dump($uri6->getHost()); - -try { - $uri3->withHost("test.com:8080"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri3->withHost("t%3As%2Ft.com"); // t:s/t.com -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri3->withHost("t:s/t.com"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri2->withHost(""); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$uri1 = Uri\Rfc3986\Uri::parse("ftp://user:pass@foo.com?query=abc#foo"); -$uri2 = $uri1->withHost("test.com"); - -var_dump($uri1->getHost()); -var_dump($uri2->getHost()); - -try { - $uri1->withHost(null); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = Uri\WhatWg\Url::parse("https://example.com"); -$url2 = $url1->withHost("test.com"); -$url3 = $url2->withHost("t%65st.com"); // test.com -$url4 = $url3->withHost("192.168.0.1"); -$url5 = $url4->withHost("[2001:db8:3333:4444:5555:6666:7777:8888]"); - -var_dump($url1->getAsciiHost()); -var_dump($url2->getAsciiHost()); -var_dump($url3->getAsciiHost()); -var_dump($url4->getAsciiHost()); -var_dump($url5->getAsciiHost()); - -try { - $url3->withHost("test.com:8080"); -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $url3->withHost("t%3As%2Ft.com"); // t:s/t.com -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $url3->withHost("t:s/t.com"); // t:s/t.com -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $url2->withHost(null); -} catch (Uri\WhatWg\InvalidUrlException $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = Uri\WhatWg\Url::parse("ftp://foo.com?query=abc#foo"); -$url2 = $url1->withHost("test.com"); - -var_dump($url1->getAsciiHost()); -var_dump($url2->getAsciiHost()); - -?> ---EXPECTF-- -string(11) "example.com" -string(11) "example.com" -string(8) "test.com" -string(8) "test.com" -string(10) "t%65st.com" -string(8) "test.com" -NULL -NULL -string(11) "192.168.0.1" -string(11) "192.168.0.1" -string(40) "[2001:db8:3333:4444:5555:6666:7777:8888]" -string(40) "[2001:db8:3333:4444:5555:6666:7777:8888]" -The specified host is malformed -The specified host is malformed -string(7) "foo.com" -string(8) "test.com" -Cannot remove the host from a URI that has a userinfo -string(11) "example.com" -string(8) "test.com" -string(8) "test.com" -string(11) "192.168.0.1" -string(40) "[2001:db8:3333:4444:5555:6666:7777:8888]" -The specified host is malformed -The specified host is malformed (DomainInvalidCodePoint) -The specified host is malformed -The specified host is malformed (HostMissing) -string(7) "foo.com" -string(8) "test.com" diff --git a/ext/uri/tests/026_userinfo.phpt b/ext/uri/tests/026_userinfo.phpt deleted file mode 100644 index cff2665803a4..000000000000 --- a/ext/uri/tests/026_userinfo.phpt +++ /dev/null @@ -1,51 +0,0 @@ ---TEST-- -Test property mutation - userinfo ---FILE-- -getRawUserInfo()); -var_dump($uri1->getUserInfo()); - -$uri2 = $uri1->withUserInfo("user"); -var_dump($uri2->getRawUserInfo()); -var_dump($uri2->getUserInfo()); - -$uri3 = $uri2->withUserInfo(null); -var_dump($uri3->getRawUserInfo()); -var_dump($uri3->getUserInfo()); - -$uri4 = $uri3->withUserInfo("%75s%2Fr:pass"); // us/r:pass -var_dump($uri4->getRawUserInfo()); -var_dump($uri4->getUserInfo()); - -$uri1 = Uri\Rfc3986\Uri::parse("/foo"); -$uri2 = $uri1->withUserInfo(null); -var_dump($uri2->getPort()); - -try { - $uri4->withUserInfo("u:s/r"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$uri5 = Uri\Rfc3986\Uri::parse("file:///foo/bar/"); -$uri6 = $uri5->withUserinfo("user:pass"); - -var_dump($uri5->getUserInfo()); -var_dump($uri6->getUserInfo()); - -?> ---EXPECT-- -NULL -NULL -string(4) "user" -string(4) "user" -NULL -NULL -string(13) "%75s%2Fr:pass" -string(11) "us%2Fr:pass" -NULL -The specified userinfo is malformed -NULL -string(9) "user:pass" diff --git a/ext/uri/tests/027.phpt b/ext/uri/tests/027.phpt deleted file mode 100644 index 334d67aa0bb6..000000000000 --- a/ext/uri/tests/027.phpt +++ /dev/null @@ -1,73 +0,0 @@ ---TEST-- -Test property mutation - port ---FILE-- -withPort(22); -$uri3 = $uri2->withPort(null); - -var_dump($uri1->getPort()); -var_dump($uri2->getPort()); -var_dump($uri3->getPort()); - -$uri1 = Uri\Rfc3986\Uri::parse("ftp://foo.com:443?query=abc#foo"); -$uri2 = $uri1->withPort(8080); - -var_dump($uri1->getPort()); -var_dump($uri2->getPort()); - -$uri1 = Uri\Rfc3986\Uri::parse("file:///foo/bar"); -$uri2 = $uri1->withPort(80); - -var_dump($uri1->getPort()); -var_dump($uri2->getPort()); - -$uri1 = Uri\Rfc3986\Uri::parse("/foo"); -$uri2 = $uri1->withPort(null); -var_dump($uri2->getPort()); - -try { - $uri1->withPort(1); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = Uri\WhatWg\Url::parse("https://example.com:8080"); -$url2 = $url1->withPort(22); -$url3 = $url2->withPort(null); - -var_dump($url1->getPort()); -var_dump($url2->getPort()); -var_dump($url3->getPort()); - -$url1 = Uri\WhatWg\Url::parse("ftp://foo.com:443?query=abc#foo"); -$url2 = $url1->withPort(8080); - -var_dump($url1->getPort()); -var_dump($url2->getPort()); - -$url1 = Uri\WhatWg\Url::parse("file:///foo/bar"); -$url2 = $url1->withPort(80); - -var_dump($url1->getPort()); -var_dump($url2->getPort()); - -?> ---EXPECT-- -int(8080) -int(22) -NULL -int(443) -int(8080) -NULL -int(80) -NULL -Cannot set a port without having a host -int(8080) -int(22) -NULL -int(443) -int(8080) -NULL -NULL diff --git a/ext/uri/tests/028.phpt b/ext/uri/tests/028.phpt deleted file mode 100644 index cfc11b331c8e..000000000000 --- a/ext/uri/tests/028.phpt +++ /dev/null @@ -1,87 +0,0 @@ ---TEST-- -Test property mutation - path ---FILE-- -getRawPath()); -var_dump($uri1->getPath()); - -$uri2 = $uri1->withPath("/foo"); -var_dump($uri2->getRawPath()); -var_dump($uri2->getPath()); - -$uri3 = $uri2->withPath("/t%65st"); -var_dump($uri3->getRawPath()); -var_dump($uri3->getPath()); - -$uri4 = $uri3->withPath("/foo%2Fbar"); -var_dump($uri4->getRawPath()); -var_dump($uri4->getPath()); - -$uri5 = $uri4->withPath(""); -var_dump($uri5->getRawPath()); -var_dump($uri5->getPath()); - -try { - $uri5->withPath("test"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri5->withPath("/#"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$uri1 = Uri\Rfc3986\Uri::parse("/foo"); -$uri2 = $uri1->withPath("bar"); - -var_dump($uri1->getPath()); -var_dump($uri2->getPath()); - -$url1 = Uri\WhatWg\Url::parse("https://example.com/foo/bar/"); -$url2 = $url1->withPath("/foo"); -$url3 = $url2->withPath(""); -$url4 = $url3->withPath("t%65st"); -$url5 = $url4->withPath("/foo%2Fbar"); -$url6 = $url5->withPath("/#"); - -var_dump($url1->getPath()); -var_dump($url2->getPath()); -var_dump($url3->getPath()); -var_dump($url4->getPath()); -var_dump($url5->getPath()); -var_dump($url6->getPath()); - -$url1 = Uri\WhatWg\Url::parse("https://example.com/"); -$uri2 = $url1->withPath("/foo"); - -var_dump($url1->getPath()); -var_dump($url2->getPath()); - -?> ---EXPECT-- -string(9) "/foo/bar/" -string(9) "/foo/bar/" -string(4) "/foo" -string(4) "/foo" -string(7) "/t%65st" -string(5) "/test" -string(10) "/foo%2Fbar" -string(10) "/foo%2Fbar" -string(0) "" -string(0) "" -The specified path is malformed -The specified path is malformed -string(4) "/foo" -string(3) "bar" -string(9) "/foo/bar/" -string(4) "/foo" -string(1) "/" -string(7) "/t%65st" -string(10) "/foo%2Fbar" -string(4) "/%23" -string(1) "/" -string(4) "/foo" diff --git a/ext/uri/tests/029.phpt b/ext/uri/tests/029.phpt deleted file mode 100644 index 4936cb60db87..000000000000 --- a/ext/uri/tests/029.phpt +++ /dev/null @@ -1,93 +0,0 @@ ---TEST-- -Test property mutation - query ---FILE-- -getRawQuery()); -var_dump($uri1->getQuery()); - -$uri2 = $uri1->withQuery("foo=baz"); -var_dump($uri2->getRawQuery()); -var_dump($uri2->getQuery()); - -$uri3 = $uri2->withQuery(null); -var_dump($uri3->getRawQuery()); -var_dump($uri3->getQuery()); - -$uri1 = Uri\Rfc3986\Uri::parse("https://example.com"); -var_dump($uri1->getRawQuery()); -var_dump($uri1->getQuery()); - -$uri2 = $uri1->withQuery("?foo=bar&foo=baz"); -var_dump($uri2->getRawQuery()); -var_dump($uri2->getQuery()); - -$uri3 = $uri1->withQuery("foo=bar&foo=baz"); -var_dump($uri3->getRawQuery()); -var_dump($uri3->getQuery()); - -$uri4 = $uri3->withQuery("t%65st"); -var_dump($uri4->getRawQuery()); -var_dump($uri4->getQuery()); - -$uri5 = $uri4->withQuery("foo=foo%26bar&baz=/qux%3D"); -var_dump($uri5->getRawQuery()); -var_dump($uri5->getQuery()); - -try { - $uri5->withQuery("#"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = Uri\WhatWg\Url::parse("https://example.com?foo=bar"); -$url2 = $url1->withQuery("?foo=baz"); -$url3 = $url2->withQuery(null); - -var_dump($url1->getQuery()); -var_dump($url2->getQuery()); -var_dump($url3->getQuery()); - -$url1 = Uri\WhatWg\Url::parse("https://example.com"); -$url2 = $url1->withQuery("?foo=bar&foo=baz"); -$url3 = $url1->withQuery("foo=bar&foo=baz"); -$url4 = $url3->withQuery("t%65st"); -$url5 = $url4->withQuery("foo=foo%26bar&baz=/qux%3D"); -$url6 = $url5->withQuery("#"); - -var_dump($url1->getQuery()); -var_dump($url2->getQuery()); -var_dump($url3->getQuery()); -var_dump($url4->getQuery()); -var_dump($url5->getQuery()); -var_dump($url6->getQuery()); - -?> ---EXPECT-- -string(7) "foo=bar" -string(7) "foo=bar" -string(7) "foo=baz" -string(7) "foo=baz" -NULL -NULL -NULL -NULL -string(16) "?foo=bar&foo=baz" -string(16) "?foo=bar&foo=baz" -string(15) "foo=bar&foo=baz" -string(15) "foo=bar&foo=baz" -string(6) "t%65st" -string(4) "test" -string(25) "foo=foo%26bar&baz=/qux%3D" -string(25) "foo=foo%26bar&baz=/qux%3D" -The specified query is malformed -string(7) "foo=bar" -string(7) "foo=baz" -NULL -NULL -string(15) "foo=bar&foo=baz" -string(15) "foo=bar&foo=baz" -string(6) "t%65st" -string(25) "foo=foo%26bar&baz=/qux%3D" -string(3) "%23" diff --git a/ext/uri/tests/030.phpt b/ext/uri/tests/030.phpt deleted file mode 100644 index 03ed763f7795..000000000000 --- a/ext/uri/tests/030.phpt +++ /dev/null @@ -1,69 +0,0 @@ ---TEST-- -Test property mutation - fragment ---FILE-- -getRawFragment()); -var_dump($uri1->getFragment()); - -$uri2 = $uri1->withFragment("fragment2"); -var_dump($uri2->getRawFragment()); -var_dump($uri2->getFragment()); - -$uri3 = $uri2->withFragment(null); -var_dump($uri3->getRawFragment()); -var_dump($uri3->getFragment()); - -try { - $uri3->withFragment(" "); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -try { - $uri1->withFragment("#fragment2"); -} catch (Uri\InvalidUriException $e) { - echo $e->getMessage() . "\n"; -} - -$uri1 = Uri\Rfc3986\Uri::parse("https://example.com?abc=def"); -$uri2 = $uri1->withFragment("fragment"); - -var_dump($uri1->getFragment()); -var_dump($uri2->getFragment()); - -$url1 = Uri\WhatWg\Url::parse("https://example.com#fragment1"); -$url2 = $url1->withFragment("#fragment2"); -$url3 = $url2->withFragment(null); -$url4 = $url3->withFragment(" "); - -var_dump($url1->getFragment()); -var_dump($url2->getFragment()); -var_dump($url3->getFragment()); -var_dump($url4->getFragment()); - -$url1 = Uri\WhatWg\Url::parse("https://example.com?abc=def"); -$url2 = $url1->withFragment("#fragment"); - -var_dump($url1->getFragment()); -var_dump($url2->getFragment()); - -?> ---EXPECT-- -string(9) "fragment1" -string(9) "fragment1" -string(9) "fragment2" -string(9) "fragment2" -NULL -NULL -The specified fragment is malformed -The specified fragment is malformed -NULL -string(8) "fragment" -string(9) "fragment1" -string(9) "fragment2" -NULL -string(3) "%20" -NULL -string(8) "fragment" diff --git a/ext/uri/tests/031.phpt b/ext/uri/tests/031.phpt deleted file mode 100644 index d3cc926b82fa..000000000000 --- a/ext/uri/tests/031.phpt +++ /dev/null @@ -1,178 +0,0 @@ ---TEST-- -Test serialization and unserialization ---FILE-- -getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":3:{i:0;a:0:{}i:1;a:0:{}i:2;a:0:{}}'); // more than 2 items -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;N;i:1;a:0:{}}'); // first item is not an array -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:0:{}i:1;a:0:{}}'); // first array is empty -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";i:1;}i:1;a:0:{}}'); // "uri" key in first array is not a string -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:2:"%1";}i:1;a:0:{}}'); // "uri" key in first array contains invalid URI -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:4:"/uri";}i:1;s:0:"";}'); // second item in not an array -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:4:"/uri";}i:1;a:1:{s:5:"prop1";i:123;}}'); // second array contains a property -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -$url1 = new Uri\WhatWg\Url("https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); -$serializedUrl1 = serialize($url1); -$url2 = unserialize($serializedUrl1); - -var_dump($serializedUrl1); -var_dump($url2); - -try { - unserialize('O:14:"Uri\WhatWg\Url":1:{i:0;a:0:{}}'); // less than 2 items -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":3:{i:0;a:0:{}i:1;a:0:{}i:2;a:0:{}}'); // more than 2 items -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;N;i:1;a:0:{}}'); // first item is not an array -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:0:{}i:1;a:0:{}}'); // first array is empty -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:2:{s:3:"uri";s:19:"https://example.com";s:1:"a";i:1;}i:1;a:0:{}}'); // "uri" key in first array contains more than 1 item -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:1:{s:3:"uri";i:1;}i:1;a:0:{}}'); // "uri" key in first array is not a string -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:1:{s:3:"uri";s:11:"invalid-url";}i:1;a:0:{}}'); // "uri" key in first array contains invalid URL -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:1:{s:3:"uri";s:19:"https://example.com";}i:1;s:0:"";}'); // second item in not an array -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -try { - unserialize('O:14:"Uri\WhatWg\Url":2:{i:0;a:1:{s:3:"uri";s:19:"https://example.com";}i:1;a:1:{s:5:"prop1";i:123;}}'); // second array contains property -} catch (Exception $e) { - echo $e->getMessage() . "\n"; -} - -?> ---EXPECTF-- -string(164) "O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:99:"https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists";}i:1;a:0:{}}" -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - string(8) "username" - ["password"]=> - string(8) "password" - ["host"]=> - string(15) "www.example.com" - ["port"]=> - int(8080) - ["path"]=> - string(30) "/pathname1/pathname2/pathname3" - ["query"]=> - string(10) "query=true" - ["fragment"]=> - string(11) "hash-exists" -} -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -Invalid serialization data for Uri\Rfc3986\Uri object -string(163) "O:14:"Uri\WhatWg\Url":2:{i:0;a:1:{s:3:"uri";s:99:"https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists";}i:1;a:0:{}}" -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - string(8) "username" - ["password"]=> - string(8) "password" - ["host"]=> - string(15) "www.example.com" - ["port"]=> - int(8080) - ["path"]=> - string(30) "/pathname1/pathname2/pathname3" - ["query"]=> - string(10) "query=true" - ["fragment"]=> - string(11) "hash-exists" -} -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object -Invalid serialization data for Uri\WhatWg\Url object diff --git a/ext/uri/tests/041.phpt b/ext/uri/tests/041.phpt deleted file mode 100644 index 59a8e3211f97..000000000000 --- a/ext/uri/tests/041.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -Test relative URI parsing ---FILE-- - ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - NULL - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - string(5) "query" - ["fragment"]=> - string(8) "fragment" -} -NULL -array(%d) { - [0]=> - object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(15) "?query#fragment" - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::MissingSchemeNonRelativeUrl) - ["failure"]=> - bool(true) - } -} diff --git a/ext/uri/tests/042.phpt b/ext/uri/tests/042.phpt deleted file mode 100644 index aadb9e5c192f..000000000000 --- a/ext/uri/tests/042.phpt +++ /dev/null @@ -1,48 +0,0 @@ ---TEST-- -Test URN parsing ---FILE-- - ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { - ["scheme"]=> - string(3) "urn" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(41) "uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(3) "urn" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - NULL - ["port"]=> - NULL - ["path"]=> - string(41) "uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/045.phpt b/ext/uri/tests/045.phpt deleted file mode 100644 index f968716f9fcd..000000000000 --- a/ext/uri/tests/045.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Test percent-decoding of reserved characters in the path ---FILE-- -toRawString()); -var_dump($uri->getPath()); -var_dump($uri->getRawPath()); - -$url = new Uri\Whatwg\Url("https://example.com/foo/bar%2Fbaz"); - -var_dump($url->toAsciiString()); -var_dump($url->getPath()); - -?> ---EXPECT-- -string(33) "https://example.com/foo/bar%2Fbaz" -string(14) "/foo/bar%2Fbaz" -string(14) "/foo/bar%2Fbaz" -string(33) "https://example.com/foo/bar%2Fbaz" -string(14) "/foo/bar%2Fbaz" diff --git a/ext/uri/tests/050.phpt b/ext/uri/tests/050.phpt deleted file mode 100644 index 3bd4052fb80c..000000000000 --- a/ext/uri/tests/050.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Test resolve() method - success cases ---FILE-- -resolve("/foo/")->toString()); -var_dump($uri->resolve("https://test.com/foo")->toString()); - -$url = new Uri\WhatWg\Url("https://example.com"); - -var_dump($url->resolve("/foo/")->toAsciiString()); -var_dump($url->resolve("https://test.com/foo")->toAsciiString()); - -?> ---EXPECTF-- -string(24) "https://example.com/foo/" -string(20) "https://test.com/foo" -string(24) "https://example.com/foo/" -string(20) "https://test.com/foo" diff --git a/ext/uri/tests/052.phpt b/ext/uri/tests/052.phpt deleted file mode 100644 index 3d8d2053f6e8..000000000000 --- a/ext/uri/tests/052.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Test UrlValidationError constructor error handling ---FILE-- -__construct('bar', Uri\WhatWg\UrlValidationErrorType::HostMissing, false); -} catch (Error $e) { - echo $e->getMessage() . "\n"; -} - -var_dump($r); - -?> ---EXPECTF-- -Cannot modify readonly property Uri\WhatWg\UrlValidationError::$context -object(Uri\WhatWg\UrlValidationError)#%d (%d) { - ["context"]=> - string(3) "foo" - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::DomainInvalidCodePoint) - ["failure"]=> - bool(true) -} diff --git a/ext/uri/tests/054.phpt b/ext/uri/tests/054.phpt deleted file mode 100644 index 757b21cc114a..000000000000 --- a/ext/uri/tests/054.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Test UrlValidationErrorType singleton ---FILE-- -getMessage() . "\n"; - var_dump($e->errors[0]->type === \Uri\WhatWg\UrlValidationErrorType::PortOutOfRange); -} - -?> ---EXPECT-- -The specified URI is malformed (PortOutOfRange) -bool(true) diff --git a/ext/uri/tests/055.phpt b/ext/uri/tests/055.phpt deleted file mode 100644 index de240bb6e053..000000000000 --- a/ext/uri/tests/055.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Test InvalidUrlException constructor error handling ---FILE-- -getMessage() . "\n"; -} -?> ---EXPECT-- -The specified base URI must be absolute diff --git a/ext/uri/tests/059.phpt b/ext/uri/tests/059.phpt deleted file mode 100644 index 23971cd4ebe0..000000000000 --- a/ext/uri/tests/059.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Test empty ports become null ---FILE-- -getPort()); - -?> ---EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (8) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -NULL diff --git a/ext/uri/tests/065.phpt b/ext/uri/tests/065.phpt deleted file mode 100644 index 2c84cceea3d4..000000000000 --- a/ext/uri/tests/065.phpt +++ /dev/null @@ -1,115 +0,0 @@ ---TEST-- -Test that overwriting the URI is not possible ---FILE-- -__construct('ftp://example.org'); -} catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; -} -var_dump($uri); - -$uri = new Uri\WhatWg\Url('https://example.com'); -try { - $uri->__unserialize([['uri' => 'ftp://example.org'], []]); -} catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; -} -var_dump($uri); - -$uri = new Uri\Rfc3986\Uri('https://example.com'); -try { - $uri->__construct('ftp://example.org'); -} catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; -} -var_dump($uri); - -$uri = new Uri\Rfc3986\Uri('https://example.com'); -try { - $uri->__unserialize([['uri' => 'ftp://example.org'], []]); -} catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; -} -var_dump($uri); - -?> ---EXPECTF-- -Error: Cannot modify readonly object of class Uri\WhatWg\Url -object(Uri\WhatWg\Url)#%d (8) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(1) "/" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -Exception: Invalid serialization data for Uri\WhatWg\Url object -object(Uri\WhatWg\Url)#%d (8) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(1) "/" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -Error: Cannot modify readonly object of class Uri\Rfc3986\Uri -object(Uri\Rfc3986\Uri)#%d (8) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -Exception: Invalid serialization data for Uri\Rfc3986\Uri object -object(Uri\Rfc3986\Uri)#%d (8) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(0) "" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/101.phpt b/ext/uri/tests/101.phpt deleted file mode 100644 index daa83e45c9f8..000000000000 --- a/ext/uri/tests/101.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -Test the Lexbor-based URI parser ---EXTENSIONS-- -zend_test ---FILE-- -getMessage(), PHP_EOL; - var_dump($e->errors); -} - -?> ---EXPECTF-- -The specified URI is malformed (MissingSchemeNonRelativeUrl) -array(1) { - [0]=> - object(Uri\WhatWg\UrlValidationError)#%d (3) { - ["context"]=> - string(11) "invalid uri" - ["type"]=> - enum(Uri\WhatWg\UrlValidationErrorType::MissingSchemeNonRelativeUrl) - ["failure"]=> - bool(true) - } -} diff --git a/ext/uri/tests/gh19780.phpt b/ext/uri/tests/gh19780.phpt deleted file mode 100644 index fffa25bc37d2..000000000000 --- a/ext/uri/tests/gh19780.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -GH-19780 (InvalidUrlException should check $errors argument) ---FILE-- -getMessage(), "\n"; -} - -try { - new InvalidUrlException('message', [ - 1 => new UrlValidationError('context', UrlValidationErrorType::HostMissing, true) - ]); -} catch (ValueError $e) { - echo $e->getMessage(), "\n"; -} - -?> ---EXPECT-- -Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError -Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError diff --git a/ext/uri/tests/gh22046.phpt b/ext/uri/tests/gh22046.phpt deleted file mode 100644 index af297905aa30..000000000000 --- a/ext/uri/tests/gh22046.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -GH-22046: The unserialize function can lead to segfault when internal classes are serialized back with the unsupported C format ---FILE-- - ---EXPECTF-- -Warning: Class Uri\WhatWg\Url has no unserializer in %s on line %d - -Warning: unserialize(): Error at offset 25 of 26 bytes in %s on line %d - -Warning: Class Uri\Rfc3986\Uri has no unserializer in %s on line %d - -Warning: unserialize(): Error at offset 26 of 27 bytes in %s on line %d diff --git a/ext/uri/tests/rfc3986/builder/build_error_invalid_internal_components.phpt b/ext/uri/tests/rfc3986/builder/build_error_invalid_internal_components.phpt new file mode 100644 index 000000000000..3d580983e012 --- /dev/null +++ b/ext/uri/tests/rfc3986/builder/build_error_invalid_internal_components.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test Uri\Rfc3986\UriBuilder::build() rejects invalid internal component values +--EXTENSIONS-- +reflection +--FILE-- + ':', + 'host' => '[', + 'query' => '<', + 'fragment' => '<', +] as $property => $value) { + + $builder = new Uri\Rfc3986\UriBuilder(); + new ReflectionProperty($builder, $property)->setValue($builder, $value); + + try { + $builder->build(); + } catch (Throwable $e) { + echo $property, ': ', $e::class, ': ', $e->getMessage(), "\n"; + } +} + +?> +--EXPECT-- +scheme: Uri\InvalidUriException: The specified scheme is malformed +host: Uri\InvalidUriException: The specified host is malformed +query: Uri\InvalidUriException: The specified query is malformed +fragment: Uri\InvalidUriException: The specified fragment is malformed diff --git a/ext/uri/tests/rfc3986/builder/host_success_empty.phpt b/ext/uri/tests/rfc3986/builder/host_success_empty.phpt new file mode 100644 index 000000000000..3d97e1ebbb06 --- /dev/null +++ b/ext/uri/tests/rfc3986/builder/host_success_empty.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test Uri\Rfc3986\UriBuilder::setHost() - success - empty host creates empty authority +--FILE-- +setHost('')->build(); + +var_dump($uri->getHost()); +var_dump($uri->toRawString()); + +?> +--EXPECT-- +string(0) "" +string(2) "//" diff --git a/ext/uri/tests/rfc3986/builder/referenced_property_success.phpt b/ext/uri/tests/rfc3986/builder/referenced_property_success.phpt new file mode 100644 index 000000000000..19bd85c63691 --- /dev/null +++ b/ext/uri/tests/rfc3986/builder/referenced_property_success.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test Uri\Rfc3986\UriBuilder::build() with shared property values +--FILE-- +build()->toRawString()); + +?> +--EXPECT-- +string(30) "https://example.com/path#/path" diff --git a/ext/uri/tests/008.phpt b/ext/uri/tests/rfc3986/getters/basic_success.phpt similarity index 62% rename from ext/uri/tests/008.phpt rename to ext/uri/tests/rfc3986/getters/basic_success.phpt index 0a02bae63163..4e90c98007cb 100644 --- a/ext/uri/tests/008.phpt +++ b/ext/uri/tests/rfc3986/getters/basic_success.phpt @@ -1,5 +1,5 @@ --TEST-- -Test Uri getters +Test Uri\Rfc3986\Uri component retrieval - basic --FILE-- getRawFragment()); } -function callWhatWgGetters($url) -{ - var_dump($url->getScheme()); - var_dump($url->getUsername()); - var_dump($url->getPassword()); - var_dump($url->getAsciiHost()); - var_dump($url->getUnicodeHost()); - var_dump($url->getPort()); - var_dump($url->getPath()); - var_dump($url->getQuery()); - var_dump($url->getFragment()); -} - $uri = Uri\Rfc3986\Uri::parse("https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); callRfc3986Getters($uri); -echo "\n"; - -$url = Uri\WhatWg\Url::parse("https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); -callWhatWgGetters($url); - ?> --EXPECT-- string(5) "https" @@ -64,13 +46,3 @@ string(10) "query=true" string(10) "query=true" string(11) "hash-exists" string(11) "hash-exists" - -string(5) "https" -string(8) "username" -string(8) "password" -string(15) "www.example.com" -string(15) "www.example.com" -int(8080) -string(30) "/pathname1/pathname2/pathname3" -string(10) "query=true" -string(11) "hash-exists" diff --git a/ext/uri/tests/039.phpt b/ext/uri/tests/rfc3986/getters/percent_encoded_components.phpt similarity index 61% rename from ext/uri/tests/039.phpt rename to ext/uri/tests/rfc3986/getters/percent_encoded_components.phpt index ae662dfd1722..3b0ae568fa2c 100644 --- a/ext/uri/tests/039.phpt +++ b/ext/uri/tests/rfc3986/getters/percent_encoded_components.phpt @@ -1,5 +1,5 @@ --TEST-- -Test percent-encoding of different URI components +Test Uri\Rfc3986\Uri component retrieval - percent-encoded components --FILE-- getRawFragment()); } -function callWhatWgGetters($url) -{ - var_dump($url->getScheme()); - var_dump($url->getUsername()); - var_dump($url->getPassword()); - var_dump($url->getAsciiHost()); - var_dump($url->getUnicodeHost()); - var_dump($url->getPort()); - var_dump($url->getPath()); - var_dump($url->getQuery()); - var_dump($url->getFragment()); -} - $uri = Uri\Rfc3986\Uri::parse("http://%61pple:p%61ss@ex%61mple.com/foob%61r?%61bc=%61bc#%61bc"); callRfc3986Getters($uri); -echo "\n"; - -$url = Uri\WhatWg\Url::parse("http://%61pple:p%61ss@ex%61mple.com/foob%61r?%61bc=%61bc#%61bc"); -callWhatWgGetters($url); - ?> --EXPECT-- string(4) "http" @@ -64,13 +46,3 @@ string(7) "abc=abc" string(11) "%61bc=%61bc" string(3) "abc" string(5) "%61bc" - -string(4) "http" -string(7) "%61pple" -string(6) "p%61ss" -string(11) "example.com" -string(11) "example.com" -NULL -string(9) "/foob%61r" -string(11) "%61bc=%61bc" -string(5) "%61bc" diff --git a/ext/uri/tests/rfc3986/getters/userinfo_without_password_separator.phpt b/ext/uri/tests/rfc3986/getters/userinfo_without_password_separator.phpt new file mode 100644 index 000000000000..1b6638a158c6 --- /dev/null +++ b/ext/uri/tests/rfc3986/getters/userinfo_without_password_separator.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\Rfc3986\Uri userinfo without a password separator +--FILE-- +getUserInfo()); +var_dump($uri->getUsername()); +var_dump($uri->getPassword()); + +?> +--EXPECT-- +string(4) "user" +string(4) "user" +string(0) "" diff --git a/ext/uri/tests/rfc3986/modification/host_error_unset_with_port.phpt b/ext/uri/tests/rfc3986/modification/host_error_unset_with_port.phpt new file mode 100644 index 000000000000..280f556d4c31 --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/host_error_unset_with_port.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - host - unsetting with port +--FILE-- +withHost(null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: Cannot remove the host from a URI that has a port diff --git a/ext/uri/tests/rfc3986/modification/host_error_unset_with_userinfo.phpt b/ext/uri/tests/rfc3986/modification/host_error_unset_with_userinfo.phpt new file mode 100644 index 000000000000..dd3a527ff9ed --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/host_error_unset_with_userinfo.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - host - unsetting with userinfo +--FILE-- +withHost(null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: Cannot remove the host from a URI that has a userinfo diff --git a/ext/uri/tests/rfc3986/modification/host_success_ipv4_to_ipv6.phpt b/ext/uri/tests/rfc3986/modification/host_success_ipv4_to_ipv6.phpt new file mode 100644 index 000000000000..b91cefeb087d --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/host_success_ipv4_to_ipv6.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - host - changing IPv4 to IPv6 +--FILE-- +withHost(null); +$uri3 = $uri2->withHost("192.168.0.1"); +$uri4 = $uri3->withHost("[2001:db8:3333:4444:5555:6666:7777:8888]"); + +var_dump($uri3->getRawHost()); +var_dump($uri3->getHost()); +var_dump($uri4->getRawHost()); +var_dump($uri4->getHost()); + +?> +--EXPECT-- +string(11) "192.168.0.1" +string(11) "192.168.0.1" +string(40) "[2001:db8:3333:4444:5555:6666:7777:8888]" +string(40) "[2001:db8:3333:4444:5555:6666:7777:8888]" diff --git a/ext/uri/tests/rfc3986/modification/host_success_percent_encoded_reserved.phpt b/ext/uri/tests/rfc3986/modification/host_success_percent_encoded_reserved.phpt new file mode 100644 index 000000000000..26f12942ef42 --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/host_success_percent_encoded_reserved.phpt @@ -0,0 +1,10 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - host - URL encoded reserved characters +--FILE-- +withHost("t%3As%2Ft.com"); + +?> +--EXPECT-- diff --git a/ext/uri/tests/rfc3986/modification/port_error_missing_host.phpt b/ext/uri/tests/rfc3986/modification/port_error_missing_host.phpt new file mode 100644 index 000000000000..51ab43185a4b --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/port_error_missing_host.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - port - missing host +--FILE-- +withPort(1); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: Cannot set a port without having a host diff --git a/ext/uri/tests/rfc3986/modification/port_success_empty_host.phpt b/ext/uri/tests/rfc3986/modification/port_success_empty_host.phpt new file mode 100644 index 000000000000..91fc56fc488f --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/port_success_empty_host.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - port - adding with an empty host +--FILE-- +withPort(80); + +var_dump($uri1->getPort()); +var_dump($uri2->getPort()); + +?> +--EXPECT-- +NULL +int(80) diff --git a/ext/uri/tests/rfc3986/modification/port_success_unset_without_host.phpt b/ext/uri/tests/rfc3986/modification/port_success_unset_without_host.phpt new file mode 100644 index 000000000000..6d5ead807167 --- /dev/null +++ b/ext/uri/tests/rfc3986/modification/port_success_unset_without_host.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test Uri\Rfc3986\Uri component modification - port - unsetting without a host +--FILE-- +withPort(null); + +var_dump($uri2->getPort()); + +?> +--EXPECT-- +NULL diff --git a/ext/uri/tests/rfc3986/parsing/basic_error_relative_base.phpt b/ext/uri/tests/rfc3986/parsing/basic_error_relative_base.phpt new file mode 100644 index 000000000000..26c947a50afc --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/basic_error_relative_base.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing with a relative base URI +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: The specified base URI must be absolute diff --git a/ext/uri/tests/rfc3986/parsing/basic_error_returns_null.phpt b/ext/uri/tests/rfc3986/parsing/basic_error_returns_null.phpt new file mode 100644 index 000000000000..ff4ec9db11a0 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/basic_error_returns_null.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test Uri\Rfc3986\Uri::parse() returns null for a malformed URI +--FILE-- + +--EXPECT-- +NULL +NULL diff --git a/ext/uri/tests/rfc3986/parsing/basic_success_constructor.phpt b/ext/uri/tests/rfc3986/parsing/basic_success_constructor.phpt new file mode 100644 index 000000000000..6a873419e631 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/basic_success_constructor.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test Uri\Rfc3986\Uri construction - basic - success +--FILE-- + +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(5) "https" + ["username"]=> + string(8) "username" + ["password"]=> + string(8) "password" + ["host"]=> + string(11) "example.com" + ["port"]=> + int(8080) + ["path"]=> + string(5) "/path" + ["query"]=> + string(3) "q=r" + ["fragment"]=> + string(8) "fragment" +} diff --git a/ext/uri/tests/021.phpt b/ext/uri/tests/rfc3986/parsing/extension_error.phpt similarity index 100% rename from ext/uri/tests/021.phpt rename to ext/uri/tests/rfc3986/parsing/extension_error.phpt diff --git a/ext/uri/tests/047.phpt b/ext/uri/tests/rfc3986/parsing/host_success_ip_addresses.phpt similarity index 63% rename from ext/uri/tests/047.phpt rename to ext/uri/tests/rfc3986/parsing/host_success_ip_addresses.phpt index de9a21efd9b0..f9dae8a376d6 100644 --- a/ext/uri/tests/047.phpt +++ b/ext/uri/tests/rfc3986/parsing/host_success_ip_addresses.phpt @@ -1,5 +1,5 @@ --TEST-- -Test IP addresses +Test Uri\Rfc3986\Uri parsing - host - IP addresses --FILE-- getHost()); var_dump($uri->toRawString()); var_dump($uri->toString()); -$url = new Uri\WhatWg\Url("https://192.168.0.1"); -var_dump($url->getAsciiHost()); -var_dump($url->toAsciiString()); - -$url = new Uri\WhatWg\Url("https://[2001:0db8:0001:0000:0000:0ab9:C0A8:0102]"); -var_dump($url->getAsciiHost()); -var_dump($url->toAsciiString()); - -$url = new Uri\WhatWg\Url("https://[0:0::1]"); -var_dump($url->getAsciiHost()); -var_dump($url->toAsciiString()); - ?> --EXPECT-- string(11) "192.168.0.1" @@ -47,9 +35,3 @@ string(9) "[v7.host]" string(9) "[v7.host]" string(18) "//[v7.host]/source" string(18) "//[v7.host]/source" -string(11) "192.168.0.1" -string(20) "https://192.168.0.1/" -string(26) "[2001:db8:1::ab9:c0a8:102]" -string(35) "https://[2001:db8:1::ab9:c0a8:102]/" -string(5) "[::1]" -string(14) "https://[::1]/" diff --git a/ext/uri/tests/rfc3986/parsing/idna_error.phpt b/ext/uri/tests/rfc3986/parsing/idna_error.phpt new file mode 100644 index 000000000000..1937a646d795 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/idna_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - IDNA characters +--FILE-- + +--EXPECT-- +NULL +NULL diff --git a/ext/uri/tests/rfc3986/parsing/instantiate_without_constructor_error.phpt b/ext/uri/tests/rfc3986/parsing/instantiate_without_constructor_error.phpt new file mode 100644 index 000000000000..5806ec1f14e5 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/instantiate_without_constructor_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test Uri\Rfc3986\Uri instantiation without calling the constructor +--EXTENSIONS-- +reflection +uri +--FILE-- +newInstanceWithoutConstructor(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +ReflectionException: Class Uri\Rfc3986\Uri is an internal class marked as final that cannot be instantiated without invoking its constructor diff --git a/ext/uri/tests/rfc3986/parsing/normalization.phpt b/ext/uri/tests/rfc3986/parsing/normalization.phpt new file mode 100644 index 000000000000..7ae8532ae6ab --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/normalization.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - normalization +--FILE-- +toRawString()); +var_dump(Uri\Rfc3986\Uri::parse("https://www.example.com/dir1/../dir2")->toRawString()); +var_dump(Uri\Rfc3986\Uri::parse("https://你好你好")); +var_dump(Uri\Rfc3986\Uri::parse("https://0Xc0.0250.01")); +var_dump(Uri\Rfc3986\Uri::parse("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->toRawString()); + +?> +--EXPECT-- +string(29) "http://////www.EXAMPLE.com:80" +string(36) "https://www.example.com/dir1/../dir2" +NULL +NULL +string(48) "HttPs://0300.0250.0000.0001/path?query=foo%20bar" diff --git a/ext/uri/tests/049.phpt b/ext/uri/tests/rfc3986/parsing/path_success_percent_encoded_reserved.phpt similarity index 56% rename from ext/uri/tests/049.phpt rename to ext/uri/tests/rfc3986/parsing/path_success_percent_encoded_reserved.phpt index 48f27277fab0..b5bc41e200cb 100644 --- a/ext/uri/tests/049.phpt +++ b/ext/uri/tests/rfc3986/parsing/path_success_percent_encoded_reserved.phpt @@ -1,17 +1,16 @@ --TEST-- -Test percent-encoding normalization - special case +Test Uri\Rfc3986\Uri parsing - path - percent-encoded reserved character --FILE-- getRawPath()); -var_dump($uri->getPath()); -$url = new Uri\WhatWg\Url("https://example.com/foo/bar%2Fbaz"); -var_dump($url->getPath()); +var_dump($uri->toRawString()); +var_dump($uri->getPath()); +var_dump($uri->getRawPath()); ?> --EXPECT-- -string(14) "/foo/bar%2Fbaz" +string(33) "https://example.com/foo/bar%2Fbaz" string(14) "/foo/bar%2Fbaz" string(14) "/foo/bar%2Fbaz" diff --git a/ext/uri/tests/rfc3986/parsing/path_success_relative_reference_numeric.phpt b/ext/uri/tests/rfc3986/parsing/path_success_relative_reference_numeric.phpt new file mode 100644 index 000000000000..ae014b2b9fd2 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/path_success_relative_reference_numeric.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - path - numeric relative reference +--FILE-- + +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + NULL + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + NULL + ["port"]=> + NULL + ["path"]=> + string(20) "192.168/contact.html" + ["query"]=> + NULL + ["fragment"]=> + NULL +} diff --git a/ext/uri/tests/046.phpt b/ext/uri/tests/rfc3986/parsing/path_success_variants.phpt similarity index 72% rename from ext/uri/tests/046.phpt rename to ext/uri/tests/rfc3986/parsing/path_success_variants.phpt index 10d56024698e..5413bbd78977 100644 --- a/ext/uri/tests/046.phpt +++ b/ext/uri/tests/rfc3986/parsing/path_success_variants.phpt @@ -1,5 +1,5 @@ --TEST-- -Test special path variants +Test Uri\Rfc3986\Uri parsing - path - special variants --FILE-- toRawString()); var_dump($uri->getPath()); var_dump($uri->getRawPath()); -$url = new Uri\Whatwg\Url("mailto:johndoe@example.com"); - -var_dump($url->toAsciiString()); -var_dump($url->getPath()); - -$url = new Uri\Whatwg\Url("https://example.com"); - -var_dump($url->toAsciiString()); -var_dump($url->getPath()); - -$url = new Uri\Whatwg\Url("https://example.com/"); - -var_dump($url->toAsciiString()); -var_dump($url->getPath()); - ?> --EXPECT-- string(26) "mailto:johndoe@example.com" @@ -79,9 +64,3 @@ string(0) "" string(20) "https://example.com/" string(1) "/" string(1) "/" -string(26) "mailto:johndoe@example.com" -string(19) "johndoe@example.com" -string(20) "https://example.com/" -string(1) "/" -string(20) "https://example.com/" -string(1) "/" diff --git a/ext/uri/tests/048.phpt b/ext/uri/tests/rfc3986/parsing/percent_encoding_normalization.phpt similarity index 100% rename from ext/uri/tests/048.phpt rename to ext/uri/tests/rfc3986/parsing/percent_encoding_normalization.phpt diff --git a/ext/uri/tests/058.phpt b/ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt similarity index 72% rename from ext/uri/tests/058.phpt rename to ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt index c1ceaa1e02e5..800b9a1a3799 100644 --- a/ext/uri/tests/058.phpt +++ b/ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt @@ -20,7 +20,13 @@ try { new \Uri\Rfc3986\Uri('https://example.com:2147483648'); } } catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + new \Uri\Rfc3986\Uri('https://example.com:4242424269424242426942424242694242424269'); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> @@ -28,3 +34,4 @@ try { 9223372036854775807 2147483647 Uri\InvalidUriException: The port is out of range +Uri\InvalidUriException: The port is out of range diff --git a/ext/uri/tests/rfc3986/parsing/query_success_variants.phpt b/ext/uri/tests/rfc3986/parsing/query_success_variants.phpt new file mode 100644 index 000000000000..a2eb5aa42f42 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/query_success_variants.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - query - variants +--FILE-- + + @")); +var_dump(Uri\Rfc3986\Uri::parse("http://example.com?foo=Hell%C3%B3+W%C3%B6rld")->toRawString()); + +?> +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + string(0) "" + ["query"]=> + string(25) "foo=Hell%C3%B3+W%C3%B6rld" + ["fragment"]=> + NULL +} +NULL +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + string(0) "" + ["query"]=> + string(30) "foobar=%27%3Cscript%3E+%2B+%40" + ["fragment"]=> + NULL +} +NULL +string(44) "http://example.com?foo=Hell%C3%B3+W%C3%B6rld" diff --git a/ext/uri/tests/003.phpt b/ext/uri/tests/rfc3986/parsing/special_references.phpt similarity index 57% rename from ext/uri/tests/003.phpt rename to ext/uri/tests/rfc3986/parsing/special_references.phpt index 38d62b0ec8e6..f75174cd1385 100644 --- a/ext/uri/tests/003.phpt +++ b/ext/uri/tests/rfc3986/parsing/special_references.phpt @@ -1,37 +1,14 @@ --TEST-- -Parse special URIs +Test Uri\Rfc3986\Uri parsing - special references --FILE-- --EXPECTF-- -NULL -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(4) "http" - ["username"]=> - string(8) "username" - ["password"]=> - string(8) "password" - ["host"]=> - string(18) "xn--hostname-b1aaa" - ["port"]=> - int(9090) - ["path"]=> - string(5) "/path" - ["query"]=> - string(14) "arg=va%C3%A9ue" - ["fragment"]=> - string(6) "anchor" -} object(Uri\Rfc3986\Uri)#%d (%d) { ["scheme"]=> NULL @@ -86,4 +63,3 @@ object(Uri\Rfc3986\Uri)#%d (%d) { ["fragment"]=> NULL } -NULL diff --git a/ext/uri/tests/100.phpt b/ext/uri/tests/rfc3986/parsing/zend_test_parse_url.phpt similarity index 100% rename from ext/uri/tests/100.phpt rename to ext/uri/tests/rfc3986/parsing/zend_test_parse_url.phpt diff --git a/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_error.phpt b/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_error.phpt new file mode 100644 index 000000000000..19aec491ec42 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test zend_test_uri_parser() with malformed parse_url input +--EXTENSIONS-- +zend_test +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: The specified URI is malformed diff --git a/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_missing_components.phpt b/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_missing_components.phpt new file mode 100644 index 000000000000..a3123fe62b65 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/zend_test_parse_url_missing_components.phpt @@ -0,0 +1,130 @@ +--TEST-- +Test zend_test_uri_parser() with parse_url missing components +--EXTENSIONS-- +zend_test +--FILE-- + +--EXPECT-- +array(3) { + ["normalized"]=> + array(8) { + ["scheme"]=> + NULL + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + NULL + ["port"]=> + NULL + ["path"]=> + string(4) "/foo" + ["query"]=> + string(3) "bar" + ["fragment"]=> + string(3) "baz" + } + ["raw"]=> + array(8) { + ["scheme"]=> + NULL + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + NULL + ["port"]=> + NULL + ["path"]=> + string(4) "/foo" + ["query"]=> + string(3) "bar" + ["fragment"]=> + string(3) "baz" + } + ["struct"]=> + array(8) { + ["scheme"]=> + NULL + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + NULL + ["port"]=> + int(0) + ["path"]=> + string(4) "/foo" + ["query"]=> + string(3) "bar" + ["fragment"]=> + string(3) "baz" + } +} +array(3) { + ["normalized"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + NULL + ["query"]=> + NULL + ["fragment"]=> + NULL + } + ["raw"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + NULL + ["query"]=> + NULL + ["fragment"]=> + NULL + } + ["struct"]=> + array(8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(0) + ["path"]=> + NULL + ["query"]=> + NULL + ["fragment"]=> + NULL + } +} diff --git a/ext/uri/tests/102.phpt b/ext/uri/tests/rfc3986/parsing/zend_test_port_success_large.phpt similarity index 100% rename from ext/uri/tests/102.phpt rename to ext/uri/tests/rfc3986/parsing/zend_test_port_success_large.phpt diff --git a/ext/uri/tests/043.phpt b/ext/uri/tests/rfc3986/reference_resolution/parse_success_variants.phpt similarity index 58% rename from ext/uri/tests/043.phpt rename to ext/uri/tests/rfc3986/reference_resolution/parse_success_variants.phpt index 18c65e3c7735..71894a39d200 100644 --- a/ext/uri/tests/043.phpt +++ b/ext/uri/tests/rfc3986/reference_resolution/parse_success_variants.phpt @@ -1,5 +1,5 @@ --TEST-- -Test reference resolution +Test Uri\Rfc3986\Uri reference resolution during parsing --FILE-- toString()); -$url = Uri\WhatWg\Url::parse("https://example.com/without-base/"); -var_dump($url); - -$url = Uri\WhatWg\Url::parse("/with-base", new Uri\WhatWg\Url("https://example.com")); -var_dump($url); - -$url = Uri\WhatWg\Url::parse("https://test.com/with-base-in-vain", Uri\WhatWg\Url::parse("https://example.com/")); -var_dump($url); ?> --EXPECTF-- object(Uri\Rfc3986\Uri)#%d (%d) { @@ -99,57 +91,3 @@ object(Uri\Rfc3986\Uri)#%d (%d) { NULL } string(34) "https://test.com/with-base-in-vain" -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(14) "/without-base/" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(10) "/with-base" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(8) "test.com" - ["port"]=> - NULL - ["path"]=> - string(18) "/with-base-in-vain" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/010.phpt b/ext/uri/tests/rfc3986/reference_resolution/parse_success_with_base.phpt similarity index 50% rename from ext/uri/tests/010.phpt rename to ext/uri/tests/rfc3986/reference_resolution/parse_success_with_base.phpt index ff5a37000775..0826f7197066 100644 --- a/ext/uri/tests/010.phpt +++ b/ext/uri/tests/rfc3986/reference_resolution/parse_success_with_base.phpt @@ -1,13 +1,10 @@ --TEST-- -Test parsing URIs when a base URI is present +Test Uri\Rfc3986\Uri parsing with a base URI --FILE-- --EXPECTF-- object(Uri\Rfc3986\Uri)#%d (%d) { @@ -46,39 +43,3 @@ object(Uri\Rfc3986\Uri)#%d (%d) { ["fragment"]=> NULL } -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(4) "http" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(11) "example.com" - ["port"]=> - NULL - ["path"]=> - string(14) "/path/to/file1" - ["query"]=> - NULL - ["fragment"]=> - NULL -} -object(Uri\WhatWg\Url)#%d (%d) { - ["scheme"]=> - string(5) "https" - ["username"]=> - NULL - ["password"]=> - NULL - ["host"]=> - string(8) "test.com" - ["port"]=> - NULL - ["path"]=> - string(14) "/path/to/file1" - ["query"]=> - NULL - ["fragment"]=> - NULL -} diff --git a/ext/uri/tests/rfc3986/reference_resolution/resolve_error_unicode.phpt b/ext/uri/tests/rfc3986/reference_resolution/resolve_error_unicode.phpt new file mode 100644 index 000000000000..3fcf488074ed --- /dev/null +++ b/ext/uri/tests/rfc3986/reference_resolution/resolve_error_unicode.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\Rfc3986\Uri reference resolution - resolve() - unicode +--FILE-- +resolve("á"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Uri\InvalidUriException: The specified URI is malformed diff --git a/ext/uri/tests/rfc3986/reference_resolution/resolve_success_basic.phpt b/ext/uri/tests/rfc3986/reference_resolution/resolve_success_basic.phpt new file mode 100644 index 000000000000..0ff7d6468001 --- /dev/null +++ b/ext/uri/tests/rfc3986/reference_resolution/resolve_success_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test Uri\Rfc3986\Uri reference resolution - resolve() - success +--FILE-- +resolve("/foo/")->toString()); +var_dump($uri->resolve("https://test.com/foo")->toString()); + +?> +--EXPECTF-- +string(24) "https://example.com/foo/" +string(20) "https://test.com/foo" diff --git a/ext/uri/tests/034.phpt b/ext/uri/tests/rfc3986/serialization/array_cast_success.phpt similarity index 53% rename from ext/uri/tests/034.phpt rename to ext/uri/tests/rfc3986/serialization/array_cast_success.phpt index 35d51aad8664..9e8e56eb7277 100644 --- a/ext/uri/tests/034.phpt +++ b/ext/uri/tests/rfc3986/serialization/array_cast_success.phpt @@ -1,17 +1,12 @@ --TEST-- -Test array cast +Test casting Uri\Rfc3986\Uri to array --FILE-- --EXPECTF-- array(%d) { } -array(%d) { -} diff --git a/ext/uri/tests/rfc3986/serialization/basic_success.phpt b/ext/uri/tests/rfc3986/serialization/basic_success.phpt new file mode 100644 index 000000000000..5a69491b1aaa --- /dev/null +++ b/ext/uri/tests/rfc3986/serialization/basic_success.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test Uri\Rfc3986\Uri serialization and unserialization +--FILE-- + +--EXPECTF-- +string(164) "O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:99:"https://username:password@www.example.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists";}i:1;a:0:{}}" +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(5) "https" + ["username"]=> + string(8) "username" + ["password"]=> + string(8) "password" + ["host"]=> + string(15) "www.example.com" + ["port"]=> + int(8080) + ["path"]=> + string(30) "/pathname1/pathname2/pathname3" + ["query"]=> + string(10) "query=true" + ["fragment"]=> + string(11) "hash-exists" +} diff --git a/ext/uri/tests/009.phpt b/ext/uri/tests/rfc3986/serialization/clone_success.phpt similarity index 59% rename from ext/uri/tests/009.phpt rename to ext/uri/tests/rfc3986/serialization/clone_success.phpt index 9c896d0153b2..6892811c871a 100644 --- a/ext/uri/tests/009.phpt +++ b/ext/uri/tests/rfc3986/serialization/clone_success.phpt @@ -1,16 +1,18 @@ --TEST-- -Test parsing with IANA schemes +Test cloning Uri\Rfc3986\Uri --FILE-- --EXPECTF-- -object(Uri\Rfc3986\Uri)#%d (%d) { +object(Uri\Rfc3986\Uri)#1 (%d) { ["scheme"]=> - string(16) "chrome-extension" + string(5) "https" ["username"]=> NULL ["password"]=> @@ -26,9 +28,9 @@ object(Uri\Rfc3986\Uri)#%d (%d) { ["fragment"]=> NULL } -object(Uri\WhatWg\Url)#%d (%d) { +object(Uri\Rfc3986\Uri)#2 (%d) { ["scheme"]=> - string(16) "chrome-extension" + string(5) "https" ["username"]=> NULL ["password"]=> diff --git a/ext/uri/tests/rfc3986/serialization/invalid_data.phpt b/ext/uri/tests/rfc3986/serialization/invalid_data.phpt new file mode 100644 index 000000000000..d256fb0b7327 --- /dev/null +++ b/ext/uri/tests/rfc3986/serialization/invalid_data.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test Uri\Rfc3986\Uri unserialization with invalid data +--FILE-- +getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":3:{i:0;a:0:{}i:1;a:0:{}i:2;a:0:{}}'); // more than 2 items +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;N;i:1;a:0:{}}'); // first item is not an array +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:0:{}i:1;a:0:{}}'); // first array is empty +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";i:1;}i:1;a:0:{}}'); // "uri" key in first array is not a string +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:2:"%1";}i:1;a:0:{}}'); // "uri" key in first array contains invalid URI +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:4:"/uri";}i:1;s:0:"";}'); // second item in not an array +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unserialize('O:15:"Uri\Rfc3986\Uri":2:{i:0;a:1:{s:3:"uri";s:4:"/uri";}i:1;a:1:{s:5:"prop1";i:123;}}'); // second array contains a property +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +Exception: Invalid serialization data for Uri\Rfc3986\Uri object diff --git a/ext/uri/tests/032.phpt b/ext/uri/tests/rfc3986/serialization/json_encode_success.phpt similarity index 52% rename from ext/uri/tests/032.phpt rename to ext/uri/tests/rfc3986/serialization/json_encode_success.phpt index b17765240c7b..cfc7b8a523d9 100644 --- a/ext/uri/tests/032.phpt +++ b/ext/uri/tests/rfc3986/serialization/json_encode_success.phpt @@ -1,15 +1,11 @@ --TEST-- -Test JSON encoding +Test JSON encoding Uri\Rfc3986\Uri --FILE-- --EXPECT-- string(2) "{}" -string(2) "{}" diff --git a/ext/uri/tests/rfc3986/serialization/legacy_format_error.phpt b/ext/uri/tests/rfc3986/serialization/legacy_format_error.phpt new file mode 100644 index 000000000000..ef76114f2f43 --- /dev/null +++ b/ext/uri/tests/rfc3986/serialization/legacy_format_error.phpt @@ -0,0 +1,11 @@ +--TEST-- +GH-22046: Uri\Rfc3986\Uri cannot be unserialized with the unsupported C format +--FILE-- + +--EXPECTF-- +Warning: Class Uri\Rfc3986\Uri has no unserializer in %s on line %d + +Warning: unserialize(): Error at offset 26 of 27 bytes in %s on line %d diff --git a/ext/uri/tests/rfc3986/serialization/reinitialization_error.phpt b/ext/uri/tests/rfc3986/serialization/reinitialization_error.phpt new file mode 100644 index 000000000000..9b7998c7fac4 --- /dev/null +++ b/ext/uri/tests/rfc3986/serialization/reinitialization_error.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test that overwriting Uri\Rfc3986\Uri is not possible +--FILE-- +__construct('ftp://example.org'); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +var_dump($uri); + +$uri = new Uri\Rfc3986\Uri('https://example.com'); +try { + $uri->__unserialize([['uri' => 'ftp://example.org'], []]); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +var_dump($uri); + +?> +--EXPECTF-- +Error: Cannot modify readonly object of class Uri\Rfc3986\Uri +object(Uri\Rfc3986\Uri)#%d (8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} +Exception: Invalid serialization data for Uri\Rfc3986\Uri object +object(Uri\Rfc3986\Uri)#%d (8) { + ["scheme"]=> + string(5) "https" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + NULL + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} diff --git a/ext/uri/tests/rfc3986/serialization/string_conversion_success.phpt b/ext/uri/tests/rfc3986/serialization/string_conversion_success.phpt new file mode 100644 index 000000000000..90556c806580 --- /dev/null +++ b/ext/uri/tests/rfc3986/serialization/string_conversion_success.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test Uri\Rfc3986\Uri string conversion +--FILE-- +toRawString()); +var_dump($uri1->toString()); +var_dump($uri2->toRawString()); +var_dump($uri2->toString()); +var_dump($uri3->toRawString()); +var_dump($uri3->toString()); + +?> +--EXPECT-- +string(23) "HTTPS://////EXAMPLE.com" +string(23) "https://////EXAMPLE.com" +string(19) "https://example.com" +string(19) "https://example.com" +string(26) "https://example.com/foo/.." +string(20) "https://example.com/" diff --git a/ext/uri/tests/033.phpt b/ext/uri/tests/rfc3986/serialization/var_export_success.phpt similarity index 52% rename from ext/uri/tests/033.phpt rename to ext/uri/tests/rfc3986/serialization/var_export_success.phpt index e88baadeba0d..de83dadb0343 100644 --- a/ext/uri/tests/033.phpt +++ b/ext/uri/tests/rfc3986/serialization/var_export_success.phpt @@ -1,5 +1,5 @@ --TEST-- -Test var_export +Test var_export() with Uri\Rfc3986\Uri --FILE-- --EXPECT-- \Uri\Rfc3986\Uri::__set_state(array( )) -\Uri\WhatWg\Url::__set_state(array( -)) diff --git a/ext/uri/tests/053.phpt b/ext/uri/tests/whatwg/exceptions/invalid_url_exception_constructor_reentry.phpt similarity index 54% rename from ext/uri/tests/053.phpt rename to ext/uri/tests/whatwg/exceptions/invalid_url_exception_constructor_reentry.phpt index c88f4d386f35..c869299eaab1 100644 --- a/ext/uri/tests/053.phpt +++ b/ext/uri/tests/whatwg/exceptions/invalid_url_exception_constructor_reentry.phpt @@ -1,5 +1,5 @@ --TEST-- -Test InvalidUrlException constructor error handling +Test Uri\WhatWg\InvalidUrlException constructor reentry --FILE-- __construct("foo"); -} catch (Error $e) { - echo $e->getMessage() . "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { $r->__construct("bar", []); -} catch (Error $e) { - echo $e->getMessage() . "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { $r->__construct("baz", [], 0); -} catch (Error $e) { - echo $e->getMessage() . "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { $r->__construct("qax", [], 0, null); -} catch (Error $e) { - echo $e->getMessage() . "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } var_dump($r->getMessage()); @@ -41,10 +41,10 @@ var_dump($r->getPrevious()::class); ?> --EXPECTF-- -Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors -Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors -Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors -Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors +Error: Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors +Error: Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors +Error: Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors +Error: Cannot modify readonly property Uri\WhatWg\InvalidUrlException::$errors string(3) "qax" array(%d) { [%d]=> diff --git a/ext/uri/tests/whatwg/exceptions/invalid_url_exception_errors_argument.phpt b/ext/uri/tests/whatwg/exceptions/invalid_url_exception_errors_argument.phpt new file mode 100644 index 000000000000..f1eabbf0e696 --- /dev/null +++ b/ext/uri/tests/whatwg/exceptions/invalid_url_exception_errors_argument.phpt @@ -0,0 +1,54 @@ +--TEST-- +GH-19780 (InvalidUrlException should check $errors argument) +--FILE-- + [ + 'errors' => [], + ], + 'single validation error' => [ + 'errors' => [$error], + ], + 'multiple validation errors' => [ + 'errors' => [ + $error, + new UrlValidationError('other', UrlValidationErrorType::InvalidUrlUnit, false), + ], + ], + 'stdClass' => [ + 'errors' => [new stdClass()], + ], + '[]' => [ + 'errors' => [[]], + ], + 'non-list' => [ + 'errors' => [ + 99 => $error, + ], + ], +]; + +foreach ($cases as $label => $case) { + try { + $e = new InvalidUrlException('message', $case['errors']); + echo $label, ': ok: ', count($e->errors), "\n"; + } catch (Throwable $e) { + echo $label, ': ', $e::class, ': ', $e->getMessage(), "\n"; + } +} + +?> +--EXPECT-- +empty list: ok: 0 +single validation error: ok: 1 +multiple validation errors: ok: 2 +stdClass: ValueError: Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError +[]: ValueError: Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError +non-list: ValueError: Uri\WhatWg\InvalidUrlException::__construct(): Argument #2 ($errors) must be a list of Uri\WhatWg\UrlValidationError diff --git a/ext/uri/tests/whatwg/exceptions/url_validation_error_constructor_reentry.phpt b/ext/uri/tests/whatwg/exceptions/url_validation_error_constructor_reentry.phpt new file mode 100644 index 000000000000..e337af401945 --- /dev/null +++ b/ext/uri/tests/whatwg/exceptions/url_validation_error_constructor_reentry.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test Uri\WhatWg\UrlValidationError constructor reentry stops after readonly failures +--FILE-- +__construct('bar', Uri\WhatWg\UrlValidationErrorType::HostMissing, false); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +var_dump($r); + +foreach ([ + 'O:29:"Uri\\WhatWg\\UrlValidationError":1:{s:4:"type";E:45:"Uri\\WhatWg\\UrlValidationErrorType:HostMissing";}', + 'O:29:"Uri\\WhatWg\\UrlValidationError":1:{s:7:"failure";b:1;}', +] as $serialized) { + + $r = unserialize($serialized); + + try { + $r->__construct('foo', Uri\WhatWg\UrlValidationErrorType::HostMissing, false); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} + +?> +--EXPECTF-- +Error: Cannot modify readonly property Uri\WhatWg\UrlValidationError::$context +object(Uri\WhatWg\UrlValidationError)#%d (%d) { + ["context"]=> + string(3) "foo" + ["type"]=> + enum(Uri\WhatWg\UrlValidationErrorType::DomainInvalidCodePoint) + ["failure"]=> + bool(true) +} +Error: Cannot modify readonly property Uri\WhatWg\UrlValidationError::$type +Error: Cannot modify readonly property Uri\WhatWg\UrlValidationError::$failure diff --git a/ext/uri/tests/whatwg/getters/basic_success.phpt b/ext/uri/tests/whatwg/getters/basic_success.phpt new file mode 100644 index 000000000000..aebf36eaaf12 --- /dev/null +++ b/ext/uri/tests/whatwg/getters/basic_success.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test Uri\WhatWg\Url component retrieval - basic +--FILE-- +getScheme()); +var_dump($url->getUsername()); +var_dump($url->getPassword()); +var_dump($url->getAsciiHost()); +var_dump($url->getUnicodeHost()); +var_dump($url->getPort()); +var_dump($url->getPath()); +var_dump($url->getQuery()); +var_dump($url->getFragment()); + +?> +--EXPECT-- +string(5) "https" +string(8) "username" +string(8) "password" +string(15) "www.example.com" +string(15) "www.example.com" +int(8080) +string(30) "/pathname1/pathname2/pathname3" +string(10) "query=true" +string(11) "hash-exists" diff --git a/ext/uri/tests/whatwg/getters/percent_encoded_components.phpt b/ext/uri/tests/whatwg/getters/percent_encoded_components.phpt new file mode 100644 index 000000000000..d6c24e1bc6e8 --- /dev/null +++ b/ext/uri/tests/whatwg/getters/percent_encoded_components.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test Uri\WhatWg\Url component retrieval - percent-encoded components +--FILE-- +getScheme()); +var_dump($url->getUsername()); +var_dump($url->getPassword()); +var_dump($url->getAsciiHost()); +var_dump($url->getUnicodeHost()); +var_dump($url->getPort()); +var_dump($url->getPath()); +var_dump($url->getQuery()); +var_dump($url->getFragment()); + +?> +--EXPECT-- +string(4) "http" +string(7) "%61pple" +string(6) "p%61ss" +string(11) "example.com" +string(11) "example.com" +NULL +string(9) "/foob%61r" +string(11) "%61bc=%61bc" +string(5) "%61bc" diff --git a/ext/uri/tests/whatwg/modification/port_success_file_scheme.phpt b/ext/uri/tests/whatwg/modification/port_success_file_scheme.phpt new file mode 100644 index 000000000000..0d7241fb97cd --- /dev/null +++ b/ext/uri/tests/whatwg/modification/port_success_file_scheme.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test Uri\WhatWg\Url component modification - port - file scheme +--FILE-- +withPort(80); + +var_dump($url1->getPort()); +var_dump($url2->getPort()); + +?> +--EXPECT-- +NULL +NULL diff --git a/ext/uri/tests/whatwg/modification/username_success_encoded.phpt b/ext/uri/tests/whatwg/modification/username_success_encoded.phpt new file mode 100644 index 000000000000..84199fe8caa3 --- /dev/null +++ b/ext/uri/tests/whatwg/modification/username_success_encoded.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test Uri\WhatWg\Url component modification - username - URL encoded characters +--FILE-- +withUsername("%75s%2Fr"); + +var_dump($url2->getUsername()); +var_dump($url2->toAsciiString()); + +?> +--EXPECT-- +string(8) "%75s%2Fr" +string(29) "https://%75s%2Fr@example.com/" diff --git a/ext/uri/tests/whatwg/modification/username_success_file_scheme.phpt b/ext/uri/tests/whatwg/modification/username_success_file_scheme.phpt new file mode 100644 index 000000000000..b5a2191dc6a8 --- /dev/null +++ b/ext/uri/tests/whatwg/modification/username_success_file_scheme.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test Uri\WhatWg\Url component modification - username - file scheme +--FILE-- +withUsername("user"); + +var_dump($url2->getUsername()); +var_dump($url2->toAsciiString()); + +?> +--EXPECT-- +NULL +string(16) "file:///foo/bar/" diff --git a/ext/uri/tests/whatwg/parsing/basic_error_returns_null.phpt b/ext/uri/tests/whatwg/parsing/basic_error_returns_null.phpt new file mode 100644 index 000000000000..6d0aef7ebb2b --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/basic_error_returns_null.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\WhatWg\Url::parse() returns null for malformed URLs +--FILE-- + +--EXPECT-- +NULL +NULL +NULL +NULL diff --git a/ext/uri/tests/whatwg/parsing/basic_success_constructor.phpt b/ext/uri/tests/whatwg/parsing/basic_success_constructor.phpt new file mode 100644 index 000000000000..578f2a1f8b6b --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/basic_success_constructor.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test Uri\WhatWg\Url construction - basic - success +--FILE-- + +--EXPECTF-- +object(Uri\WhatWg\Url)#%d (%d) { + ["scheme"]=> + string(5) "https" + ["username"]=> + string(8) "username" + ["password"]=> + string(8) "password" + ["host"]=> + string(11) "example.com" + ["port"]=> + int(8080) + ["path"]=> + string(5) "/path" + ["query"]=> + string(3) "q=r" + ["fragment"]=> + string(8) "fragment" +} diff --git a/ext/uri/tests/whatwg/parsing/basic_success_invalid_url_unit_warnings.phpt b/ext/uri/tests/whatwg/parsing/basic_success_invalid_url_unit_warnings.phpt new file mode 100644 index 000000000000..9ee858362b97 --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/basic_success_invalid_url_unit_warnings.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test Uri\WhatWg\Url parsing reports invalid URL unit warnings +--FILE-- +toAsciiString()); +var_dump($errors); + +?> +--EXPECTF-- +string(20) "https://example.org/" +array(2) { + [0]=> + object(Uri\WhatWg\UrlValidationError)#%d (%d) { + ["context"]=> + string(1) " " + ["type"]=> + enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit) + ["failure"]=> + bool(false) + } + [1]=> + object(Uri\WhatWg\UrlValidationError)#%d (%d) { + ["context"]=> + string(21) " https://example.org " + ["type"]=> + enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit) + ["failure"]=> + bool(false) + } +} diff --git a/ext/uri/tests/005.phpt b/ext/uri/tests/whatwg/parsing/basic_success_multibyte.phpt similarity index 86% rename from ext/uri/tests/005.phpt rename to ext/uri/tests/whatwg/parsing/basic_success_multibyte.phpt index 8d8be9679397..b6856ec22177 100644 --- a/ext/uri/tests/005.phpt +++ b/ext/uri/tests/whatwg/parsing/basic_success_multibyte.phpt @@ -1,10 +1,8 @@ --TEST-- -Parse multibyte URLs +Test Uri\WhatWg\Url parsing - basic - multibyte URL --FILE-- getAsciiHost()); @@ -14,7 +12,6 @@ var_dump($url->toUnicodeString()); ?> --EXPECTF-- -NULL object(Uri\WhatWg\Url)#%d (%d) { ["scheme"]=> string(4) "http" diff --git a/ext/uri/tests/057.phpt b/ext/uri/tests/whatwg/parsing/errors_reference_error.phpt similarity index 53% rename from ext/uri/tests/057.phpt rename to ext/uri/tests/whatwg/parsing/errors_reference_error.phpt index 5cc4e5974212..4cbc3451418b 100644 --- a/ext/uri/tests/057.phpt +++ b/ext/uri/tests/whatwg/parsing/errors_reference_error.phpt @@ -11,9 +11,16 @@ $f = new Foo(); try { Uri\WhatWg\Url::parse(" https://example.org ", errors: $f->x); } catch (Throwable $e) { - echo $e::class, ": ", $e->getMessage(), PHP_EOL; + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + Uri\WhatWg\Url::parse('invalid uri', errors: $f->x); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- TypeError: Cannot assign array to reference held by property Foo::$x of type string +TypeError: Cannot assign array to reference held by property Foo::$x of type string diff --git a/ext/uri/tests/gh19892.phpt b/ext/uri/tests/whatwg/parsing/errors_success_empty.phpt similarity index 100% rename from ext/uri/tests/gh19892.phpt rename to ext/uri/tests/whatwg/parsing/errors_success_empty.phpt diff --git a/ext/uri/tests/022.phpt b/ext/uri/tests/whatwg/parsing/extension_error.phpt similarity index 100% rename from ext/uri/tests/022.phpt rename to ext/uri/tests/whatwg/parsing/extension_error.phpt diff --git a/ext/uri/tests/whatwg/parsing/host_success_ip_addresses.phpt b/ext/uri/tests/whatwg/parsing/host_success_ip_addresses.phpt new file mode 100644 index 000000000000..3f33c4982cbc --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/host_success_ip_addresses.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test Uri\WhatWg\Url parsing - host - IP addresses +--FILE-- +getAsciiHost()); +var_dump($url->toAsciiString()); + +$url = new Uri\WhatWg\Url("https://[2001:0db8:0001:0000:0000:0ab9:C0A8:0102]"); +var_dump($url->getAsciiHost()); +var_dump($url->toAsciiString()); + +$url = new Uri\WhatWg\Url("https://[0:0::1]"); +var_dump($url->getAsciiHost()); +var_dump($url->toAsciiString()); + +?> +--EXPECT-- +string(11) "192.168.0.1" +string(20) "https://192.168.0.1/" +string(26) "[2001:db8:1::ab9:c0a8:102]" +string(35) "https://[2001:db8:1::ab9:c0a8:102]/" +string(5) "[::1]" +string(14) "https://[::1]/" diff --git a/ext/uri/tests/019.phpt b/ext/uri/tests/whatwg/parsing/idna_support.phpt similarity index 86% rename from ext/uri/tests/019.phpt rename to ext/uri/tests/whatwg/parsing/idna_support.phpt index 7f62a64e9fde..0433997d22ca 100644 --- a/ext/uri/tests/019.phpt +++ b/ext/uri/tests/whatwg/parsing/idna_support.phpt @@ -1,19 +1,13 @@ --TEST-- -Test IDNA support +Test Uri\WhatWg\Url parsing - IDNA support --FILE-- getAsciiHost()); @@ -24,7 +18,6 @@ var_dump($url->toUnicodeString()); ?> --EXPECTF-- NULL -NULL array(1) { [0]=> object(Uri\WhatWg\UrlValidationError)#%d (%d) { @@ -36,7 +29,6 @@ array(1) { bool(true) } } -NULL object(Uri\WhatWg\Url)#%d (%d) { ["scheme"]=> string(5) "https" diff --git a/ext/uri/tests/whatwg/parsing/instantiate_without_constructor_error.phpt b/ext/uri/tests/whatwg/parsing/instantiate_without_constructor_error.phpt new file mode 100644 index 000000000000..088c8f5fb642 --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/instantiate_without_constructor_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test Uri\WhatWg\Url instantiation without calling the constructor +--EXTENSIONS-- +reflection +uri +--FILE-- +newInstanceWithoutConstructor(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +ReflectionException: Class Uri\WhatWg\Url is an internal class marked as final that cannot be instantiated without invoking its constructor diff --git a/ext/uri/tests/056.phpt b/ext/uri/tests/whatwg/parsing/memory_management.phpt similarity index 100% rename from ext/uri/tests/056.phpt rename to ext/uri/tests/whatwg/parsing/memory_management.phpt diff --git a/ext/uri/tests/011.phpt b/ext/uri/tests/whatwg/parsing/normalization.phpt similarity index 56% rename from ext/uri/tests/011.phpt rename to ext/uri/tests/whatwg/parsing/normalization.phpt index 0e8fd8ec8f48..9b8b883a72f4 100644 --- a/ext/uri/tests/011.phpt +++ b/ext/uri/tests/whatwg/parsing/normalization.phpt @@ -1,31 +1,22 @@ --TEST-- -Test encoding and normalization +Test Uri\WhatWg\Url parsing - normalization --FILE-- toRawString()); -var_dump(Uri\Rfc3986\Uri::parse("https://www.example.com/dir1/../dir2")->toRawString()); -var_dump(Uri\Rfc3986\Uri::parse("https://你好你好")); -var_dump(Uri\Rfc3986\Uri::parse("https://0Xc0.0250.01")); -var_dump(Uri\Rfc3986\Uri::parse("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->toRawString()); - var_dump(Uri\WhatWg\Url::parse("http://////www.EXAMPLE.com:80")->toAsciiString()); var_dump(Uri\WhatWg\Url::parse("https://www.example.com:443/dir1/../dir2")->toAsciiString()); var_dump(Uri\WhatWg\Url::parse("https://你好你好")->toAsciiString()); var_dump(Uri\WhatWg\Url::parse("https://你好你好")->toUnicodeString()); var_dump(Uri\WhatWg\Url::parse("https://0Xc0.0250.01")->toAsciiString()); var_dump(Uri\WhatWg\Url::parse("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->toAsciiString()); +var_dump(Uri\WhatWg\Url::parse("file:///E:\\Documents and Settings")->toAsciiString()); ?> --EXPECT-- -string(29) "http://////www.EXAMPLE.com:80" -string(36) "https://www.example.com/dir1/../dir2" -NULL -NULL -string(48) "HttPs://0300.0250.0000.0001/path?query=foo%20bar" string(23) "http://www.example.com/" string(28) "https://www.example.com/dir2" string(23) "https://xn--6qqa088eba/" string(21) "https://你好你好/" string(20) "https://192.168.0.1/" string(40) "https://192.168.0.1/path?query=foo%20bar" +string(37) "file:///E:/Documents%20and%20Settings" diff --git a/ext/uri/tests/whatwg/parsing/path_success_percent_encoded_reserved.phpt b/ext/uri/tests/whatwg/parsing/path_success_percent_encoded_reserved.phpt new file mode 100644 index 000000000000..532ce6c1ffb8 --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/path_success_percent_encoded_reserved.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test Uri\WhatWg\Url parsing - path - percent-encoded reserved character +--FILE-- +toAsciiString()); +var_dump($url->getPath()); + +?> +--EXPECT-- +string(33) "https://example.com/foo/bar%2Fbaz" +string(14) "/foo/bar%2Fbaz" diff --git a/ext/uri/tests/whatwg/parsing/path_success_variants.phpt b/ext/uri/tests/whatwg/parsing/path_success_variants.phpt new file mode 100644 index 000000000000..9890d9758fad --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/path_success_variants.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test Uri\WhatWg\Url parsing - path - special variants +--FILE-- +toAsciiString()); +var_dump($url->getPath()); + +$url = new Uri\WhatWg\Url("https://example.com"); +var_dump($url->toAsciiString()); +var_dump($url->getPath()); + +$url = new Uri\WhatWg\Url("https://example.com/"); +var_dump($url->toAsciiString()); +var_dump($url->getPath()); + +?> +--EXPECT-- +string(26) "mailto:johndoe@example.com" +string(19) "johndoe@example.com" +string(20) "https://example.com/" +string(1) "/" +string(20) "https://example.com/" +string(1) "/" diff --git a/ext/uri/tests/whatwg/parsing/port_error_too_large.phpt b/ext/uri/tests/whatwg/parsing/port_error_too_large.phpt new file mode 100644 index 000000000000..f9e045728307 --- /dev/null +++ b/ext/uri/tests/whatwg/parsing/port_error_too_large.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Uri\WhatWg\Url parsing - port - too large +--FILE-- +getMessage(), "\n"; + var_dump($e->errors[0]->type === Uri\WhatWg\UrlValidationErrorType::PortOutOfRange); +} + +?> +--EXPECT-- +Uri\WhatWg\InvalidUrlException: The specified URI is malformed (PortOutOfRange) +bool(true) diff --git a/ext/uri/tests/013.phpt b/ext/uri/tests/whatwg/parsing/query_success_variants.phpt similarity index 61% rename from ext/uri/tests/013.phpt rename to ext/uri/tests/whatwg/parsing/query_success_variants.phpt index 865843ec27e8..fc45ae455ee1 100644 --- a/ext/uri/tests/013.phpt +++ b/ext/uri/tests/whatwg/parsing/query_success_variants.phpt @@ -1,41 +1,16 @@ --TEST-- -Test parsing of query strings +Test Uri\WhatWg\Url parsing - query - variants --FILE-- + @")); - var_dump(Uri\WhatWg\Url::parse("http://example.com?foobar=%27%3Cscript%3E+%2B+%40")); var_dump(Uri\WhatWg\Url::parse("http://example.com?foobar='