fix all the tests (for sqlite, php7.4, osx, at least)
This commit is contained in:
@ -12,28 +12,28 @@ class RandomImage extends Extension
|
||||
$search_terms = [];
|
||||
} elseif ($event->count_args() == 2) {
|
||||
$action = $event->get_arg(0);
|
||||
$search_terms = explode(' ', $event->get_arg(1));
|
||||
$search_terms = Tag::explode($event->get_arg(1));
|
||||
} else {
|
||||
throw new SCoreException("Error: too many arguments.");
|
||||
}
|
||||
$image = Image::by_random($search_terms);
|
||||
if(!$image) {
|
||||
throw new SCoreException(
|
||||
"Couldn't find any images randomly",
|
||||
Tag::implode($search_terms)
|
||||
);
|
||||
}
|
||||
|
||||
if ($action === "download") {
|
||||
if (!is_null($image)) {
|
||||
$page->set_mode(PageMode::DATA);
|
||||
$page->set_type($image->get_mime_type());
|
||||
$page->set_data(file_get_contents($image->get_image_filename()));
|
||||
}
|
||||
$page->set_mode(PageMode::DATA);
|
||||
$page->set_type($image->get_mime_type());
|
||||
$page->set_data(file_get_contents($image->get_image_filename()));
|
||||
} elseif ($action === "view") {
|
||||
if (!is_null($image)) {
|
||||
send_event(new DisplayingImageEvent($image));
|
||||
}
|
||||
send_event(new DisplayingImageEvent($image));
|
||||
} elseif ($action === "widget") {
|
||||
if (!is_null($image)) {
|
||||
$page->set_mode(PageMode::DATA);
|
||||
$page->set_type("text/html");
|
||||
$page->set_data($this->theme->build_thumb_html($image));
|
||||
}
|
||||
$page->set_mode(PageMode::DATA);
|
||||
$page->set_type("text/html");
|
||||
$page->set_data($this->theme->build_thumb_html($image));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php declare(strict_types=1);
|
||||
class RandomTest extends ShimmiePHPUnitTestCase
|
||||
class RandomImageTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testRandom()
|
||||
{
|
||||
@ -7,53 +7,41 @@ class RandomTest extends ShimmiePHPUnitTestCase
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
||||
$this->log_out();
|
||||
|
||||
$this->get_page("random_image/view");
|
||||
$this->assert_title("Image $image_id: test");
|
||||
$page = $this->get_page("random_image/view");
|
||||
$this->assertEquals("Image $image_id: test", $page->title);
|
||||
|
||||
$this->get_page("random_image/view/test");
|
||||
$this->assert_title("Image $image_id: test");
|
||||
$page = $this->get_page("random_image/view/test");
|
||||
$this->assertEquals("Image $image_id: test", $page->title);
|
||||
|
||||
$this->get_page("random_image/download");
|
||||
$page = $this->get_page("random_image/download");
|
||||
$this->assertNotNull($page->data);
|
||||
# FIXME: assert($raw == file(blah.jpg))
|
||||
}
|
||||
|
||||
public function testPostListBlock()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page("setup");
|
||||
|
||||
$this->markTestIncomplete();
|
||||
|
||||
$this->set_field("_config_show_random_block", true);
|
||||
$this->click("Save Settings");
|
||||
$this->log_out();
|
||||
|
||||
# enabled, no image = no text
|
||||
$this->get_page("post/list");
|
||||
$this->assert_no_text("Random Image");
|
||||
|
||||
$this->log_in_as_user();
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
||||
$this->log_out();
|
||||
$config->set_bool("show_random_block", true);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
|
||||
# enabled, image = text
|
||||
$this->get_page("post/list");
|
||||
$this->assert_text("Random Image");
|
||||
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page("setup");
|
||||
$this->set_field("_config_show_random_block", true);
|
||||
$this->click("Save Settings");
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNotNull($page->find_block("Random Image"));
|
||||
|
||||
# disabled, image = no text
|
||||
$this->get_page("post/list");
|
||||
$this->assert_text("Random Image");
|
||||
|
||||
$this->delete_image($image_id);
|
||||
$this->log_out();
|
||||
$config->set_bool("show_random_block", false);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
|
||||
# disabled, no image = no image
|
||||
$this->get_page("post/list");
|
||||
$this->assert_no_text("Random Image");
|
||||
$this->delete_image($image_id);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\{DIV,A,IMG};
|
||||
|
||||
class RandomImageTheme extends Themelet
|
||||
{
|
||||
@ -9,20 +10,24 @@ class RandomImageTheme extends Themelet
|
||||
|
||||
public function build_random_html(Image $image, ?string $query = null): string
|
||||
{
|
||||
$i_id = int_escape($image->id);
|
||||
$h_view_link = make_link("post/view/$i_id", $query);
|
||||
$h_thumb_link = $image->get_thumb_link();
|
||||
$h_tip = html_escape($image->get_tooltip());
|
||||
$tsize = get_thumbnail_size($image->width, $image->height);
|
||||
|
||||
return "
|
||||
<center><div>
|
||||
|
||||
<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
|
||||
<img id='thumb_rand_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
|
||||
</a>
|
||||
|
||||
</div></center>
|
||||
";
|
||||
return (string)DIV(
|
||||
["style"=>"text-align: center;"],
|
||||
A(
|
||||
[
|
||||
"href"=>make_link("post/view/{$image->id}", $query),
|
||||
"style"=>"position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;"
|
||||
],
|
||||
IMG([
|
||||
"id"=>"thumb_rand_{$image->id}",
|
||||
"title"=>$image->get_tooltip(),
|
||||
"alt"=>$image->get_tooltip(),
|
||||
"class"=>'highlighted',
|
||||
"style"=>"height: {$tsize[1]}px; width: {$tsize[0]}px;",
|
||||
"src"=>$image->get_thumb_link()
|
||||
])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user