[core] fix nicedebug

This commit is contained in:
Shish 2024-02-11 23:28:48 +00:00
parent cf2edb91f5
commit f9d06d5e7e
3 changed files with 14 additions and 4 deletions

View file

@ -91,9 +91,7 @@ class PageRequestEvent extends Event
);
// break the path into parts
$args = explode('/', $path);
$this->args = $args;
$this->args = explode('/', $path);
}
public function get_GET(string $key): ?string
@ -165,6 +163,11 @@ class PageRequestEvent extends Event
return $value;
}
public function page_starts_with(string $name): bool
{
return (count($this->args) >= 1) && ($this->args[0] == $name);
}
/**
* Test if the requested path matches a given pattern.
*

View file

@ -324,7 +324,7 @@ class Setup extends Extension
{
global $config, $page, $user;
if ($event->page_matches("nicedebug")) {
if ($event->page_starts_with("nicedebug")) {
$page->set_mode(PageMode::DATA);
$page->set_data(json_encode_ex([
"args" => $event->args,

View file

@ -16,6 +16,13 @@ class SetupTest extends ShimmiePHPUnitTestCase
$this->assert_no_content("\n");
}
public function testNiceDebug(): void
{
// the automatic testing for shimmie2-examples depends on this
$page = $this->get_page('nicedebug/foo%2Fbar/1');
$this->assertEquals('{"args":["nicedebug","foo%2Fbar","1"]}', $page->data);
}
public function testAuthAnon(): void
{
$this->assertException(PermissionDenied::class, function () {