2020-02-01 22:26:08 +00:00
|
|
|
<?php declare(strict_types=1);
|
2020-03-13 09:23:54 +00:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2020-02-01 22:26:08 +00:00
|
|
|
require_once "core/urls.php";
|
|
|
|
|
2020-03-13 09:23:54 +00:00
|
|
|
class UrlsTest extends TestCase
|
2020-02-01 22:26:08 +00:00
|
|
|
{
|
|
|
|
public function test_make_link()
|
|
|
|
{
|
2020-03-28 14:11:14 +00:00
|
|
|
// basic
|
2020-02-01 22:26:08 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"/test/foo",
|
|
|
|
make_link("foo")
|
|
|
|
);
|
|
|
|
|
2020-03-28 14:11:14 +00:00
|
|
|
// remove leading slash from path
|
2020-02-01 22:26:08 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"/test/foo",
|
|
|
|
make_link("/foo")
|
|
|
|
);
|
2020-03-28 14:11:14 +00:00
|
|
|
|
|
|
|
// query
|
|
|
|
$this->assertEquals(
|
|
|
|
"/test/foo?a=1&b=2",
|
|
|
|
make_link("foo", "a=1&b=2")
|
|
|
|
);
|
|
|
|
|
|
|
|
// hash
|
|
|
|
$this->assertEquals(
|
|
|
|
"/test/foo#cake",
|
|
|
|
make_link("foo", null, "cake")
|
|
|
|
);
|
|
|
|
|
|
|
|
// query + hash
|
|
|
|
$this->assertEquals(
|
|
|
|
"/test/foo?a=1&b=2#cake",
|
|
|
|
make_link("foo", "a=1&b=2", "cake")
|
|
|
|
);
|
2020-02-01 22:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_make_http()
|
|
|
|
{
|
|
|
|
// relative to shimmie install
|
|
|
|
$this->assertEquals(
|
2020-10-24 12:46:49 +00:00
|
|
|
"http://cli-command/test/foo",
|
2020-02-01 22:26:08 +00:00
|
|
|
make_http("foo")
|
|
|
|
);
|
|
|
|
|
|
|
|
// relative to web server
|
|
|
|
$this->assertEquals(
|
2020-10-24 12:46:49 +00:00
|
|
|
"http://cli-command/foo",
|
2020-02-01 22:26:08 +00:00
|
|
|
make_http("/foo")
|
|
|
|
);
|
|
|
|
|
|
|
|
// absolute
|
|
|
|
$this->assertEquals(
|
2020-03-25 11:47:00 +00:00
|
|
|
"https://foo.com",
|
|
|
|
make_http("https://foo.com")
|
2020-02-01 22:26:08 +00:00
|
|
|
);
|
|
|
|
}
|
2020-03-27 23:35:07 +00:00
|
|
|
|
|
|
|
public function test_modify_url()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
"/foo/bar?a=3&b=2",
|
|
|
|
modify_url("/foo/bar?a=1&b=2", ["a"=>"3"])
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
"https://blah.com/foo/bar?b=2",
|
|
|
|
modify_url("https://blah.com/foo/bar?a=1&b=2", ["a"=>null])
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
"/foo/bar",
|
|
|
|
modify_url("/foo/bar?a=1&b=2", ["a"=>null, "b"=>null])
|
|
|
|
);
|
|
|
|
}
|
2020-03-28 14:11:14 +00:00
|
|
|
|
|
|
|
public function test_referer_or()
|
|
|
|
{
|
|
|
|
unset($_SERVER['HTTP_REFERER']);
|
|
|
|
$this->assertEquals(
|
|
|
|
"foo",
|
|
|
|
referer_or("foo")
|
|
|
|
);
|
|
|
|
|
|
|
|
$_SERVER['HTTP_REFERER'] = "cake";
|
|
|
|
$this->assertEquals(
|
|
|
|
"cake",
|
|
|
|
referer_or("foo")
|
|
|
|
);
|
|
|
|
|
|
|
|
$_SERVER['HTTP_REFERER'] = "cake";
|
|
|
|
$this->assertEquals(
|
|
|
|
"foo",
|
|
|
|
referer_or("foo", ["cake"])
|
|
|
|
);
|
|
|
|
}
|
2020-02-01 22:26:08 +00:00
|
|
|
}
|