From a5711d34086d73b706f2e4a84a570a7d1822bc4b Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 15 Nov 2009 06:23:42 +0000 Subject: [PATCH] a load of testing --- contrib/pools/main.php | 34 ++++++++++++++++++++++------------ contrib/pools/test.php | 37 +++++++++++++++++++++++++++++++++++-- contrib/pools/theme.php | 20 +++++++++++++++----- 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/contrib/pools/main.php b/contrib/pools/main.php index 8de48326..32eeb248 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -7,6 +7,9 @@ * Documentation: */ +class PoolCreationException extends SCoreException { +} + class Pools extends SimpleExtension { public function onInitExt($event) { global $config, $database; @@ -82,12 +85,17 @@ class Pools extends SimpleExtension { } case "create": // ADD _POST { - if(!$user->is_anonymous()) { + try { + if($user->is_anonymous()) { + throw new PoolCreationException("You must be registered and logged in to add a image."); + } + $newPoolID = $this->add_pool(); $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$newPoolID."")); - } else { - $this->theme->display_error("You must be registered and logged in to add a image."); + $page->set_redirect(make_link("pool/view/".$newPoolID)); + } + catch(PoolCreationException $ex) { + $this->theme->display_error($ex->getMessage()); } break; } @@ -125,7 +133,7 @@ class Pools extends SimpleExtension { $this->theme->edit_pool($page, $this->get_pool($poolID), $this->edit_posts($poolID)); } else { $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$poolID."")); + $page->set_redirect(make_link("pool/view/".$poolID)); } } break; @@ -134,7 +142,7 @@ class Pools extends SimpleExtension { { $poolID = int_escape($_POST["pool_id"]); $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/edit/".$poolID."")); + $page->set_redirect(make_link("pool/edit/".$poolID)); break; } case "order": @@ -148,7 +156,7 @@ class Pools extends SimpleExtension { $this->theme->edit_order($page, $this->get_pool($poolID), $this->edit_order($poolID)); } else { $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$poolID."")); + $page->set_redirect(make_link("pool/view/".$poolID)); } } break; @@ -157,7 +165,7 @@ class Pools extends SimpleExtension { { $poolID = int_escape($_POST["pool_id"]); $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/order/".$poolID."")); + $page->set_redirect(make_link("pool/order/".$poolID)); break; } case "import": @@ -261,7 +269,7 @@ class Pools extends SimpleExtension { foreach ($poolsIDs as $poolID) { $pools = $this->get_pool($poolID['pool_id']); foreach ($pools as $pool) { - $linksPools .= "".$pool['title'].", "; + $linksPools .= "".$pool['title'].", "; } } $linksPools = substr($linksPools, 0, -2); @@ -311,13 +319,15 @@ class Pools extends SimpleExtension { global $user, $database; $public = html_escape($_POST["public"]); - $title = html_escape($_POST["title"]); - $description = html_escape($_POST["description"]); + $title = html_escape(trim($_POST["title"])); + $description = html_escape(trim($_POST["description"])); if($public == "") { $public = "N"; } + if(empty($title)) throw new PoolCreationException("Pool must have a title"); + $database->execute(" INSERT INTO pools (user_id, public, title, description, date) @@ -325,7 +335,7 @@ class Pools extends SimpleExtension { (?, ?, ?, ?, now())", array($user->id, $public, $title, $description)); - $result = $database->get_row("SELECT LAST_INSERT_ID() AS poolID", array()); + $result = $database->get_row("SELECT LAST_INSERT_ID() AS poolID"); log_info("pools", "Pool {$result["poolID"]} created by {$user->name}"); diff --git a/contrib/pools/test.php b/contrib/pools/test.php index 3c7b5b2b..b322ac6b 100644 --- a/contrib/pools/test.php +++ b/contrib/pools/test.php @@ -1,8 +1,41 @@ get_page('pool/list'); + $this->get_page('pool/list'); $this->assert_title("Pools"); + + $this->get_page('pool/new'); + $this->assert_title("Error"); + + + $this->log_in_as_user(); + + $this->get_page('pool/list'); + $this->click("Create New"); + $this->assert_title("Create Pool"); + $this->click("Create"); + $this->assert_title("Error"); + + $this->get_page('pool/new'); + $this->assert_title("Create Pool"); + $this->set_field("title", "Test Pool Title"); + $this->set_field("description", "Test pool description"); + $this->click("Create"); + $this->assert_title("Pool: Test Pool Title"); + + $this->log_out(); + + + $this->log_in_as_admin(); + + $this->get_page('pool/list'); + $this->click("Test Pool Title"); + $this->assert_title("Pool: Test Pool Title"); + $this->click("Delete"); + $this->assert_title("Pools"); + $this->assert_no_text("Test Pool Title"); + + $this->log_out(); } } ?> diff --git a/contrib/pools/theme.php b/contrib/pools/theme.php index ad6f7927..4d84382e 100644 --- a/contrib/pools/theme.php +++ b/contrib/pools/theme.php @@ -63,6 +63,9 @@ class PoolsTheme extends Themelet { } + if(!$user->is_anonymous()) { + $html .= "Create New"; + } $html .= ""; $blockTitle = "Pools"; @@ -84,7 +87,7 @@ class PoolsTheme extends Themelet { Title: Public? Description: - + "; @@ -123,14 +126,21 @@ class PoolsTheme extends Themelet { $this->sidebar_options($page, $pool); } } - $this->display_paginator($page, "pool/view/".$pool['id']."", null, $pageNumber, $totalPages); + $this->display_paginator($page, "pool/view/".$pool['id'], null, $pageNumber, $totalPages); } $pool_info .= ""; - $page->set_title("Viewing Pool"); - $page->set_heading("Viewing Pool"); - $page->add_block(new Block("Viewing Pool", $pool_info, "main", 10)); + if(count($pools) == 1) { + $page->set_title("Pool: ".html_escape($pool['title'])); + $page->set_heading(html_escape($pool['title'])); + $page->add_block(new Block("Viewing Pool", $pool_info, "main", 10)); + } + else { + $page->set_title("Viewing Pool"); + $page->set_heading("Viewing Pool"); + $page->add_block(new Block("Viewing Pool", $pool_info, "main", 10)); + } $pool_images = ''; foreach($images as $pair) {