summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-03-22 12:24:31 +0300
committerAndrew Dolgov <[email protected]>2022-03-22 12:24:31 +0300
commit1c4f7ab3b838b23afb2ee4dab14acbf75956e952 (patch)
tree0a19274107d717efe92d2c0376cd3105fead5a11 /tests
parent711662948768492e8d05b778a7d80eacaec368d2 (diff)
* add phpunit as a dev dependency
* add some basic tests for UrlHelper::rewrite_relative() * fix UrlHelper::rewrite_relative() to work better on non-absolute relative URL paths
Diffstat (limited to 'tests')
-rw-r--r--tests/UrlHelperTest.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/UrlHelperTest.php b/tests/UrlHelperTest.php
new file mode 100644
index 000000000..2d92c332b
--- /dev/null
+++ b/tests/UrlHelperTest.php
@@ -0,0 +1,54 @@
+<?php
+set_include_path(dirname(__DIR__) ."/include" . PATH_SEPARATOR .
+ get_include_path());
+
+require_once "autoload.php";
+require_once "functions.php";
+
+use PHPUnit\Framework\TestCase;
+
+final class UrlHelperTest extends TestCase {
+ public function testCanBeUsedAsString(): void {
+ /*$this->assertEquals(
+ 'http://example.com/example.html',
+ UrlHelper::rewrite_relative('http://example.com/example/', '/example.html')
+ );
+
+ $this->assertEquals(
+ 'http://example.com/example/example.html',
+ UrlHelper::rewrite_relative('http://example.com/example/', 'example.html')
+ );*/
+
+ // protocol-neutral URL
+ $this->assertEquals(
+ 'https://example.com/example.html',
+ UrlHelper::rewrite_relative('http://example.com/example/', '//example.com/example.html')
+ );
+
+ // magnet allowed because it's a href attribute
+ $this->assertEquals(
+ 'magnet:?xt=urn:btih:...',
+ UrlHelper::rewrite_relative('http://example.com/example/',
+ 'magnet:?xt=urn:btih:...',
+ "a", "href", "")
+ );
+
+ // disallowed magnet
+ $this->assertEquals(
+ 'http://example.com?xt=urn:btih:...',
+ UrlHelper::rewrite_relative('http://example.com/example/',
+ 'magnet:?xt=urn:btih:...')
+ );
+
+ $this->assertEquals(
+ 'https://apod.nasa.gov/apod/image/2203/Road2Stars_EsoHoralek_1080.jpg',
+ UrlHelper::rewrite_relative('https://apod.nasa.gov/apod/ap220315.html', 'image/2203/Road2Stars_EsoHoralek_1080.jpg')
+ );
+
+ $this->assertEquals(
+ 'https://apod.nasa.gov/apod/image/2203/Road2Stars_EsoHoralek_1080.jpg',
+ UrlHelper::rewrite_relative('https://apod.nasa.gov/apod/ap220315.html', './image/2203/Road2Stars_EsoHoralek_1080.jpg')
+ );
+
+ }
+}