From 179e18abb23003d20d9454d99beee19b2c496637 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 15 Jul 2009 22:17:53 +0100 Subject: [PATCH 1/6] warn about missing mysql --- install.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/install.php b/install.php index 445afa44..b0b8e0b2 100644 --- a/install.php +++ b/install.php @@ -92,20 +92,45 @@ function do_install() { // {{{ } } // }}} function begin() { // {{{ + $err = ""; + $thumberr = ""; + $dberr = ""; + if(check_gd_version() == 0 && check_im_version() == 0) { - $gd = "

Error

\nPHP's GD extension seems to be missing, ". + $thumberr = "

PHP's GD extension seems to be missing, ". "and imagemagick's \"convert\" command cannot be found - ". "no thumbnailing engines are available."; } - else { - $gd = ""; + + if(!function_exists("mysql_connect")) { + $dberr = "

PHP's MySQL extension seems to be missing; you may ". + "be able to use an unofficial alternative, checking ". + "for libraries..."; + if(!function_exists("pg_connect")) { + $dberr .= "
PgSQL is missing"; + } + else { + $dberr .= "
PgSQL is available"; + } + if(!function_exists("sqlite_open")) { + $dberr .= "
SQLite is missing"; + } + else { + $dberr .= "
SQLite is available"; + } + } + + if($thumberr || $dberr) { + $err = "

Error

"; } print <<

Shimmie Installer

- $gd + $err + $thumberr + $dberr

Install

From 4f141975778bdbc8a61812b7e785880a8fa51965 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 15 Jul 2009 22:20:10 +0100 Subject: [PATCH 2/6] remove the auto install file after using it --- install.php | 1 + 1 file changed, 1 insertion(+) diff --git a/install.php b/install.php index b0b8e0b2..d87d8a1b 100644 --- a/install.php +++ b/install.php @@ -86,6 +86,7 @@ function do_install() { // {{{ } else if(file_exists("auto_install.conf")) { install_process(trim(file_get_contents("auto_install.conf"))); + unlink("auto_install.conf"); } else { begin(); From 9d968b630df4260c233b0b8e7a12ca393b8980e8 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 15 Jul 2009 23:29:01 +0100 Subject: [PATCH 3/6] more reliable self finding --- contrib/simpletest/main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php index 2793ec93..9240b258 100644 --- a/contrib/simpletest/main.php +++ b/contrib/simpletest/main.php @@ -17,7 +17,9 @@ define('ADMIN_PASS', "demo"); class ShimmieWebTestCase extends WebTestCase { protected function get_page($page) { - $this->get($_SERVER["HTTP_HOST"].'/'.make_link($page)); + $url = "http://".$_SERVER["HTTP_HOST"].get_base_href().'/'.make_link($page); + $url = str_replace("/./", "/", $url); + $this->get($url); } protected function log_in_as_user() { $this->get_page('post/list'); From d7ce9add6a834b5886f5972a037b93dc20a9501e Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 15 Jul 2009 23:29:14 +0100 Subject: [PATCH 4/6] aaaaaaaargh dates and times in sql --- core/database.class.php | 2 ++ install.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 3b7b3ed1..2880684b 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -72,6 +72,7 @@ class MySQL extends DBEngine { $data = str_replace("SCORE_BOOL_Y", "'Y'", $data); $data = str_replace("SCORE_BOOL_N", "'N'", $data); $data = str_replace("SCORE_BOOL", "ENUM('Y', 'N')", $data); + $data = str_replace("SCORE_DATETIME", "DATETIME", $data); $data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data); $ctes = "TYPE=InnoDB DEFAULT CHARSET='utf8'"; return "CREATE TABLE $name ($data) $ctes"; @@ -86,6 +87,7 @@ class PostgreSQL extends DBEngine { $data = str_replace("SCORE_BOOL_Y", "'t'", $data); $data = str_replace("SCORE_BOOL_N", "'f'", $data); $data = str_replace("SCORE_BOOL", "BOOL", $data); + $data = str_replace("SCORE_DATETIME", "TIMESTAMP", $data); $data = str_replace("SCORE_NOW", "current_time", $data); return "CREATE TABLE $name ($data)"; } diff --git a/install.php b/install.php index d87d8a1b..bb869e5a 100644 --- a/install.php +++ b/install.php @@ -197,7 +197,7 @@ function create_tables($dsn) { // {{{ id SCORE_AIPK, name VARCHAR(32) UNIQUE NOT NULL, pass CHAR(32), - joindate DATETIME NOT NULL DEFAULT SCORE_NOW, + joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW, admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, email VARCHAR(128) ")); @@ -212,7 +212,7 @@ function create_tables($dsn) { // {{{ source VARCHAR(255), width INTEGER NOT NULL, height INTEGER NOT NULL, - posted TIMESTAMP NOT NULL DEFAULT SCORE_NOW, + posted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW, locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, INDEX(owner_id), INDEX(width), From d08b7faf63a7d256f4f697fa9afcd2890be9f29d Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 16 Jul 2009 20:20:53 +0100 Subject: [PATCH 5/6] more tests --- contrib/handle_flash/main.php | 64 +++++++++++------------------------ contrib/handle_ico/main.php | 9 +++-- contrib/handle_mp3/main.php | 39 +++++---------------- contrib/handle_svg/main.php | 16 +++++---- contrib/rss_images/test.php | 14 +++++--- contrib/word_filter/main.php | 2 ++ contrib/word_filter/test.php | 55 +++++++++++++++++++++++++++++- core/extension.class.php | 36 ++++++++++++++++++++ ext/alias_editor/test.php | 56 ++++++++++++++++++++++++++++++ ext/handle_pixel/main.php | 40 +++------------------- ext/index/test.php | 8 +++++ ext/upload/main.php | 3 ++ ext/upload/test.php | 18 ++++++++++ 13 files changed, 233 insertions(+), 127 deletions(-) diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index cd2671c4..be3ac459 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -5,46 +5,19 @@ * Description: Handle Flash files */ -class FlashFileHandler extends SimpleExtension { - public function onDataUpload($event) { - if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - if(!move_upload_to_archive($event)) return; - send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); - $image = $this->create_image_from_data("images/$ha/$hash", $event->metadata); - if(is_null($image)) { - throw new UploadException( - "Flash Handler failed to create image object from data. ". - "Note: compressed flash files are currently unsupported"); - } - send_event(new ImageAdditionEvent($event->user, $image)); - } +class FlashFileHandler extends DataHandlerExtension { + protected function create_thumb($hash) { + $ha = substr($hash, 0, 2); + // FIXME: scale image, as not all boards use 192x192 + copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash"); } - public function onThumbnailGeneration($event) { - if($this->supported_ext($event->type)) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - // FIXME: scale image, as not all boards use 192x192 - copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash"); - } - } - - public function onDisplayingImage($event) { - global $page; - if($this->supported_ext($event->image->ext)) { - $this->theme->display_image($event->page, $event->image); - } - } - - - private function supported_ext($ext) { + protected function supported_ext($ext) { $exts = array("swf"); return in_array(strtolower($ext), $exts); } - private function create_image_from_data($filename, $metadata) { + protected function create_image_from_data($filename, $metadata) { global $config; $image = new Image(); @@ -72,6 +45,17 @@ class FlashFileHandler extends SimpleExtension { return $image; } + protected function check_contents($file) { + if(!file_exists($file)) return false; + + $fp = fopen($file, "r"); + $head = fread($fp, 3); + fclose($fp); + if(!in_array($head, array("CWS", "FWS"))) return false; + + return true; + } + private function str_to_binarray($string) { $binary = array(); for($j=0; $j diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 678f2579..45f2940f 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -16,7 +16,9 @@ class IcoFileHandler extends SimpleExtension { if(is_null($image)) { throw new UploadException("Icon handler failed to create image object from data"); } - send_event(new ImageAdditionEvent($event->user, $image)); + $iae = new ImageAdditionEvent($event->user, $image); + send_event($iae); + $event->image_id = $iae->image->id; } } @@ -27,13 +29,14 @@ class IcoFileHandler extends SimpleExtension { } public function onDisplayingImage($event) { + global $page; if($this->supported_ext($event->image->ext)) { - $this->theme->display_image($event->page, $event->image); + $this->theme->display_image($page, $event->image); } } public function onPageRequest($event) { - global $config, $database; + global $config, $database, $page; if($event->page_matches("get_ico")) { $id = int_escape($event->get_arg(0)); $image = Image::by_id($id); diff --git a/contrib/handle_mp3/main.php b/contrib/handle_mp3/main.php index dc771a93..91255f5a 100644 --- a/contrib/handle_mp3/main.php +++ b/contrib/handle_mp3/main.php @@ -5,42 +5,19 @@ * Description: Handle MP3 files */ -class MP3FileHandler implements Extension { - var $theme; - - public function receive_event(Event $event) { - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - if(!move_upload_to_archive($event)) return; - send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); - $image = $this->create_image_from_data("images/$ha/$hash", $event->metadata); - if(is_null($image)) { - throw new UploadException("MP3 handler failed to create image object from data"); - } - send_event(new ImageAdditionEvent($event->user, $image)); - } - - if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - // FIXME: scale image, as not all boards use 192x192 - copy("ext/handle_mp3/thumb.jpg", "thumbs/$ha/$hash"); - } - - if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { - $this->theme->display_image($event->page, $event->image); - } +class MP3FileHandler extends DataHandlerExtension { + protected function create_thumb($hash) { + $ha = substr($hash, 0, 2); + // FIXME: scale image, as not all boards use 192x192 + copy("ext/handle_mp3/thumb.jpg", "thumbs/$ha/$hash"); } - private function supported_ext($ext) { + protected function supported_ext($ext) { $exts = array("mp3"); return in_array(strtolower($ext), $exts); } - private function create_image_from_data($filename, $metadata) { + protected function create_image_from_data($filename, $metadata) { global $config; $image = new Image(); @@ -59,7 +36,7 @@ class MP3FileHandler implements Extension { return $image; } - private function check_contents($file) { + protected function check_contents($file) { // FIXME: mp3 magic header? return (file_exists($file)); } diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index 741a3805..401898cb 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -20,7 +20,9 @@ class SVGFileHandler implements Extension { if(is_null($image)) { throw new UploadException("SVG handler failed to create image object from data"); } - send_event(new ImageAdditionEvent($event->user, $image)); + $iae = new ImageAdditionEvent($event->user, $image); + send_event($iae); + $event->image_id = $iae->image->id; } if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { @@ -44,20 +46,20 @@ class SVGFileHandler implements Extension { } if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { - $this->theme->display_image($event->page, $event->image); + global $page; + $this->theme->display_image($page, $event->image); } if(($event instanceof PageRequestEvent) && $event->page_matches("get_svg")) { - global $config; - global $database; + global $config, $database, $page; $id = int_escape($event->get_arg(0)); $image = Image::by_id($id); $hash = $image->hash; $ha = substr($hash, 0, 2); - $event->page->set_type("image/svg+xml"); - $event->page->set_mode("data"); - $event->page->set_data(file_get_contents("images/$ha/$hash")); + $page->set_type("image/svg+xml"); + $page->set_mode("data"); + $page->set_data(file_get_contents("images/$ha/$hash")); } } diff --git a/contrib/rss_images/test.php b/contrib/rss_images/test.php index fb27131b..9b1c4f3a 100644 --- a/contrib/rss_images/test.php +++ b/contrib/rss_images/test.php @@ -5,9 +5,6 @@ class RSSImagesTest extends ShimmieWebTestCase { $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); $this->log_out(); - $this->assertTitle("Upload Status"); - $this->assertText("already has hash"); - $this->get_page('rss/images'); $this->assertMime("application/rss+xml"); $this->assertNoText("Exception"); @@ -16,11 +13,18 @@ class RSSImagesTest extends ShimmieWebTestCase { $this->assertMime("application/rss+xml"); $this->assertNoText("Exception"); - $this->get_page('rss/images/tagme/1'); + # FIXME: test that the image is actually found + $this->get_page('rss/images/computer/1'); $this->assertMime("application/rss+xml"); $this->assertNoText("Exception"); - $this->get_page('rss/images/tagme/2'); + # valid tag, invalid page + $this->get_page('rss/images/computer/2'); + $this->assertMime("application/rss+xml"); + $this->assertNoText("Exception"); + + # not found + $this->get_page('rss/images/waffle/2'); $this->assertMime("application/rss+xml"); $this->assertNoText("Exception"); diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php index f471b8d4..dc2a8f9a 100644 --- a/contrib/word_filter/main.php +++ b/contrib/word_filter/main.php @@ -23,6 +23,8 @@ class WordFilter implements Extension { private function filter($text) { $map = $this->get_map(); foreach($map as $search => $replace) { + $search = trim($search); + $replace = trim($replace); $search = "/\\b$search\\b/i"; $text = preg_replace($search, $replace, $text); } diff --git a/contrib/word_filter/test.php b/contrib/word_filter/test.php index e82fa0ad..e84c8882 100644 --- a/contrib/word_filter/test.php +++ b/contrib/word_filter/test.php @@ -1,5 +1,58 @@ log_in_as_admin(); + $this->get_page("setup"); + $this->setField("_config_word_filter", "whore,nice lady\na duck,a kitten\n white ,\tspace\ninvalid"); + $this->click("Save Settings"); + $this->log_out(); + + $this->log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->get_page("post/view/$image_id"); + + # regular + $this->setField('comment', "posted by a whore"); + $this->click("Post Comment"); + $this->assertText("posted by a nice lady"); + + # replace all instances + $this->setField('comment', "a whore is a whore is a whore"); + $this->click("Post Comment"); + $this->assertText("a nice lady is a nice lady is a nice lady"); + + # still have effect when case is changed + $this->setField('comment', "monkey WhorE"); + $this->click("Post Comment"); + $this->assertText("monkey nice lady"); + + # only do whole words + $this->setField('comment', "my name is whoretta"); + $this->click("Post Comment"); + $this->assertText("my name is whoretta"); + + # search multiple words + $this->setField('comment', "I would like a duck"); + $this->click("Post Comment"); + $this->assertText("I would like a kitten"); + + # test for a line which was entered with extra whitespace + $this->setField('comment', "A colour is white"); + $this->click("Post Comment"); + $this->assertText("A colour is space"); + + # don't do anything with invalid lines + $this->setField('comment', "The word was invalid"); + $this->click("Post Comment"); + $this->assertText("The word was invalid"); + + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + } +} if(!defined(VERSION)) return; diff --git a/core/extension.class.php b/core/extension.class.php index acffecf2..1c498170 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -54,4 +54,40 @@ abstract class FormatterExtension implements Extension { abstract public function format($text); abstract public function strip($text); } + +abstract class DataHandlerExtension implements Extension { + var $theme; + + public function receive_event(Event $event) { + if(is_null($this->theme)) $this->theme = get_theme_object($this); + + if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { + $hash = $event->hash; + $ha = substr($hash, 0, 2); + if(!move_upload_to_archive($event)) return; + send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); + $image = $this->create_image_from_data("images/$ha/$hash", $event->metadata); + if(is_null($image)) { + throw new UploadException("Data handler failed to create image object from data"); + } + $iae = new ImageAdditionEvent($event->user, $image); + send_event($iae); + $event->image_id = $iae->image->id; + } + + if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { + $this->create_thumb($event->hash); + } + + if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { + global $page; + $this->theme->display_image($page, $event->image); + } + } + + abstract protected function supported_ext($ext); + abstract protected function check_contents($tmpname); + abstract protected function create_image_from_data($filename, $metadata); + abstract protected function create_thumb($hash); +} ?> diff --git a/ext/alias_editor/test.php b/ext/alias_editor/test.php index 5eeb6c80..8d6f469d 100644 --- a/ext/alias_editor/test.php +++ b/ext/alias_editor/test.php @@ -5,8 +5,64 @@ class AliasEditorTest extends ShimmieWebTestCase { $this->assertTitle("Alias List"); $this->log_in_as_admin(); + + # test one to one $this->get_page('alias/list'); $this->assertTitle("Alias List"); + $this->setField('oldtag', "test1"); + $this->setField('newtag', "test2"); + $this->click("Add"); + $this->assertText("test1"); + + $this->get_page("alias/export/aliases.csv"); + $this->assertText("test1,test2"); + + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test1"); + $this->get_page("post/view/$image_id"); # check that the tag has been replaced + $this->assertTitle("Image $image_id: test2"); + $this->get_page("post/list/test1/1"); # searching for an alias should find the master tag + $this->assertTitle("Image $image_id: test2"); + $this->get_page("post/list/test2/1"); # check that searching for the main tag still works + $this->assertTitle("Image $image_id: test2"); + $this->delete_image($image_id); + + $this->get_page('alias/list'); + $this->click("Remove"); + $this->assertTitle("Alias List"); + $this->assertNoText("test1"); + + # test one to many + $this->get_page('alias/list'); + $this->assertTitle("Alias List"); + $this->setField('oldtag', "onetag"); + $this->setField('newtag', "multi tag"); + $this->click("Add"); + $this->assertText("multi"); + $this->assertText("tag"); + + $this->get_page("alias/export/aliases.csv"); + $this->assertText("onetag,multi tag"); + + $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "onetag"); + $image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "onetag"); + // FIXME: known broken + //$this->get_page("post/list/onetag/1"); # searching for an aliased tag should find its aliases + //$this->assertTitle("onetag"); + //$this->assertNoText("No Images Found"); + $this->get_page("post/list/multi/1"); + $this->assertTitle("multi"); + $this->assertNoText("No Images Found"); + $this->get_page("post/list/multi%20tag/1"); + $this->assertTitle("multi tag"); + $this->assertNoText("No Images Found"); + $this->delete_image($image_id_1); + $this->delete_image($image_id_2); + + $this->get_page('alias/list'); + $this->click("Remove"); + $this->assertTitle("Alias List"); + $this->assertNoText("test1"); + $this->log_out(); } } diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 37f662b0..eef011f4 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -5,43 +5,13 @@ * Description: Handle JPG, PNG, GIF, etc files */ -class PixelFileHandler implements Extension { - var $theme; - - public function receive_event(Event $event) { - global $page; - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - if(!move_upload_to_archive($event)) return; - send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); - $image = $this->create_image_from_data("images/$ha/$hash", $event->metadata); - if(is_null($image)) { - throw new UploadException("Pixel Handler failed to create image object from data"); - } - - $iae = new ImageAdditionEvent($event->user, $image); - send_event($iae); // this might raise an exception, but all we'd do is re-throw it... - $event->image_id = $iae->image->id; - } - - if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { - $this->create_thumb($event->hash); - } - - if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { - $this->theme->display_image($page, $event->image); - } - } - - private function supported_ext($ext) { +class PixelFileHandler extends DataHandlerExtension { + protected function supported_ext($ext) { $exts = array("jpg", "jpeg", "gif", "png"); return in_array(strtolower($ext), $exts); } - private function create_image_from_data($filename, $metadata) { + protected function create_image_from_data($filename, $metadata) { global $config; $image = new Image(); @@ -62,7 +32,7 @@ class PixelFileHandler implements Extension { return $image; } - private function check_contents($file) { + protected function check_contents($file) { $valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG); if(!file_exists($file)) return false; $info = getimagesize($file); @@ -71,7 +41,7 @@ class PixelFileHandler implements Extension { return false; } - private function create_thumb($hash) { + protected function create_thumb($hash) { $ha = substr($hash, 0, 2); $inname = "images/$ha/$hash"; $outname = "thumbs/$ha/$hash"; diff --git a/ext/index/test.php b/ext/index/test.php index e7605f25..d2931000 100644 --- a/ext/index/test.php +++ b/ext/index/test.php @@ -48,14 +48,17 @@ class IndexTest extends ShimmieWebTestCase { # regular tag, many results $this->get_page('post/list/computer/1'); $this->assertTitle("computer"); + $this->assertNoText("No Images Found"); # meta tag, many results $this->get_page('post/list/size=640x480/1'); $this->assertTitle("size=640x480"); + $this->assertNoText("No Images Found"); # multiple tags, many results $this->get_page('post/list/computer%20size=640x480/1'); $this->assertTitle("computer size=640x480"); + $this->assertNoText("No Images Found"); # multiple tags, single result; search with one result = direct to image $this->get_page('post/list/screenshot%20computer/1'); @@ -65,6 +68,11 @@ class IndexTest extends ShimmieWebTestCase { $this->get_page('post/list/computer%20-pbx/1'); $this->assertTitle(new PatternExpectation("/^Image $image_id_2: /")); + # negative tag alone, should work + # FIXME: known broken in mysql + //$this->get_page('post/list/-pbx/1'); + //$this->assertTitle(new PatternExpectation("/^Image $image_id_2: /")); + $this->log_in_as_admin(); $this->delete_image($image_id_1); $this->delete_image($image_id_2); diff --git a/ext/upload/main.php b/ext/upload/main.php index b389a61c..d6c1990b 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -150,6 +150,9 @@ class Upload implements Extension { $event = new DataUploadEvent($user, $file['tmp_name'], $metadata); try { send_event($event); + if($event->image_id == -1) { + throw new UploadException("File type not recognised"); + } header("X-Shimmie-Image-ID: ".int_escape($event->image_id)); } catch(UploadException $ex) { diff --git a/ext/upload/test.php b/ext/upload/test.php index 1ebf096f..2f7b4386 100644 --- a/ext/upload/test.php +++ b/ext/upload/test.php @@ -7,14 +7,32 @@ class UploadTest extends ShimmieWebTestCase { $this->assertResponse(302); $image_id_2 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->assertResponse(200); $this->assertTitle("Upload Status"); $this->assertText("already has hash"); + $image_id_3 = $this->post_image("index.php", "test"); + $this->assertResponse(200); + $this->assertTitle("Upload Status"); + $this->assertText("File type not recognised"); + + /* + // FIXME: huge.dat is rejected for other reasons; manual testing shows that this works + file_put_contents("huge.dat", file_get_contents("ext/simpletest/data/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3)); + $image_id_4 = $this->post_image("index.php", "test"); + $this->assertResponse(200); + $this->assertTitle("Upload Status"); + $this->assertText("File too large"); + unlink("huge.dat"); + */ + $this->log_out(); $this->log_in_as_admin(); $this->delete_image($image_id_1); $this->delete_image($image_id_2); + $this->delete_image($image_id_3); # if these were successfully rejected, + //$this->delete_image($image_id_4); # then delete_image is a no-op $this->log_out(); } } From 75d4c6cf7399dacb8b430b2a296a3fb6efede5be Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 16 Jul 2009 20:21:49 +0100 Subject: [PATCH 6/6] yet more tests --- contrib/ban_words/test.php | 34 ++++++++++++++++++++++++++++++++++ contrib/handle_ico/test.php | 14 ++++++++++++++ contrib/handle_svg/test.php | 31 +++++++++++++++++++++++++++++++ contrib/news/test.php | 25 +++++++++++++++++++++++++ ext/handle_pixel/test.php | 14 ++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 contrib/ban_words/test.php create mode 100644 contrib/handle_ico/test.php create mode 100644 contrib/handle_svg/test.php create mode 100644 contrib/news/test.php create mode 100644 ext/handle_pixel/test.php diff --git a/contrib/ban_words/test.php b/contrib/ban_words/test.php new file mode 100644 index 00000000..a457c157 --- /dev/null +++ b/contrib/ban_words/test.php @@ -0,0 +1,34 @@ +log_in_as_admin(); + $this->get_page("setup"); + $this->setField("_config_banned_words", "viagra\nporn\n/http:.*\.cn\//"); + $this->click("Save Settings"); + $this->log_out(); + + $this->log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + + $this->get_page("post/view/$image_id"); + $this->setField('comment', "kittens and viagra"); + $this->click("Post Comment"); + $this->assertTitle("Comment Blocked"); + + $this->get_page("post/view/$image_id"); + $this->setField('comment', "some link to http://something.cn/"); + $this->click("Post Comment"); + $this->assertTitle("Comment Blocked"); + + $this->get_page('comment/list'); + $this->assertTitle('Comments'); + $this->assertNoText('viagra'); + $this->assertNoText('http://something.cn/'); + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + } +} +?> diff --git a/contrib/handle_ico/test.php b/contrib/handle_ico/test.php new file mode 100644 index 00000000..b1fe8b83 --- /dev/null +++ b/contrib/handle_ico/test.php @@ -0,0 +1,14 @@ +log_in_as_user(); + $image_id = $this->post_image("favicon.ico", "shimmie favicon"); + $this->assertResponse(302); + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + } +} +?> diff --git a/contrib/handle_svg/test.php b/contrib/handle_svg/test.php new file mode 100644 index 00000000..fe0751ad --- /dev/null +++ b/contrib/handle_svg/test.php @@ -0,0 +1,31 @@ + + + + + +'); + + $this->log_in_as_user(); + $image_id = $this->post_image("favicon.ico", "shimmie favicon"); + $this->assertResponse(302); + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + + unlink("test.svg"); + } +} +?> diff --git a/contrib/news/test.php b/contrib/news/test.php new file mode 100644 index 00000000..0e959439 --- /dev/null +++ b/contrib/news/test.php @@ -0,0 +1,25 @@ +log_in_as_admin(); + + $this->get_page("setup"); + $this->setField("_config_news_text", "kittens"); + $this->click("Save Settings"); + + $this->get_page("post/list"); + $this->assertText("Note"); + $this->assertText("kittens"); + + $this->get_page("setup"); + $this->setField("_config_news_text", ""); + $this->click("Save Settings"); + + $this->get_page("post/list"); + $this->assertNoText("Note"); + $this->assertNoText("kittens"); + + $this->log_out(); + } +} +?> diff --git a/ext/handle_pixel/test.php b/ext/handle_pixel/test.php new file mode 100644 index 00000000..f5d76e3a --- /dev/null +++ b/ext/handle_pixel/test.php @@ -0,0 +1,14 @@ +log_in_as_user(); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $this->assertResponse(302); + $this->log_out(); + + $this->log_in_as_admin(); + $this->delete_image($image_id); + $this->log_out(); + } +} +?>