A ton of tests, figured out how to test uploads \o/

This commit is contained in:
Shish
2009-07-15 02:42:18 +01:00
parent 8dac266af4
commit c88ecebb7b
25 changed files with 250 additions and 153 deletions

View File

@ -15,6 +15,13 @@ class ImageAdditionEvent extends Event {
}
}
class ImageAdditionException extends SCoreException {
var $error;
public function __construct($error) {
$this->error = $error;
}
}
/*
* ImageDeletionEvent:
@ -104,8 +111,12 @@ class ImageIO extends SimpleExtension {
}
public function onImageAddition($event) {
$error = $this->add_image($event->image);
if(!empty($error)) throw new UploadException($error);
try {
$this->add_image($event->image);
}
catch(ImageAdditionException $e) {
throw new UploadException($e->error);
}
}
public function onImageDeletion($event) {
@ -158,8 +169,7 @@ class ImageIO extends SimpleExtension {
}
if(!empty($image->source)) {
if(!preg_match("#^(https?|ftp)://#", $image->source)) {
$error = "Image's source isn't a valid URL";
return $error;
throw new ImageAdditionException("Image's source isn't a valid URL");
}
}
@ -177,7 +187,7 @@ class ImageIO extends SimpleExtension {
else {
$error = "Image <a href='".make_link("post/view/{$existing->id}")."'>{$existing->id}</a> ".
"already has hash {$image->hash}:<p>".Themelet::build_thumb_html($existing);
return $error;
throw new ImageAdditionException($error);
}
}
@ -194,8 +204,6 @@ class ImageIO extends SimpleExtension {
log_info("image", "Uploaded Image #{$image->id} ({$image->hash})");
send_event(new TagSetEvent($image, $image->get_tag_array()));
return null;
}
// }}}
// fetch image {{{