a load of testing

This commit is contained in:
Shish 2009-11-15 06:23:42 +00:00
parent 43dbf5baea
commit a5711d3408
3 changed files with 72 additions and 19 deletions

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;
@ -82,12 +85,17 @@ class Pools extends SimpleExtension {
} }
case "create": // ADD _POST 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(); $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 $ex) {
$this->theme->display_error($ex->getMessage());
} }
break; break;
} }
@ -125,7 +133,7 @@ class Pools extends SimpleExtension {
$this->theme->edit_pool($page, $this->get_pool($poolID), $this->edit_posts($poolID)); $this->theme->edit_pool($page, $this->get_pool($poolID), $this->edit_posts($poolID));
} else { } else {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("pool/view/".$poolID."")); $page->set_redirect(make_link("pool/view/".$poolID));
} }
} }
break; break;
@ -134,7 +142,7 @@ class Pools extends SimpleExtension {
{ {
$poolID = int_escape($_POST["pool_id"]); $poolID = int_escape($_POST["pool_id"]);
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("pool/edit/".$poolID."")); $page->set_redirect(make_link("pool/edit/".$poolID));
break; break;
} }
case "order": case "order":
@ -148,7 +156,7 @@ class Pools extends SimpleExtension {
$this->theme->edit_order($page, $this->get_pool($poolID), $this->edit_order($poolID)); $this->theme->edit_order($page, $this->get_pool($poolID), $this->edit_order($poolID));
} else { } else {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("pool/view/".$poolID."")); $page->set_redirect(make_link("pool/view/".$poolID));
} }
} }
break; break;
@ -157,7 +165,7 @@ class Pools extends SimpleExtension {
{ {
$poolID = int_escape($_POST["pool_id"]); $poolID = int_escape($_POST["pool_id"]);
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("pool/order/".$poolID."")); $page->set_redirect(make_link("pool/order/".$poolID));
break; break;
} }
case "import": case "import":
@ -261,7 +269,7 @@ class Pools extends SimpleExtension {
foreach ($poolsIDs as $poolID) { foreach ($poolsIDs as $poolID) {
$pools = $this->get_pool($poolID['pool_id']); $pools = $this->get_pool($poolID['pool_id']);
foreach ($pools as $pool) { foreach ($pools as $pool) {
$linksPools .= "<a href='".make_link("pool/view/".$pool['id']."")."'>".$pool['title']."</a>, "; $linksPools .= "<a href='".make_link("pool/view/".$pool['id'])."'>".$pool['title']."</a>, ";
} }
} }
$linksPools = substr($linksPools, 0, -2); $linksPools = substr($linksPools, 0, -2);
@ -311,13 +319,15 @@ class Pools extends SimpleExtension {
global $user, $database; global $user, $database;
$public = html_escape($_POST["public"]); $public = html_escape($_POST["public"]);
$title = html_escape($_POST["title"]); $title = html_escape(trim($_POST["title"]));
$description = html_escape($_POST["description"]); $description = html_escape(trim($_POST["description"]));
if($public == "") { if($public == "") {
$public = "N"; $public = "N";
} }
if(empty($title)) throw new PoolCreationException("Pool must have a title");
$database->execute(" $database->execute("
INSERT INTO pools INSERT INTO pools
(user_id, public, title, description, date) (user_id, public, title, description, date)
@ -325,7 +335,7 @@ class Pools extends SimpleExtension {
(?, ?, ?, ?, now())", (?, ?, ?, ?, now())",
array($user->id, $public, $title, $description)); 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}"); log_info("pools", "Pool {$result["poolID"]} created by {$user->name}");

View file

@ -1,8 +1,41 @@
<?php <?php
class PoolsTest extends SCoreWebTestCase { class PoolsTest extends ShimmieWebTestCase {
function testPools() { function testPools() {
$this->get_page('pool/list'); $this->get_page('pool/list');
$this->assert_title("Pools"); $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();
} }
} }
?> ?>

View file

@ -63,6 +63,9 @@ class PoolsTheme extends Themelet {
} }
if(!$user->is_anonymous()) {
$html .= "<tfoot><tr><td colspan='5'><a href='".make_link("pool/new")."'>Create New</a></td></tr></tfoot>";
}
$html .= "</tbody></table>"; $html .= "</tbody></table>";
$blockTitle = "Pools"; $blockTitle = "Pools";
@ -84,7 +87,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>
"; ";
@ -123,14 +126,21 @@ class PoolsTheme extends Themelet {
$this->sidebar_options($page, $pool); $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 .= "</tbody></table>"; $pool_info .= "</tbody></table>";
$page->set_title("Viewing Pool"); if(count($pools) == 1) {
$page->set_heading("Viewing Pool"); $page->set_title("Pool: ".html_escape($pool['title']));
$page->add_block(new Block("Viewing Pool", $pool_info, "main", 10)); $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 = ''; $pool_images = '';
foreach($images as $pair) { foreach($images as $pair) {