-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UrlImmutable, UrlScript: added resolve()
- Loading branch information
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Http\UrlImmutable; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$tests = [ | ||
'https://example.com/path/' => [ | ||
// absolute URLs with various schemes | ||
'a:' => 'a:', | ||
'a:b' => 'a:b', | ||
'http://other.com/test' => 'http://other.com/test', | ||
'https://other.com/test' => 'https://other.com/test', | ||
'ftp://other.com/test' => 'ftp://other.com/test', | ||
|
||
// protocol-relative URLs - keep current scheme | ||
'//other.com/test' => 'https://other.com/test', | ||
|
||
// root-relative paths | ||
'/test' => 'https://example.com/test', | ||
'/test/' => 'https://example.com/test/', | ||
|
||
// relative paths | ||
'sibling' => 'https://example.com/path/sibling', | ||
'../parent' => 'https://example.com/parent', | ||
'child/' => 'https://example.com/path/child/', | ||
], | ||
|
||
// base dir with query string and fragment | ||
'https://example.com/path/?q=123#frag' => [ | ||
'' => 'https://example.com/path/?q=123', | ||
'file' => 'https://example.com/path/file', | ||
'./file' => 'https://example.com/path/file', | ||
'/root' => 'https://example.com/root', | ||
'subdir/?q=456' => 'https://example.com/path/subdir/?q=456', | ||
'subdir/#frag' => 'https://example.com/path/subdir/#frag', | ||
'../file' => 'https://example.com/file', | ||
'/../file' => 'https://example.com/file', | ||
'file?newq=/..#newfrag/..' => 'https://example.com/path/file?newq=%2F..#newfrag/..', | ||
'?newq=/..' => 'https://example.com/path/?newq=%2F..', | ||
'#newfrag/..' => 'https://example.com/path/?q=123#newfrag/..', | ||
], | ||
|
||
// base file with query string and fragment | ||
'https://example.com/path/file?q=123#frag' => [ | ||
'' => 'https://example.com/path/file?q=123', | ||
'file' => 'https://example.com/path/file', | ||
'./file' => 'https://example.com/path/file', | ||
'/root' => 'https://example.com/root', | ||
'subdir/file?q=123' => 'https://example.com/path/subdir/file?q=123', | ||
'subdir/file#frag' => 'https://example.com/path/subdir/file#frag', | ||
'../file' => 'https://example.com/file', | ||
'/../file' => 'https://example.com/file', | ||
'?newq=/..' => 'https://example.com/path/file?newq=%2F..', | ||
'#newfrag/..' => 'https://example.com/path/file?q=123#newfrag/..', | ||
], | ||
]; | ||
|
||
|
||
foreach ($tests as $base => $paths) { | ||
$url = new UrlImmutable($base); | ||
foreach ($paths as $path => $expected) { | ||
Assert::same($expected, (string) $url->resolve($path), "Base: $base, Reference: $path"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Http\UrlScript; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$tests = [ | ||
'https://example.com/path/' => [ | ||
// absolute URLs with various schemes | ||
'a:' => 'a:', | ||
'a:b' => 'a:b', | ||
'http://other.com/test' => 'http://other.com/test', | ||
'https://other.com/test' => 'https://other.com/test', | ||
'ftp://other.com/test' => 'ftp://other.com/test', | ||
|
||
// protocol-relative URLs - keep current scheme | ||
'//other.com/test' => 'https://other.com/test', | ||
|
||
// root-relative paths | ||
'/test' => 'https://example.com/test', | ||
'/test/' => 'https://example.com/test/', | ||
|
||
// relative paths | ||
'sibling' => 'https://example.com/sibling', | ||
'../parent' => 'https://example.com/parent', | ||
'child/' => 'https://example.com/child/', | ||
], | ||
|
||
// base dir with query string and fragment | ||
'https://example.com/path/?q=123#frag' => [ | ||
'' => 'https://example.com/path/?q=123', | ||
'file' => 'https://example.com/file', | ||
'./file' => 'https://example.com/file', | ||
'/root' => 'https://example.com/root', | ||
'subdir/?q=456' => 'https://example.com/subdir/?q=456', | ||
'subdir/#frag' => 'https://example.com/subdir/#frag', | ||
'../file' => 'https://example.com/file', | ||
'/../file' => 'https://example.com/file', | ||
'file?newq=/..#newfrag/..' => 'https://example.com/file?newq=%2F..#newfrag/..', | ||
'?newq=/..' => 'https://example.com/path/?newq=%2F..', | ||
'#newfrag/..' => 'https://example.com/path/?q=123#newfrag/..', | ||
], | ||
|
||
// base file with query string and fragment | ||
'https://example.com/path/file?q=123#frag' => [ | ||
'' => 'https://example.com/path/file?q=123', | ||
'file' => 'https://example.com/file', | ||
'./file' => 'https://example.com/file', | ||
'/root' => 'https://example.com/root', | ||
'subdir/file?q=123' => 'https://example.com/subdir/file?q=123', | ||
'subdir/file#frag' => 'https://example.com/subdir/file#frag', | ||
'../file' => 'https://example.com/file', | ||
'/../file' => 'https://example.com/file', | ||
'?newq=/..' => 'https://example.com/path/file?newq=%2F..', | ||
'#newfrag/..' => 'https://example.com/path/file?q=123#newfrag/..', | ||
], | ||
]; | ||
|
||
|
||
foreach ($tests as $base => $paths) { | ||
$url = new UrlScript($base, '/'); | ||
foreach ($paths as $path => $expected) { | ||
Assert::same($expected, (string) $url->resolve($path), "Base: $base, Reference: $path"); | ||
} | ||
} |