diff --git a/core/testcase.php b/core/testcase.php index f536e92b..74cd686a 100644 --- a/core/testcase.php +++ b/core/testcase.php @@ -161,6 +161,9 @@ if(class_exists("\\PHPUnit\\Framework\\TestCase")) { } } + /** + * Assert that the page contains the given text somewhere in the blocks + */ protected function assert_text(string $text, string $section = null): void { $this->assertStringContainsString($text, $this->page_to_text($section)); @@ -171,6 +174,9 @@ if(class_exists("\\PHPUnit\\Framework\\TestCase")) { $this->assertStringNotContainsString($text, $this->page_to_text($section)); } + /** + * Assert that the page contains the given text somewhere in the binary data + */ protected function assert_content(string $content): void { global $page; diff --git a/ext/download/main.php b/ext/download/main.php index 52f42888..5bf5facc 100644 --- a/ext/download/main.php +++ b/ext/download/main.php @@ -14,17 +14,13 @@ class Download extends Extension return 99; } - public function onImageDownloading(ImageDownloadingEvent $event) { global $page; $page->set_mime($event->mime); - $page->set_mode(PageMode::FILE); - $page->set_file($event->path, $event->file_modified); - $event->stop_processing = true; } } diff --git a/ext/download/test.php b/ext/download/test.php new file mode 100644 index 00000000..b0ac2949 --- /dev/null +++ b/ext/download/test.php @@ -0,0 +1,16 @@ +post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("/image/$image_id"); + $this->assertEquals(PageMode::FILE, $page->mode); + } +} diff --git a/ext/et_server/main.php b/ext/et_server/main.php index c88ac6cc..dbc314c6 100644 --- a/ext/et_server/main.php +++ b/ext/et_server/main.php @@ -12,7 +12,6 @@ class ETServer extends Extension { global $database, $page, $user; if ($event->page_matches("register.php")) { - error_log("register.php"); if (isset($_POST["data"])) { $database->execute( "INSERT INTO registration(data) VALUES(:data)", diff --git a/ext/et_server/test.php b/ext/et_server/test.php new file mode 100644 index 00000000..9b80e637 --- /dev/null +++ b/ext/et_server/test.php @@ -0,0 +1,21 @@ +post_page("register.php", ["data" => "test entry"]); + + $this->log_in_as_user(); + $this->get_page("register.php"); + $this->assert_no_text("test entry"); + + $this->log_in_as_admin(); + $this->get_page("register.php"); + $this->assert_text("test entry"); + } +} diff --git a/ext/image_view_counter/test.php b/ext/image_view_counter/test.php new file mode 100644 index 00000000..1722d1c5 --- /dev/null +++ b/ext/image_view_counter/test.php @@ -0,0 +1,23 @@ +post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->log_in_as_admin(); + $this->get_page("post/view/$image_id"); + $this->assert_text("Views"); + } + + public function testPopular() + { + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("popular_images"); + $this->assert_text("$image_id"); + } +} diff --git a/ext/image_view_counter/theme.php b/ext/image_view_counter/theme.php index d6c07f34..5ba94656 100644 --- a/ext/image_view_counter/theme.php +++ b/ext/image_view_counter/theme.php @@ -6,7 +6,10 @@ namespace Shimmie2; class ImageViewCounterTheme extends Themelet { - public function view_popular($images) + /** + * @param Image[] $images + */ + public function view_popular(array $images) { global $page, $config; $pop_images = "";