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

@@ -1,26 +1,20 @@
<?php
class AdminPageTest extends WebTestCase {
class AdminPageTest extends ShimmieWebTestCase {
function testAuth() {
$this->get(TEST_BASE.'/admin');
$this->get_page('admin');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/admin');
$this->log_in_as_user();
$this->get_page('admin');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->click('Log Out');
$this->log_out();
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/admin');
$this->log_in_as_admin();
$this->get_page('admin');
$this->assertTitle("Admin Tools");
$this->click('Log Out');
$this->log_out();
}
}
?>

View File

@@ -1,28 +1,13 @@
<?php
class AliasEditorTest extends WebTestCase {
class AliasEditorTest extends ShimmieWebTestCase {
function testAliasEditor() {
/*
$this->get(TEST_BASE.'/admin');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->get_page('alias/list');
$this->assertTitle("Alias List");
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/admin');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->click('Log Out');
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/admin');
$this->assertTitle("Admin Tools");
$this->click('Log Out');
*/
$this->log_in_as_admin();
$this->get_page('alias/list');
$this->assertTitle("Alias List");
$this->log_out();
}
}
?>

View File

@@ -1,5 +1,5 @@
<?php
class BBCodeTest extends WebTestCase {}
class BBCodeTest extends ShimmieWebTestCase {}
if(!defined(VERSION)) return;

View File

@@ -1,10 +1,10 @@
<?php
class CommentListTest extends WebTestCase {
class CommentListTest extends ShimmieWebTestCase {
function testCommentsPage() {
$this->get(TEST_BASE.'/comment/list');
$this->get_page('comment/list');
$this->assertTitle('Comments');
$this->get(TEST_BASE.'/comment/list/2');
$this->get_page('comment/list/2');
$this->assertTitle('Comments');
}
}

View File

@@ -1,27 +1,21 @@
<?php
class ExtManagerTest extends WebTestCase {
class ExtManagerTest extends ShimmieWebTestCase {
function testAuth() {
$this->get(TEST_BASE.'/ext_manager');
$this->get_page('ext_manager');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/ext_manager');
$this->log_in_as_user();
$this->get_page('ext_manager');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->click('Log Out');
$this->log_out();
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/ext_manager');
$this->log_in_as_admin();
$this->get_page('ext_manager');
$this->assertTitle("Extensions");
$this->assertText("SimpleTest integration");
$this->click('Log Out');
$this->log_out();
}
}
?>

View File

@@ -1,7 +1,7 @@
<?php
class Handle404Test extends WebTestCase {
class Handle404Test extends ShimmieWebTestCase {
function test404Handler() {
$this->get(TEST_BASE.'/not/a/page');
$this->get_page('not/a/page');
$this->assertResponse(404);
$this->assertTitle('404');
$this->assertText("No handler could be found for the page 'not/a/page'");

View File

@@ -24,6 +24,7 @@ class PixelFileHandler implements Extension {
$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)) {

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 {{{

View File

@@ -1,42 +1,70 @@
<?php
class IndexTest extends WebTestCase {
class IndexTest extends ShimmieWebTestCase {
function testIndexPage() {
$this->get(TEST_BASE.'/post/list');
$this->assertTitle("Shimmie Testbed");
$this->log_in_as_user();
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
$this->log_out();
$this->get_page('post/list');
$this->assertTitle("Shimmie");
$this->assertText("Prev | Index | Next");
$this->get(TEST_BASE.'/post/list/-1');
$this->assertTitle("Shimmie Testbed");
$this->get_page('post/list/-1');
$this->assertTitle("Shimmie");
$this->get(TEST_BASE.'/post/list/0');
$this->assertTitle("Shimmie Testbed");
$this->get_page('post/list/0');
$this->assertTitle("Shimmie");
$this->get(TEST_BASE.'/post/list/1');
$this->assertTitle("Shimmie Testbed");
$this->get_page('post/list/1');
$this->assertTitle("Shimmie");
$this->get(TEST_BASE.'/post/list/99999');
$this->assertTitle("Shimmie Testbed");
$this->get_page('post/list/99999');
$this->assertTitle("Shimmie");
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
}
function testSearches() {
$this->get(TEST_BASE.'/post/list/maumaumau/1');
$this->log_in_as_user();
$image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
$image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "computer bedroom workshop");
$this->log_out();
# make sure both uploads were ok
$this->assertTrue($image_id_1 > 0);
$this->assertTrue($image_id_2 > 0);
# regular tag, no results
$this->get_page('post/list/maumaumau/1');
$this->assertTitle("maumaumau");
$this->assertText("No Images Found");
$this->get(TEST_BASE.'/post/list/screenshot/1');
$this->assertTitle("screenshot");
# regular tag, many results
$this->get_page('post/list/computer/1');
$this->assertTitle("computer");
$this->get(TEST_BASE.'/post/list/size=1024x768/1');
$this->assertTitle("size=1024x768");
# meta tag, many results
$this->get_page('post/list/size=640x480/1');
$this->assertTitle("size=640x480");
$this->get(TEST_BASE.'/post/list/screenshot%20size=1024x768/1');
$this->assertTitle("screenshot size=1024x768");
# multiple tags, many results
$this->get_page('post/list/computer%20size=640x480/1');
$this->assertTitle("computer size=640x480");
$this->get(TEST_BASE.'/post/list/screenshot%20computer/1');
$this->assertTitle("screenshot computer");
# multiple tags, single result; search with one result = direct to image
$this->get_page('post/list/screenshot%20computer/1');
$this->assertTitle(new PatternExpectation("/^Image $image_id_1: /"));
$this->get(TEST_BASE.'/post/list/screenshot%20computer%20-pbx/1');
$this->assertTitle("screenshot computer -pbx");
# negative tag, should have one result
$this->get_page('post/list/computer%20-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);
$this->log_out();
}
}
?>

View File

@@ -1,27 +1,21 @@
<?php
class SetupTest extends WebTestCase {
class SetupTest extends ShimmieWebTestCase {
function testAuth() {
$this->get(TEST_BASE.'/setup');
$this->get_page('setup');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/setup');
$this->log_in_as_user();
$this->get_page('setup');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->click('Log Out');
$this->log_out();
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->get(TEST_BASE.'/setup');
$this->log_in_as_admin();
$this->get_page('setup');
$this->assertTitle("Shimmie Setup");
$this->assertText("General");
$this->click('Log Out');
$this->log_out();
}
}
?>

View File

@@ -1,16 +1,16 @@
<?php
class TagListTest extends WebTestCase {
class TagListTest extends ShimmieWebTestCase {
function testTagList() {
$this->get(TEST_BASE.'/tags/map');
$this->get_page('tags/map');
$this->assertTitle('Tag List');
$this->get(TEST_BASE.'/tags/alphabetic');
$this->get_page('tags/alphabetic');
$this->assertTitle('Tag List');
$this->get(TEST_BASE.'/tags/popularity');
$this->get_page('tags/popularity');
$this->assertTitle('Tag List');
$this->get(TEST_BASE.'/tags/categories');
$this->get_page('tags/categories');
$this->assertTitle('Tag List');
}
}

View File

@@ -8,7 +8,7 @@
* Some data is being uploaded. Should be caught by a file handler.
*/
class DataUploadEvent extends Event {
var $user, $tmpname, $metadata, $hash, $type;
var $user, $tmpname, $metadata, $hash, $type, $image_id = -1;
public function DataUploadEvent($user, $tmpname, $metadata) {
$this->user = $user;
@@ -150,6 +150,7 @@ class Upload implements Extension {
$event = new DataUploadEvent($user, $file['tmp_name'], $metadata);
try {
send_event($event);
header("X-Shimmie-Image-ID: ".int_escape($event->image_id));
}
catch(UploadException $ex) {
$this->theme->display_upload_error($page, "Error with ".html_escape($file['name']),

21
ext/upload/test.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
class UploadTest extends ShimmieWebTestCase {
function testUpload() {
$this->log_in_as_user();
$image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
$this->assertResponse(302);
$image_id_2 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
$this->assertTitle("Upload Status");
$this->assertText("already has hash");
$this->log_out();
$this->log_in_as_admin();
$this->delete_image($image_id_1);
$this->delete_image($image_id_2);
$this->log_out();
}
}
?>

View File

@@ -1,36 +1,30 @@
<?php
class UserPageTest extends WebTestCase {
class UserPageTest extends ShimmieWebTestCase {
function testUserPage() {
$this->get(TEST_BASE.'/user');
$this->get_page('user');
$this->assertTitle("Anonymous's Page");
$this->assertNoText("Options");
$this->assertNoText("More Options");
$this->get(TEST_BASE.'/user/Shish');
$this->assertTitle("Shish's Page");
$this->get_page('user/demo');
$this->assertTitle("demo's Page");
$this->get(TEST_BASE.'/user/MauMau');
$this->get_page('user/MauMau');
$this->assertTitle("No Such User");
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
$this->log_in_as_user();
// should be on the user page
$this->assertTitle("test's Page");
$this->assertTitle(USER_NAME+"'s Page");
$this->assertText("Options");
$this->assertNoText("More Options");
$this->click('Log Out');
$this->log_out();
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->log_in_as_admin();
// should be on the user page
$this->assertTitle(ADMIN_NAME+"'s Page");
$this->assertText("Options");
$this->assertText("More Options");
$this->click('Log Out');
$this->log_out();
}
}
?>

View File

@@ -1,14 +1,23 @@
<?php
class ViewTest extends WebTestCase {
class ViewTest extends ShimmieWebTestCase {
function testViewPage() {
$this->get(TEST_BASE.'/post/view/1914');
$this->assertTitle('Image 1914: test');
$this->log_in_as_user();
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test");
$idp1 = $image_id + 1;
$this->log_out();
$this->get(TEST_BASE.'/post/view/1');
$this->get_page("post/view/$image_id");
$this->assertTitle("Image $image_id: test");
$this->get_page("post/view/$idp1");
$this->assertTitle('Image not found');
$this->get(TEST_BASE.'/post/view/-1');
$this->get_page('post/view/-1');
$this->assertTitle('Image not found');
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
}
}
?>