2019-08-27 02:13:30 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\TestCase\Misc;
|
|
|
|
|
|
|
|
use JKingWeb\Arsse\Misc\URL;
|
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\Misc\URL */
|
|
|
|
class TestURL extends \JKingWeb\Arsse\Test\AbstractTest {
|
|
|
|
/** @dataProvider provideNormalizations */
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testNormalizeAUrl(string $url, string $exp, string $user = null, string $pass = null): void {
|
2019-08-27 15:08:13 +00:00
|
|
|
$this->assertSame($exp, URL::normalize($url, $user, $pass));
|
2019-08-27 02:13:30 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public function provideNormalizations(): iterable {
|
2019-08-27 02:13:30 +00:00
|
|
|
return [
|
2019-08-27 15:08:13 +00:00
|
|
|
["http://example.com/", "http://example.com/"],
|
|
|
|
["HTTP://example.com/", "http://example.com/"],
|
|
|
|
["http://example.com", "http://example.com/"],
|
|
|
|
["http://example.com:/", "http://example.com/"],
|
|
|
|
["HTTP://example.com:80/", "http://example.com:80/"],
|
|
|
|
["HTTP://example.com:80", "http://example.com:80/"],
|
|
|
|
["http://example.com/?", "http://example.com/"],
|
|
|
|
["http://example.com?", "http://example.com/"],
|
|
|
|
["http://example.com/#fragment", "http://example.com/"],
|
|
|
|
["http://example.com#fragment", "http://example.com/"],
|
|
|
|
["http://example.com?#", "http://example.com/"],
|
|
|
|
["http://example.com/?key=value", "http://example.com/?key=value"],
|
|
|
|
["http://example.com/", "http://user:pass@example.com/", "user", "pass"],
|
|
|
|
["http://example.com/", "http://user@example.com/", "user"],
|
|
|
|
["http://user:pass@example.com/", "http://user:pass@example.com/"],
|
|
|
|
["http://user@example.com/", "http://user@example.com/"],
|
|
|
|
["http://user:pass@example.com/", "http://u:p@example.com/", "u", "p"],
|
|
|
|
["http://user:pass@example.com/", "http://u@example.com/", "u"],
|
|
|
|
["http://user:pass@example.com/", "http://user:pass@example.com/", "", "p"],
|
|
|
|
["http://example.com/", "http://example.com/", "", "p"],
|
|
|
|
["http://example.com/path", "http://example.com/path"],
|
2019-09-03 23:34:56 +00:00
|
|
|
["http://example.com/PATH", "http://example.com/PATH"],
|
2019-08-27 15:08:13 +00:00
|
|
|
["http://example.com/path/", "http://example.com/path/"],
|
|
|
|
["http://example.com/path/.", "http://example.com/path"],
|
|
|
|
["http://example.com/path/./", "http://example.com/path/"],
|
|
|
|
["http://example.com/path/..", "http://example.com/"],
|
|
|
|
["http://example.com/path/../", "http://example.com/"],
|
|
|
|
["http://example.com/a/b/..", "http://example.com/a"],
|
|
|
|
["http://example.com/a/b/../", "http://example.com/a/"],
|
|
|
|
["http://example.com/../", "http://example.com/"],
|
|
|
|
["http://example.com////", "http://example.com/"],
|
|
|
|
["http://example.com/a/./b/", "http://example.com/a/b/"],
|
|
|
|
["http://example.com/a/../b/", "http://example.com/b/"],
|
|
|
|
["http://example.com/.a/", "http://example.com/.a/"],
|
|
|
|
["http://example.com/..a/", "http://example.com/..a/"],
|
2019-08-27 19:18:02 +00:00
|
|
|
["http://日本.example.com/", "http://日本.example.com/"],
|
|
|
|
["http://EXAMPLE.COM/", "http://example.com/"],
|
|
|
|
["http://É.example.com/", "http://é.example.com/"],
|
2019-09-03 17:16:05 +00:00
|
|
|
["http://[::1]/", "http://[::1]/"],
|
|
|
|
["http://[0::1]/", "http://[::1]/"],
|
|
|
|
["http://[Z]/", "http://[z]/"],
|
|
|
|
["http://example.com/ ?%61=%3d", "http://example.com/%20?a=%3D"],
|
|
|
|
["http://example.com/%", "http://example.com/%25"],
|
|
|
|
["http://example.com/%a", "http://example.com/%25a"],
|
|
|
|
["http://example.com/%za", "http://example.com/%25za"],
|
2019-09-03 23:34:56 +00:00
|
|
|
["//EXAMPLE.COM/", "//example.com/"],
|
|
|
|
["//EXAMPLE.COM/", "//u:p@example.com/", "u", "p"],
|
|
|
|
["/ ", "/%20"],
|
|
|
|
["/ ", "/%20", "u", "p"],
|
|
|
|
["EXAMPLE.COM/", "EXAMPLE.COM/"],
|
|
|
|
["EXAMPLE.COM", "EXAMPLE.COM"],
|
|
|
|
[" ", "%20"],
|
2019-08-27 02:13:30 +00:00
|
|
|
];
|
|
|
|
}
|
2019-09-25 22:30:53 +00:00
|
|
|
|
|
|
|
/** @dataProvider provideQueries */
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAppendQueryParameters(string $url, string $query, string $exp): void {
|
2019-09-25 22:30:53 +00:00
|
|
|
$this->assertSame($exp, URL::queryAppend($url, $query));
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public function provideQueries(): iterable {
|
2019-09-25 22:30:53 +00:00
|
|
|
return [
|
|
|
|
["/", "ook=eek", "/?ook=eek"],
|
|
|
|
["/?", "ook=eek", "/?ook=eek"],
|
|
|
|
["/#ack", "ook=eek", "/?ook=eek#ack"],
|
|
|
|
["/?Huh?", "ook=eek", "/?Huh?&ook=eek"],
|
|
|
|
["/?Eh?&Huh?&", "ook=eek", "/?Eh?&Huh?&ook=eek"],
|
|
|
|
["/#ack", "", "/#ack"],
|
|
|
|
];
|
|
|
|
}
|
2019-10-17 20:23:41 +00:00
|
|
|
|
|
|
|
/** @dataProvider provideAbsolutes */
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testDetermineAbsoluteness(bool $exp, string $url): void {
|
2019-10-17 20:23:41 +00:00
|
|
|
$this->assertSame($exp, URL::absolute($url));
|
|
|
|
}
|
|
|
|
|
2020-01-20 18:34:03 +00:00
|
|
|
public function provideAbsolutes(): array {
|
2019-10-17 20:23:41 +00:00
|
|
|
return [
|
|
|
|
[true, "http://example.com/"],
|
|
|
|
[true, "HTTP://example.com/"],
|
|
|
|
[false, "//example.com/"],
|
|
|
|
[false, "/example"],
|
|
|
|
[false, "example.com/"],
|
|
|
|
[false, "example.com"],
|
|
|
|
[false, "http:///example"],
|
|
|
|
];
|
|
|
|
}
|
2019-08-27 02:13:30 +00:00
|
|
|
}
|