A bunch of testing / fixes

This commit is contained in:
Shish 2010-05-04 20:10:37 +01:00
parent c94e16f814
commit 46ce762949
7 changed files with 60 additions and 36 deletions

View File

@ -12,12 +12,14 @@ class AdminPageTest extends ShimmieWebTestCase {
$this->log_out(); $this->log_out();
} }
function testPurge() { function testLowercase() {
$ts = time(); // we need a tag that hasn't been used before
$this->log_in_as_admin(); $this->log_in_as_admin();
$image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "TeSt"); $image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "TeStCase$ts");
$this->get_page("post/view/$image_id_1"); $this->get_page("post/view/$image_id_1");
$this->assert_title("Image $image_id_1: TeSt"); $this->assert_title("Image $image_id_1: TeStCase$ts");
$this->get_page('admin'); $this->get_page('admin');
$this->assert_title("Admin Tools"); $this->assert_title("Admin Tools");
@ -26,7 +28,7 @@ class AdminPageTest extends ShimmieWebTestCase {
$this->log_out(); $this->log_out();
$this->get_page("post/view/$image_id_1"); $this->get_page("post/view/$image_id_1");
$this->assert_title("Image $image_id_1: test"); $this->assert_title("Image $image_id_1: testcase$ts");
$this->delete_image($image_id_1); $this->delete_image($image_id_1);
$this->log_out(); $this->log_out();

View File

@ -7,6 +7,9 @@
* Documentation: * Documentation:
*/ */
class PoolCreationException extends SCoreException {
}
class Pools extends SimpleExtension { class Pools extends SimpleExtension {
public function onInitExt($event) { public function onInitExt($event) {
global $config, $database; global $config, $database;
@ -81,12 +84,13 @@ class Pools extends SimpleExtension {
break; break;
case "create": // ADD _POST case "create": // ADD _POST
if(!$user->is_anonymous()) { try {
$newPoolID = $this->add_pool(); $newPoolID = $this->add_pool();
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("pool/view/".$newPoolID)); $page->set_redirect(make_link("pool/view/".$newPoolID));
} else { }
$this->theme->display_error("You must be registered and logged in to add a image."); catch(PoolCreationException $pce) {
$this->theme->display_error($pce->getMessage());
} }
break; break;
@ -269,14 +273,15 @@ class Pools extends SimpleExtension {
$poolsPerPage = $config->get_int("poolsListsPerPage"); $poolsPerPage = $config->get_int("poolsListsPerPage");
$pools = $database->get_all( $pools = $database->get_all("
"SELECT p.id, p.user_id, p.public, p.title, p.description, p.posts, u.name as user_name ". SELECT p.id, p.user_id, p.public, p.title, p.description,
"FROM pools AS p ". p.posts, u.name as user_name
"INNER JOIN users AS u ". FROM pools AS p
"ON p.user_id = u.id ". INNER JOIN users AS u
"ORDER BY p.date DESC ". ON p.user_id = u.id
"OFFSET ? LIMIT ?" ORDER BY p.date DESC
, array($pageNumber * $poolsPerPage, $poolsPerPage) LIMIT ? OFFSET ?
", array($poolsPerPage, $pageNumber * $poolsPerPage)
); );
$totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pools") / $poolsPerPage); $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pools") / $poolsPerPage);
@ -291,6 +296,13 @@ class Pools extends SimpleExtension {
private function add_pool() { private function add_pool() {
global $user, $database; global $user, $database;
if($user->is_anonymous()) {
throw new PoolCreationException("You must be registered and logged in to add a image.");
}
if(empty($_POST["title"])) {
throw new PoolCreationException("Pool needs a title");
}
$public = $_POST["public"] == "Y" ? "Y" : "N"; $public = $_POST["public"] == "Y" ? "Y" : "N";
$database->execute(" $database->execute("
INSERT INTO pools (user_id, public, title, description, date) INSERT INTO pools (user_id, public, title, description, date)
@ -452,8 +464,8 @@ class Pools extends SimpleExtension {
INNER JOIN images AS i ON i.id = p.image_id INNER JOIN images AS i ON i.id = p.image_id
WHERE p.pool_id = ? AND i.rating IN ($rating) WHERE p.pool_id = ? AND i.rating IN ($rating)
ORDER BY p.image_order ASC ORDER BY p.image_order ASC
OFFSET ? LIMIT ?", LIMIT ? OFFSET ?",
array($poolID, $pageNumber * $imagesPerPage, $imagesPerPage)); array($poolID, $imagesPerPage, $pageNumber * $imagesPerPage));
$totalPages = ceil($database->db->GetOne(" $totalPages = ceil($database->db->GetOne("
SELECT COUNT(*) SELECT COUNT(*)
@ -468,8 +480,8 @@ class Pools extends SimpleExtension {
FROM pool_images FROM pool_images
WHERE pool_id=? WHERE pool_id=?
ORDER BY image_order ASC ORDER BY image_order ASC
OFFSET ? LIMIT ?", LIMIT ? OFFSET ?",
array($poolID, $pageNumber * $imagesPerPage, $imagesPerPage)); array($poolID, $imagesPerPage, $pageNumber * $imagesPerPage));
$totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_images WHERE pool_id=?", array($poolID)) / $imagesPerPage); $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_images WHERE pool_id=?", array($poolID)) / $imagesPerPage);
} }
@ -580,16 +592,17 @@ class Pools extends SimpleExtension {
$historiesPerPage = $config->get_int("poolsUpdatedPerPage"); $historiesPerPage = $config->get_int("poolsUpdatedPerPage");
$history = $database->get_all( $history = $database->get_all("
"SELECT h.id, h.pool_id, h.user_id, h.action, h.images, h.count, h.date, u.name as user_name, p.title as title ". SELECT h.id, h.pool_id, h.user_id, h.action, h.images,
"FROM pool_history AS h ". h.count, h.date, u.name as user_name, p.title as title
"INNER JOIN pools AS p ". FROM pool_history AS h
"ON p.id = h.pool_id ". INNER JOIN pools AS p
"INNER JOIN users AS u ". ON p.id = h.pool_id
"ON h.user_id = u.id ". INNER JOIN users AS u
"ORDER BY h.date DESC ". ON h.user_id = u.id
"OFFSET ? LIMIT ?" ORDER BY h.date DESC
, array($pageNumber * $historiesPerPage, $historiesPerPage)); LIMIT ? OFFSET ?
", array($historiesPerPage, $pageNumber * $historiesPerPage));
$totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_history") / $historiesPerPage); $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_history") / $historiesPerPage);

View File

@ -11,7 +11,7 @@ class PoolsTest extends ShimmieWebTestCase {
$this->log_in_as_user(); $this->log_in_as_user();
$this->get_page('pool/list'); $this->get_page('pool/list');
$this->click("Create New"); $this->click("Create Pool");
$this->assert_title("Create Pool"); $this->assert_title("Create Pool");
$this->click("Create"); $this->click("Create");
$this->assert_title("Error"); $this->assert_title("Error");
@ -31,7 +31,7 @@ class PoolsTest extends ShimmieWebTestCase {
$this->get_page('pool/list'); $this->get_page('pool/list');
$this->click("Test Pool Title"); $this->click("Test Pool Title");
$this->assert_title("Pool: Test Pool Title"); $this->assert_title("Pool: Test Pool Title");
$this->click("Delete"); $this->click("Delete Pool");
$this->assert_title("Pools"); $this->assert_title("Pools");
$this->assert_no_text("Test Pool Title"); $this->assert_no_text("Test Pool Title");

View File

@ -86,7 +86,7 @@ class PoolsTheme extends Themelet {
<tr><td>Title:</td><td><input type='text' name='title'></td></tr> <tr><td>Title:</td><td><input type='text' name='title'></td></tr>
<tr><td>Public?</td><td><input name='public' type='checkbox' value='Y' checked='checked'/></td></tr> <tr><td>Public?</td><td><input name='public' type='checkbox' value='Y' checked='checked'/></td></tr>
<tr><td>Description:</td><td><textarea name='description'></textarea></td></tr> <tr><td>Description:</td><td><textarea name='description'></textarea></td></tr>
<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr> <tr><td colspan='2'><input type='submit' value='Create' /></td></tr>
</table> </table>
"; ";
@ -147,7 +147,7 @@ class PoolsTheme extends Themelet {
public function view_pool($pools, $images, $pageNumber, $totalPages) { public function view_pool($pools, $images, $pageNumber, $totalPages) {
global $user, $page; global $user, $page;
$this->display_top($pools, "Viewing Pool"); $this->display_top($pools, "Pool: ".$pools[0]['title']);
$pool_images = ''; $pool_images = '';
foreach($images as $image) { foreach($images as $image) {

View File

@ -176,6 +176,8 @@ class ShimmieWebTestCase extends SCoreWebTestCase {
} }
} }
$this->assertTrue($image_id > 0);
$this->setMaximumRedirects(5); $this->setMaximumRedirects(5);
return $image_id; return $image_id;
} }

View File

@ -5,7 +5,7 @@ class ExtManagerTest extends SCoreWebTestCase {
$this->assert_title("Extensions"); $this->assert_title("Extensions");
$this->get_page('ext_doc'); $this->get_page('ext_doc');
$this->assert_response(404); $this->assert_title("Extensions");
$this->get_page('ext_doc/ext_manager'); $this->get_page('ext_doc/ext_manager');
$this->assert_title("Documentation for Extension Manager"); $this->assert_title("Documentation for Extension Manager");

View File

@ -155,8 +155,15 @@ class Index extends SimpleExtension {
$search_terms = $event->get_search_terms(); $search_terms = $event->get_search_terms();
$page_number = $event->get_page_number(); $page_number = $event->get_page_number();
$page_size = $event->get_page_size(); $page_size = $event->get_page_size();
try {
$total_pages = Image::count_pages($search_terms); $total_pages = Image::count_pages($search_terms);
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms); $images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
}
catch(SearchTermParseException $stpe) {
// FIXME: display the error somewhere
$total_pages = 0;
$images = array();
}
if(count($search_terms) == 0 && count($images) == 0 && $page_number == 1) { if(count($search_terms) == 0 && count($images) == 0 && $page_number == 1) {
$this->theme->display_intro($page); $this->theme->display_intro($page);