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;