diff --git a/core/tests/BasePageTest.php b/core/tests/BasePageTest.php index 922bc6a5..64ed41e5 100644 --- a/core/tests/BasePageTest.php +++ b/core/tests/BasePageTest.php @@ -52,4 +52,12 @@ class BasePageTest extends TestCase ob_end_clean(); $this->assertTrue(true); // doesn't crash } + + public function test_subNav(): void + { + // the default theme doesn't send this, so let's have + // a random test manually + send_event(new PageSubNavBuildingEvent("system")); + $this->assertTrue(true); // doesn't crash + } } diff --git a/ext/admin/main.php b/ext/admin/main.php index 1020d602..c9e50518 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -154,6 +154,15 @@ class AdminPage extends Extension }); } + public function onAdminAction(AdminActionEvent $event): void + { + global $page; + if ($event->action === "test") { + $page->set_mode(PageMode::DATA); + $page->set_data("test"); + } + } + public function onAdminBuilding(AdminBuildingEvent $event): void { $this->theme->display_page(); diff --git a/ext/admin/test.php b/ext/admin/test.php index 2bbd051e..332f7475 100644 --- a/ext/admin/test.php +++ b/ext/admin/test.php @@ -8,19 +8,34 @@ class AdminPageTest extends ShimmiePHPUnitTestCase { public function testAuth(): void { - send_event(new UserLoginEvent(User::by_name(self::$anon_name))); + $this->log_out(); $this->assertException(PermissionDeniedException::class, function () { $this->get_page('admin'); }); - send_event(new UserLoginEvent(User::by_name(self::$user_name))); + $this->log_in_as_user(); $this->assertException(PermissionDeniedException::class, function () { $this->get_page('admin'); }); - send_event(new UserLoginEvent(User::by_name(self::$admin_name))); + $this->log_in_as_admin(); $page = $this->get_page('admin'); $this->assertEquals(200, $page->code); $this->assertEquals("Admin Tools", $page->title); } + + public function testAct(): void + { + $this->log_in_as_admin(); + $page = $this->post_page('admin/test'); + $this->assertEquals("test", $page->data); + } + + // does this belong here?? + public function testCliGen(): void + { + $app = new CliApp(); + send_event(new CliGenEvent($app)); + $this->assertTrue(true); // TODO: check for more than "no crash"? + } } diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 86bc2e2d..4fbbaef7 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -52,7 +52,7 @@ class DeleteAliasEvent extends Event } } -class AddAliasException extends SCoreException +class AddAliasException extends UserErrorException { } @@ -67,13 +67,9 @@ class AliasEditor extends Extension if ($event->page_matches("alias/add", method: "POST", permission: Permissions::MANAGE_ALIAS_LIST)) { $input = validate_input(["c_oldtag" => "string", "c_newtag" => "string"]); - try { - send_event(new AddAliasEvent($input['c_oldtag'], $input['c_newtag'])); - $page->set_mode(PageMode::REDIRECT); - $page->set_redirect(make_link("alias/list")); - } catch (AddAliasException $ex) { - $this->theme->display_error(500, "Error adding alias", $ex->getMessage()); - } + send_event(new AddAliasEvent($input['c_oldtag'], $input['c_newtag'])); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link("alias/list")); } if ($event->page_matches("alias/remove", method: "POST", permission: Permissions::MANAGE_ALIAS_LIST)) { $input = validate_input(["d_oldtag" => "string"]); diff --git a/ext/alias_editor/test.php b/ext/alias_editor/test.php index 55522cde..1cb9e113 100644 --- a/ext/alias_editor/test.php +++ b/ext/alias_editor/test.php @@ -33,7 +33,7 @@ class AliasEditorTest extends ShimmiePHPUnitTestCase $this->get_page("alias/export/aliases.csv"); $this->assert_no_text("test1"); - send_event(new AddAliasEvent("test1", "test2")); + $this->post_page('alias/add', ['c_oldtag' => 'test1', 'c_newtag' => 'test2']); $this->get_page('alias/list'); $this->assert_text("test1"); $this->get_page("alias/export/aliases.csv"); @@ -48,7 +48,7 @@ class AliasEditorTest extends ShimmiePHPUnitTestCase $this->assert_response(302); $this->delete_image($image_id); - send_event(new DeleteAliasEvent("test1")); + $this->post_page('alias/remove', ['d_oldtag' => 'test1']); $this->get_page('alias/list'); $this->assert_title("Alias List"); $this->assert_no_text("test1"); diff --git a/ext/approval/main.php b/ext/approval/main.php index 323e7534..8614440c 100644 --- a/ext/approval/main.php +++ b/ext/approval/main.php @@ -57,7 +57,8 @@ class Approval extends Extension public function onSetupBuilding(SetupBuildingEvent $event): void { - $this->theme->display_admin_block($event); + $sb = $event->panel->create_new_block("Approval"); + $sb->add_bool_option(ApprovalConfig::IMAGES, "Posts: "); } public function onAdminBuilding(AdminBuildingEvent $event): void @@ -89,7 +90,6 @@ class Approval extends Extension ); break; default: - break; } } @@ -99,7 +99,7 @@ class Approval extends Extension { global $page; - if (!$this->check_permissions(($event->image))) { + if (!$this->check_permissions($event->image)) { $page->set_mode(PageMode::REDIRECT); $page->set_redirect(make_link()); } @@ -207,7 +207,7 @@ class Approval extends Extension * Deny images upon insufficient permissions. **/ if (!$this->check_permissions($event->image)) { - throw new SCoreException("Access denied"); + throw new PermissionDeniedException("Access denied"); } } diff --git a/ext/approval/test.php b/ext/approval/test.php new file mode 100644 index 00000000..348d295d --- /dev/null +++ b/ext/approval/test.php @@ -0,0 +1,43 @@ +log_in_as_user(); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "some_tag"); + $this->assert_search_results(["some_tag"], [$image_id]); + } + + public function testApprovalNeeded(): void + { + global $config; + $config->set_bool(ApprovalConfig::IMAGES, true); + + // use can post but not see what they posted + $this->log_in_as_user(); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "some_tag"); + $this->assert_search_results(["some_tag"], []); + + // admin can approve + $this->log_in_as_admin(); + $this->assert_search_results(["some_tag"], []); + $this->post_page("approve_image/$image_id"); + $this->assert_search_results(["some_tag"], [$image_id]); + + // use then sees the image + $this->log_in_as_user(); + $this->assert_search_results(["some_tag"], [$image_id]); + } + + public function tearDown(): void + { + global $config; + $config->set_bool(ApprovalConfig::IMAGES, false); + parent::tearDown(); + } +} diff --git a/ext/approval/theme.php b/ext/approval/theme.php index b4cb2dc0..28aee035 100644 --- a/ext/approval/theme.php +++ b/ext/approval/theme.php @@ -8,7 +8,7 @@ use MicroHTML\HTMLElement; use function MicroHTML\emptyHTML; -use function MicroHTML\{BUTTON,INPUT,P}; +use function MicroHTML\{BUTTON,P}; class ApprovalTheme extends Themelet { @@ -21,12 +21,6 @@ class ApprovalTheme extends Themelet ); } - public function display_admin_block(SetupBuildingEvent $event): void - { - $sb = $event->panel->create_new_block("Approval"); - $sb->add_bool_option(ApprovalConfig::IMAGES, "Posts: "); - } - public function display_admin_form(): void { global $page;