Merge branch 'branch-2.10'

This commit is contained in:
Shish
2024-02-08 00:41:38 +00:00
42 changed files with 132 additions and 1259 deletions

View File

@@ -254,4 +254,42 @@ class PolyfillsTest extends TestCase
deltree($dir);
$this->assertFalse(file_exists($dir));
}
private function _tbh(array $vars, string $result): void
{
// update $_SERVER with $vars, call get_base_href() and check result, then reset $_SERVER to original value
$old_server = $_SERVER;
$_SERVER = array_merge($_SERVER, $vars);
$this->assertEquals($result, get_base_href());
$_SERVER = $old_server;
}
public function test_get_base_href(): void
{
// PHP_SELF should point to "the currently executing script
// relative to the document root"
$this->_tbh(["PHP_SELF" => "/index.php"], "");
$this->_tbh(["PHP_SELF" => "/mydir/index.php"], "/mydir");
// SCRIPT_FILENAME should point to "the absolute pathname of
// the currently executing script" and DOCUMENT_ROOT should
// point to "the document root directory under which the
// current script is executing"
$this->_tbh([
"PHP_SELF" => "<invalid>",
"SCRIPT_FILENAME" => "/var/www/html/mydir/index.php",
"DOCUMENT_ROOT" => "/var/www/html",
], "/mydir");
$this->_tbh([
"PHP_SELF" => "<invalid>",
"SCRIPT_FILENAME" => "/var/www/html/mydir/index.php",
"DOCUMENT_ROOT" => "/var/www/html/",
], "/mydir");
$this->_tbh([
"PHP_SELF" => "<invalid>",
"SCRIPT_FILENAME" => "/var/www/html/index.php",
"DOCUMENT_ROOT" => "/var/www/html",
], "");
}
}

View File

@@ -162,4 +162,27 @@ class UtilTest extends TestCase
path_to_tags("/category:/tag/baz.jpg")
);
}
public function test_get_query(): void
{
// niceurls
$_SERVER["REQUEST_URI"] = "/test/tasty/cake";
$this->assertEquals("/tasty/cake", _get_query());
// no niceurls
$_SERVER["REQUEST_URI"] = "/test/index.php?q=/tasty/cake";
$this->assertEquals("/tasty/cake", _get_query());
// leave url encoding alone
$_SERVER["REQUEST_URI"] = "/test/index.php?q=/tasty/cake%20pie";
$this->assertEquals("/tasty/cake%20pie", _get_query());
// if just viewing index.php
$_SERVER["REQUEST_URI"] = "/test/index.php";
$this->assertEquals("/", _get_query());
// niceurl root
$_SERVER["REQUEST_URI"] = "/test/";
$this->assertEquals("/", _get_query());
}
}