2008-10-11 07:05:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: SimpleTest integration
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: adds unit testing to SCore
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('simpletest/web_tester.php');
|
2008-10-18 06:05:06 +00:00
|
|
|
require_once('simpletest/unit_tester.php');
|
2008-10-11 07:05:24 +00:00
|
|
|
require_once('simpletest/reporter.php');
|
|
|
|
|
2009-07-15 01:42:18 +00:00
|
|
|
define('USER_NAME', "test");
|
|
|
|
define('USER_PASS', "test");
|
|
|
|
define('ADMIN_NAME', "demo");
|
|
|
|
define('ADMIN_PASS', "demo");
|
|
|
|
|
2009-07-19 18:35:46 +00:00
|
|
|
class SCoreWebTestCase extends WebTestCase {
|
2009-07-15 01:42:18 +00:00
|
|
|
protected function get_page($page) {
|
2009-07-15 22:29:01 +00:00
|
|
|
$url = "http://".$_SERVER["HTTP_HOST"].get_base_href().'/'.make_link($page);
|
|
|
|
$url = str_replace("/./", "/", $url);
|
2009-07-20 06:31:41 +00:00
|
|
|
$raw = $this->get($url);
|
2009-07-19 18:35:46 +00:00
|
|
|
$this->assertNoText("Exception:");
|
|
|
|
$this->assertNoText("Error:");
|
|
|
|
$this->assertNoText("Warning:");
|
|
|
|
$this->assertNoText("Notice:");
|
2009-07-20 06:31:41 +00:00
|
|
|
return $raw;
|
2009-07-15 01:42:18 +00:00
|
|
|
}
|
2009-07-19 18:35:46 +00:00
|
|
|
|
2009-07-15 01:42:18 +00:00
|
|
|
protected function log_in_as_user() {
|
2009-07-20 05:51:36 +00:00
|
|
|
$this->get_page('user_admin/login');
|
2009-07-15 01:42:18 +00:00
|
|
|
$this->assertText("Login");
|
|
|
|
$this->setField('user', USER_NAME);
|
|
|
|
$this->setField('pass', USER_PASS);
|
|
|
|
$this->click("Log In");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function log_in_as_admin() {
|
2009-07-20 05:51:36 +00:00
|
|
|
$this->get_page('user_admin/login');
|
2009-07-15 01:42:18 +00:00
|
|
|
$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');
|
|
|
|
}
|
2009-07-19 18:35:46 +00:00
|
|
|
}
|
2009-07-15 01:42:18 +00:00
|
|
|
|
2009-07-19 18:35:46 +00:00
|
|
|
class ShimmieWebTestCase extends SCoreWebTestCase {
|
2009-07-15 01:42:18 +00:00
|
|
|
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);
|
2009-07-15 18:07:09 +00:00
|
|
|
$this->click("Post");
|
2009-07-15 01:42:18 +00:00
|
|
|
|
|
|
|
$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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-18 06:05:06 +00:00
|
|
|
class TestFinder extends TestSuite {
|
|
|
|
function TestFinder($hint) {
|
2009-07-15 16:09:50 +00:00
|
|
|
if(strpos($hint, "..") !== FALSE) return;
|
2008-10-18 06:05:06 +00:00
|
|
|
$dir = "*";
|
2009-07-15 16:09:50 +00:00
|
|
|
if(file_exists("ext/$hint/test.php")) $dir = $hint;
|
2008-10-11 07:05:24 +00:00
|
|
|
$this->TestSuite('All tests');
|
2008-10-18 06:05:06 +00:00
|
|
|
foreach(glob("ext/$dir/test.php") as $file) {
|
2008-10-11 07:05:24 +00:00
|
|
|
$this->addFile($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 21:09:24 +00:00
|
|
|
class SimpleSCoreTest extends SimpleExtension {
|
|
|
|
public function onPageRequest($event) {
|
|
|
|
global $page;
|
|
|
|
if($event->page_matches("test")) {
|
2009-07-20 05:51:36 +00:00
|
|
|
set_time_limit(0);
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
$page->set_title("Test Results");
|
|
|
|
$page->set_heading("Test Results");
|
|
|
|
$page->add_block(new NavBlock());
|
2008-10-11 07:05:24 +00:00
|
|
|
|
2008-10-18 06:05:06 +00:00
|
|
|
$all = new TestFinder($event->get_arg(0));
|
2009-05-11 14:04:33 +00:00
|
|
|
$all->run(new SCoreReporter($page));
|
2008-10-11 07:05:24 +00:00
|
|
|
}
|
2009-05-11 21:09:24 +00:00
|
|
|
}
|
2008-10-11 07:05:24 +00:00
|
|
|
|
2009-05-11 21:09:24 +00:00
|
|
|
public function onUserBlockBuilding($event) {
|
|
|
|
global $user;
|
|
|
|
if($user->is_admin()) {
|
|
|
|
$event->add_link("Run Tests", make_link("test/all"));
|
2008-10-11 07:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|