Merge branch 'pools_test'
This commit is contained in:
commit
4a20b3915c
3 changed files with 78 additions and 17 deletions
|
@ -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 .= "<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);
|
||||
|
@ -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}");
|
||||
|
||||
|
|
41
contrib/pools/test.php
Normal file
41
contrib/pools/test.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
class PoolsTest extends ShimmieWebTestCase {
|
||||
function testPools() {
|
||||
$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();
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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>";
|
||||
|
||||
$blockTitle = "Pools";
|
||||
|
@ -84,7 +87,7 @@ class PoolsTheme extends Themelet {
|
|||
<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>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>
|
||||
";
|
||||
|
||||
|
@ -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 .= "</tbody></table>";
|
||||
|
||||
$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) {
|
||||
|
|
Reference in a new issue