more tests

This commit is contained in:
Shish 2024-01-03 03:45:06 +00:00
parent 2f2f8e2eda
commit 1f9de8dd5a
7 changed files with 70 additions and 6 deletions

View file

@ -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;

View file

@ -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;
}
}

16
ext/download/test.php Normal file
View file

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class DownloadTest extends ShimmiePHPUnitTestCase
{
public function testView()
{
global $page;
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
$this->get_page("/image/$image_id");
$this->assertEquals(PageMode::FILE, $page->mode);
}
}

View file

@ -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)",

21
ext/et_server/test.php Normal file
View file

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class ETServerTest extends ShimmiePHPUnitTestCase
{
public function testView()
{
$this->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");
}
}

View file

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class ImageViewCounterTest extends ShimmiePHPUnitTestCase
{
public function testPostView()
{
$image_id = $this->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");
}
}

View file

@ -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 = "";