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,9 +1,9 @@
<?php
class HomeTest extends WebTestCase {
class HomeTest extends ShimmieWebTestCase {
function testHomePage() {
$this->get(TEST_BASE.'/home');
$this->assertTitle('Shimmie Testbed');
$this->assertText('Shimmie Testbed');
$this->get_page('home');
$this->assertTitle('Shimmie');
$this->assertText('Shimmie');
}
}
?>

View File

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

View File

@ -1,17 +1,13 @@
<?php
class IPBanTest extends WebTestCase {
class IPBanTest extends ShimmieWebTestCase {
function testIPBan() {
$this->get(TEST_BASE.'/ip_ban/list');
$this->get_page('ip_ban/list');
$this->assertResponse(403);
$this->assertTitle("Permission Denied");
$this->get(TEST_BASE.'/user');
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
$this->log_in_as_admin();
$this->get(TEST_BASE.'/ip_ban/list');
$this->get_page('ip_ban/list');
$this->assertNoText("42.42.42.42");
$this->setField('ip', '42.42.42.42');
$this->setField('reason', 'unit testing');
@ -22,7 +18,7 @@ class IPBanTest extends WebTestCase {
$this->click("Remove"); // FIXME: remove which ban? :S
$this->assertNoText("42.42.42.42");
$this->click('Log Out');
$this->log_out();
}
}
?>

View File

@ -1,7 +1,7 @@
<?php
class RSSCommentsTest extends WebTestCase {
class RSSCommentsTest extends ShimmieWebTestCase {
function testImageFeed() {
$this->get(TEST_BASE.'/rss/comments');
$this->get_page('rss/comments');
$this->assertMime("application/rss+xml");
$this->assertNoText("Exception");
}

View File

@ -1,21 +1,32 @@
<?php
class RSSImagesTest extends WebTestCase {
class RSSImagesTest extends ShimmieWebTestCase {
function testImageFeed() {
$this->get(TEST_BASE.'/rss/images');
$this->log_in_as_user();
$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");
$this->get(TEST_BASE.'/rss/images/1');
$this->get_page('rss/images/1');
$this->assertMime("application/rss+xml");
$this->assertNoText("Exception");
$this->get(TEST_BASE.'/rss/images/tagme/1');
$this->get_page('rss/images/tagme/1');
$this->assertMime("application/rss+xml");
$this->assertNoText("Exception");
$this->get(TEST_BASE.'/rss/images/tagme/2');
$this->get_page('rss/images/tagme/2');
$this->assertMime("application/rss+xml");
$this->assertNoText("Exception");
$this->log_in_as_admin();
$this->delete_image($image_id);
$this->log_out();
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -10,6 +10,68 @@ require_once('simpletest/web_tester.php');
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
define('TEST_BASE', "http://shimmie.shishnet.org/branch_2.3/index.php?q=");
define('USER_NAME', "test");
define('USER_PASS', "test");
define('ADMIN_NAME', "demo");
define('ADMIN_PASS', "demo");
class ShimmieWebTestCase extends WebTestCase {
protected function get_page($page) {
$this->get(TEST_BASE.'/'.$page);
}
protected function log_in_as_user() {
$this->get_page('post/list');
$this->assertText("Login");
$this->setField('user', USER_NAME);
$this->setField('pass', USER_PASS);
$this->click("Log In");
}
protected function log_in_as_admin() {
$this->get_page('post/list');
$this->assertText("Login");
$this->setField('user', ADMIN_NAME);
$this->setField('pass', ADMIN_PASS);
$this->click("Log In");
}
protected function log_out() {
$this->get_page('post/list');
$this->click('Log Out');
}
protected function post_image($filename, $tags) {
$image_id = -1;
$this->setMaximumRedirects(0);
$this->get_page('post/list');
$this->assertText("Upload");
$this->setField("data0", $filename);
$this->setField("tags", $tags);
$this->click("Post");
$raw_headers = $this->getBrowser()->getHeaders();
$headers = explode("\n", $raw_headers);
foreach($headers as $header) {
$parts = explode(":", $header);
if(trim($parts[0]) == "X-Shimmie-Image-ID") {
$image_id = int_escape(trim($parts[1]));
}
}
$this->setMaximumRedirects(5);
return $image_id;
}
protected function delete_image($image_id) {
if($image_id > 0) {
$this->get_page('post/view/'.$image_id);
$this->click("Delete");
}
}
}
class TestFinder extends TestSuite {
function TestFinder($hint) {
$dir = "*";

View File

@ -4,7 +4,7 @@ class SimpleSCoreTestTheme extends Themelet {
class SCoreReporter extends HtmlReporter {
var $current_html = "";
var $clear_modules = "";
var $clear_modules = array();
var $page;
public function SCoreReporter(Page $page) {
@ -19,8 +19,7 @@ class SCoreReporter extends HtmlReporter {
function paintFooter($test_name) {
//parent::paintFooter($test_name);
$fail = $this->getFailCount() > 0;
if($fail) {
if($this->getFailCount() > 0) {
$style = "background: red;";
}
else {
@ -29,7 +28,7 @@ class SCoreReporter extends HtmlReporter {
$html = "<div style=\"padding: 4px; $style\">".
$this->getPassCount() . " passes, " .
$this->getFailCount() . " failures" .
"<br>Passed modules: " . $this->clear_modules .
"<br>Passed modules: " . implode(", ", $this->clear_modules) .
"</div>";
$this->page->add_block(new Block("Results", $html, "main", 40));
}
@ -47,7 +46,7 @@ class SCoreReporter extends HtmlReporter {
}
parent::paintGroupEnd($name);
if($this->current_html == "") {
$this->clear_modules .= "$name, ";
$this->clear_modules[] = $name;
}
else {
$this->current_html .= "<p>$link";

View File

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

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();
}
}
?>