summaryrefslogtreecommitdiff
path: root/modules/gallery/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r--modules/gallery/tests/Access_Helper_Test.php119
-rw-r--r--modules/gallery/tests/Album_Helper_Test.php88
-rw-r--r--modules/gallery/tests/Albums_Controller_Test.php38
-rw-r--r--modules/gallery/tests/Cache_Test.php2
-rw-r--r--modules/gallery/tests/Controller_Auth_Test.php2
-rw-r--r--modules/gallery/tests/Database_Test.php2
-rw-r--r--modules/gallery/tests/Dir_Helper_Test.php2
-rw-r--r--modules/gallery/tests/DrawForm_Test.php2
-rw-r--r--modules/gallery/tests/File_Structure_Test.php4
-rw-r--r--modules/gallery/tests/Gallery_I18n_Test.php2
-rw-r--r--modules/gallery/tests/Gallery_Installer_Test.php2
-rw-r--r--modules/gallery/tests/Gallery_Rest_Helper_Test.php277
-rw-r--r--modules/gallery/tests/Html_Helper_Test.php2
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php33
-rw-r--r--modules/gallery/tests/Item_Model_Test.php279
-rw-r--r--modules/gallery/tests/Item_Rest_Helper_Test.php223
-rw-r--r--modules/gallery/tests/Locales_Helper_Test.php2
-rw-r--r--modules/gallery/tests/Menu_Test.php2
-rw-r--r--modules/gallery/tests/Movie_Helper_Test.php56
-rw-r--r--modules/gallery/tests/ORM_MPTT_Test.php156
-rw-r--r--modules/gallery/tests/Photo_Helper_Test.php130
-rw-r--r--modules/gallery/tests/Photos_Controller_Test.php30
-rw-r--r--modules/gallery/tests/SafeString_Test.php2
-rw-r--r--modules/gallery/tests/Sendmail_Test.php2
-rw-r--r--modules/gallery/tests/Url_Security_Test.php2
-rw-r--r--modules/gallery/tests/Var_Test.php2
-rw-r--r--modules/gallery/tests/Xss_Security_Test.php2
-rw-r--r--modules/gallery/tests/controller_auth_data.txt6
28 files changed, 544 insertions, 925 deletions
diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php
index 298dd0ac..5331117d 100644
--- a/modules/gallery/tests/Access_Helper_Test.php
+++ b/modules/gallery/tests/Access_Helper_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Access_Helper_Test extends Unit_Test_Case {
+class Access_Helper_Test extends Gallery_Unit_Test_Case {
private $_group;
public function teardown() {
@@ -40,8 +40,7 @@ class Access_Helper_Test extends Unit_Test_Case {
} catch (Exception $e) { }
// Reset some permissions that we mangle below
- $root = ORM::factory("item", 1);
- access::allow(identity::everybody(), "view", $root);
+ access::allow(identity::everybody(), "view", item::root());
}
public function setup() {
@@ -67,16 +66,15 @@ class Access_Helper_Test extends Unit_Test_Case {
public function user_can_access_test() {
$access_test = identity::create_group("access_test");
- $root = ORM::factory("item", 1);
- access::allow($access_test, "view", $root);
+ access::allow($access_test, "view", item::root());
- $item = album::create($root, rand(), "test album");
+ $item = test::random_album();
access::deny(identity::everybody(), "view", $item);
access::deny(identity::registered_users(), "view", $item);
$item->reload();
- $user = identity::create_user("access_test", "Access Test", "");
+ $user = identity::create_user("access_test", "Access Test", "*****", "user@user.com");
foreach ($user->groups() as $group) {
$user->remove($group);
}
@@ -87,13 +85,12 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function user_can_no_access_test() {
- $root = ORM::factory("item", 1);
- $item = album::create($root, rand(), "test album");
+ $item = test::random_album();
access::deny(identity::everybody(), "view", $item);
access::deny(identity::registered_users(), "view", $item);
- $user = identity::create_user("access_test", "Access Test", "");
+ $user = identity::create_user("access_test", "Access Test", "*****", "user@user.com");
foreach ($user->groups() as $group) {
$user->remove($group);
}
@@ -103,8 +100,7 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function adding_and_removing_items_adds_ands_removes_rows_test() {
- $root = ORM::factory("item", 1);
- $item = album::create($root, rand(), "test album");
+ $item = test::random_album();
// New rows exist
$this->assert_true(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded());
@@ -119,19 +115,16 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function new_photos_inherit_parent_permissions_test() {
- $root = ORM::factory("item", 1);
-
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
access::allow(identity::everybody(), "view", $album);
- $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", "");
+ $photo = test::random_photo($album);
$this->assert_true($photo->__get("view_" . identity::everybody()->id));
}
public function can_allow_deny_and_reset_intent_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
$intent = ORM::factory("access_intent")->where("item_id", "=", $album->id)->find();
// Allow
@@ -167,23 +160,21 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function can_view_item_test() {
- $root = ORM::factory("item", 1);
- access::allow(identity::everybody(), "view", $root);
- $this->assert_true(access::group_can(identity::everybody(), "view", $root));
+ access::allow(identity::everybody(), "view", item::root());
+ $this->assert_true(access::group_can(identity::everybody(), "view", item::root()));
}
public function can_always_fails_on_unloaded_items_test() {
- $root = ORM::factory("item", 1);
- access::allow(identity::everybody(), "view", $root);
- $this->assert_true(access::group_can(identity::everybody(), "view", $root));
+ access::allow(identity::everybody(), "view", item::root());
+ $this->assert_true(access::group_can(identity::everybody(), "view", item::root()));
$bogus = ORM::factory("item", -1);
$this->assert_false(access::group_can(identity::everybody(), "view", $bogus));
}
public function cant_view_child_of_hidden_parent_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $root = item::root();
+ $album = test::random_album();
$root->reload();
access::deny(identity::everybody(), "view", $root);
@@ -194,40 +185,39 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function view_permissions_propagate_down_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
- access::allow(identity::everybody(), "view", $root);
+ access::allow(identity::everybody(), "view", item::root());
access::reset(identity::everybody(), "view", $album);
$album->reload();
$this->assert_true(access::group_can(identity::everybody(), "view", $album));
}
public function view_permissions_propagate_down_to_photos_test() {
- $album = album::create(item::root(), rand(), "test album");
- $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", "");
+ $album = test::random_album();
+ $photo = test::random_photo($album);
identity::set_active_user(identity::guest());
$this->assert_true(access::can("view", $photo));
+ $album->reload(); // MPTT pointers have changed, so reload before calling access::deny
access::deny(identity::everybody(), "view", $album);
- $photo->reload(); // view permissions are cached in the photo
+ $photo->reload(); // view permissions are cached in the photo, so reload before checking
$this->assert_false(access::can("view", $photo));
}
public function can_toggle_view_permissions_propagate_down_test() {
- $root = ORM::factory("item", 1);
- $album1 = album::create($root, rand(), "test album");
- $album2 = album::create($album1, rand(), "test album");
- $album3 = album::create($album2, rand(), "test album");
- $album4 = album::create($album3, rand(), "test album");
+ $album1 = test::random_album(item::root());
+ $album2 = test::random_album($album1);
+ $album3 = test::random_album($album2);
+ $album4 = test::random_album($album3);
$album1->reload();
$album2->reload();
$album3->reload();
$album4->reload();
- access::allow(identity::everybody(), "view", $root);
+ access::allow(identity::everybody(), "view", item::root());
access::deny(identity::everybody(), "view", $album1);
access::reset(identity::everybody(), "view", $album2);
access::reset(identity::everybody(), "view", $album3);
@@ -242,9 +232,9 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function revoked_view_permissions_cant_be_allowed_lower_down_test() {
- $root = ORM::factory("item", 1);
- $album1 = album::create($root, rand(), "test album");
- $album2 = album::create($album1, rand(), "test album");
+ $root = item::root();
+ $album1 = test::random_album($root);
+ $album2 = test::random_album($album1);
$root->reload();
access::deny(identity::everybody(), "view", $root);
@@ -258,38 +248,30 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function can_edit_item_test() {
- $root = ORM::factory("item", 1);
+ $root = item::root();
access::allow(identity::everybody(), "edit", $root);
$this->assert_true(access::group_can(identity::everybody(), "edit", $root));
}
public function non_view_permissions_propagate_down_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
- access::allow(identity::everybody(), "edit", $root);
+ access::allow(identity::everybody(), "edit", item::root());
access::reset(identity::everybody(), "edit", $album);
$this->assert_true(access::group_can(identity::everybody(), "edit", $album));
}
public function non_view_permissions_can_be_revoked_lower_down_test() {
- $root = ORM::factory("item", 1);
- $outer = album::create($root, rand(), "test album");
- $outer_photo = ORM::factory("item");
- $outer_photo->type = "photo";
- $outer_photo->add_to_parent($outer);
- access::add_item($outer_photo);
-
- $inner = album::create($outer, rand(), "test album");
- $inner_photo = ORM::factory("item");
- $inner_photo->type = "photo";
- $inner_photo->add_to_parent($inner);
- access::add_item($inner_photo);
+ $outer = test::random_album();
+ $outer_photo = test::random_photo($outer);
+
+ $inner = test::random_album($outer);
+ $inner_photo = test::random_photo($inner);
$outer->reload();
$inner->reload();
- access::allow(identity::everybody(), "edit", $root);
+ access::allow(identity::everybody(), "edit", item::root());
access::deny(identity::everybody(), "edit", $outer);
access::allow(identity::everybody(), "edit", $inner);
@@ -300,7 +282,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function i_can_edit_test() {
// Create a new user that belongs to no groups
- $user = identity::create_user("access_test", "Access Test", "");
+ $user = identity::create_user("access_test", "Access Test", "*****", "user@user.com");
foreach ($user->groups() as $group) {
$user->remove($group);
}
@@ -308,7 +290,7 @@ class Access_Helper_Test extends Unit_Test_Case {
identity::set_active_user($user);
// This user can't edit anything
- $root = ORM::factory("item", 1);
+ $root = item::root();
$this->assert_false(access::can("edit", $root));
// Now add them to a group that has edit permission
@@ -325,8 +307,7 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function everybody_view_permission_maintains_htaccess_files_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
$this->assert_false(file_exists($album->file_path() . "/.htaccess"));
@@ -344,8 +325,7 @@ class Access_Helper_Test extends Unit_Test_Case {
}
public function everybody_view_full_permission_maintains_htaccess_files_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), "test album");
+ $album = test::random_album();
$this->assert_false(file_exists($album->file_path() . "/.htaccess"));
$this->assert_false(file_exists($album->resize_path() . "/.htaccess"));
@@ -375,16 +355,15 @@ class Access_Helper_Test extends Unit_Test_Case {
public function moved_items_inherit_new_permissions_test() {
identity::set_active_user(identity::lookup_user_by_name("admin"));
- $root = ORM::factory("item", 1);
- $public_album = album::create($root, rand(), "public album");
- $public_photo = photo::create($public_album, MODPATH . "gallery/images/gallery.png", "", "");
+ $public_album = test::random_album();
+ $public_photo = test::random_photo($public_album);
access::allow(identity::everybody(), "view", $public_album);
- $root->reload(); // Account for MPTT changes
+ item::root()->reload(); // Account for MPTT changes
- $private_album = album::create($root, rand(), "private album");
+ $private_album = test::random_album();
access::deny(identity::everybody(), "view", $private_album);
- $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", "");
+ $private_photo = test::random_photo($private_album);
// Make sure that we now have a public photo and private photo.
$this->assert_true(access::group_can(identity::everybody(), "view", $public_photo));
diff --git a/modules/gallery/tests/Album_Helper_Test.php b/modules/gallery/tests/Album_Helper_Test.php
deleted file mode 100644
index ef0905da..00000000
--- a/modules/gallery/tests/Album_Helper_Test.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Album_Helper_Test extends Unit_Test_Case {
- public function create_album_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
-
- $this->assert_equal(VARPATH . "albums/$rand", $album->file_path());
- $this->assert_equal(VARPATH . "thumbs/$rand/.album.jpg", $album->thumb_path());
- $this->assert_true(is_dir(VARPATH . "thumbs/$rand"), "missing thumb dir");
-
- // It's unclear that a resize makes sense for an album. But we have one.
- $this->assert_equal(VARPATH . "resizes/$rand/.album.jpg", $album->resize_path());
- $this->assert_true(is_dir(VARPATH . "resizes/$rand"), "missing resizes dir");
-
- $this->assert_equal(1, $album->parent_id); // MPTT tests will cover other hierarchy checks
- $this->assert_equal($rand, $album->name);
- $this->assert_equal($rand, $album->title);
- $this->assert_equal($rand, $album->description);
- }
-
- public function create_conflicting_album_test() {
- $rand = "name_" . rand();
- $root = ORM::factory("item", 1);
- $album1 = album::create($root, $rand, $rand, $rand);
- $album2 = album::create($root, $rand, $rand, $rand);
- $this->assert_true($album1->name != $album2->name);
- }
-
- public function thumb_url_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $this->assert_equal(
- "http://./var/thumbs/$rand/.album.jpg?m={$album->updated}", $album->thumb_url());
- }
-
- public function resize_url_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $this->assert_equal("http://./var/resizes/$rand/.album.jpg?m={$album->updated}", $album->resize_url());
- }
-
- public function create_album_shouldnt_allow_names_with_slash_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $album = album::create($root, $rand . "/", $rand, $rand);
- } catch (Exception $e) {
- // pass
- return;
- }
-
- $this->assert_true(false, "Shouldn't create an album with / in the name");
- }
-
- public function create_album_silently_trims_trailing_periods_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $album = album::create($root, $rand . "..", $rand, $rand);
- } catch (Exception $e) {
- $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage());
- return;
- }
-
- $this->assert_true(false, "Shouldn't create an album with trailing . in the name");
- }
-}
diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php
index 4d8935cd..76c9a628 100644
--- a/modules/gallery/tests/Albums_Controller_Test.php
+++ b/modules/gallery/tests/Albums_Controller_Test.php
@@ -17,64 +17,58 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Albums_Controller_Test extends Unit_Test_Case {
+class Albums_Controller_Test extends Gallery_Unit_Test_Case {
public function setup() {
$this->_save = array($_POST, $_SERVER);
}
public function teardown() {
list($_POST, $_SERVER) = $this->_save;
- if (isset($this->_album)) {
- $this->_album->delete();
- }
}
public function change_album_test() {
$controller = new Albums_Controller();
- $root = ORM::factory("item", 1);
- $this->_album = album::create($root, "test", "test", "test");
- $orig_name = $this->_album->name;
+ $album = test::random_album();
// Randomize to avoid conflicts.
- $new_dirname = "new_name_" . rand();
+ $new_name = "new_name_" . rand();
- $_POST["dirname"] = $new_dirname;
+ $_POST["name"] = $new_name;
$_POST["title"] = "new title";
$_POST["description"] = "new description";
$_POST["column"] = "weight";
$_POST["direction"] = "ASC";
$_POST["csrf"] = access::csrf_token();
$_POST["slug"] = "new-name";
- access::allow(identity::everybody(), "edit", $root);
+ access::allow(identity::everybody(), "edit", item::root());
ob_start();
- $controller->update($this->_album->id);
- $this->_album->reload();
+ $controller->update($album->id);
+ $album->reload();
$results = ob_get_contents();
ob_end_clean();
- $this->assert_equal(
- json_encode(array("result" => "success")),
- $results);
- $this->assert_equal($new_dirname, $this->_album->name);
- $this->assert_equal("new title", $this->_album->title);
- $this->assert_equal("new description", $this->_album->description);
+ $this->assert_equal(json_encode(array("result" => "success")), $results);
+ $this->assert_equal($new_name, $album->name);
+ $this->assert_equal("new title", $album->title);
+ $this->assert_equal("new description", $album->description);
}
public function change_album_no_csrf_fails_test() {
$controller = new Albums_Controller();
- $root = ORM::factory("item", 1);
- $this->_album = album::create($root, "test", "test", "test");
+ $album = test::random_album();
+
$_POST["name"] = "new name";
$_POST["title"] = "new title";
$_POST["description"] = "new description";
- access::allow(identity::everybody(), "edit", $root);
+ access::allow(identity::everybody(), "edit", item::root());
try {
- $controller->_update($this->_album);
+ $controller->update($album->id);
$this->assert_true(false, "This should fail");
} catch (Exception $e) {
// pass
+ $this->assert_same("@todo FORBIDDEN", $e->getMessage());
}
}
}
diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php
index d5bf37cc..1023568b 100644
--- a/modules/gallery/tests/Cache_Test.php
+++ b/modules/gallery/tests/Cache_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Cache_Test extends Unit_Test_Case {
+class Cache_Test extends Gallery_Unit_Test_Case {
private $_driver;
public function setup() {
db::build()->delete("caches")->execute();
diff --git a/modules/gallery/tests/Controller_Auth_Test.php b/modules/gallery/tests/Controller_Auth_Test.php
index 124d8b4c..c27196da 100644
--- a/modules/gallery/tests/Controller_Auth_Test.php
+++ b/modules/gallery/tests/Controller_Auth_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Controller_Auth_Test extends Unit_Test_Case {
+class Controller_Auth_Test extends Gallery_Unit_Test_Case {
public function find_missing_auth_test() {
$found = array();
$controllers = explode("\n", `git ls-files '*/*/controllers/*.php'`);
diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php
index 6aa186e5..e58f73eb 100644
--- a/modules/gallery/tests/Database_Test.php
+++ b/modules/gallery/tests/Database_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Database_Test extends Unit_Test_Case {
+class Database_Test extends Gallery_Unit_Test_Case {
function setup() {
$config = Kohana_Config::instance();
$config->set("database.mock.connection.type", "mock");
diff --git a/modules/gallery/tests/Dir_Helper_Test.php b/modules/gallery/tests/Dir_Helper_Test.php
index 46bb871c..69241447 100644
--- a/modules/gallery/tests/Dir_Helper_Test.php
+++ b/modules/gallery/tests/Dir_Helper_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Dir_Helper_Test extends Unit_Test_Case {
+class Dir_Helper_Test extends Gallery_Unit_Test_Case {
public function remove_album_test() {
$dirname = (VARPATH . "albums/testdir");
mkdir($dirname, 0777, true);
diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php
index da8a6b04..f7b727c0 100644
--- a/modules/gallery/tests/DrawForm_Test.php
+++ b/modules/gallery/tests/DrawForm_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class DrawForm_Test extends Unit_Test_Case {
+class DrawForm_Test extends Gallery_Unit_Test_Case {
function no_group_test() {
$form = new Forge("test/controller", "", "post", array("id" => "g-test-group-form"));
$form->input("title")->label(t("Title"));
diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php
index b5026188..4590e95d 100644
--- a/modules/gallery/tests/File_Structure_Test.php
+++ b/modules/gallery/tests/File_Structure_Test.php
@@ -19,7 +19,7 @@
*/
require_once(MODPATH . "gallery/tests/Gallery_Filters.php");
-class File_Structure_Test extends Unit_Test_Case {
+class File_Structure_Test extends Gallery_Unit_Test_Case {
public function no_trailing_closing_php_tag_test() {
$dir = new GalleryCodeFilterIterator(
new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
@@ -36,7 +36,7 @@ class File_Structure_Test extends Unit_Test_Case {
$dir = new GalleryCodeFilterIterator(
new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
foreach ($dir as $file) {
- if (strpos($file, "modules/gallery/views/kohana/error.php")) {
+ if (strpos($file, "views/kohana/error.php")) {
continue;
}
diff --git a/modules/gallery/tests/Gallery_I18n_Test.php b/modules/gallery/tests/Gallery_I18n_Test.php
index 5d2fd994..f6e50d71 100644
--- a/modules/gallery/tests/Gallery_I18n_Test.php
+++ b/modules/gallery/tests/Gallery_I18n_Test.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Gallery_I18n_Test extends Unit_Test_Case {
+class Gallery_I18n_Test extends Gallery_Unit_Test_Case {
private $i18n;
public function setup() {
diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php
index 74a07b1a..3db434bc 100644
--- a/modules/gallery/tests/Gallery_Installer_Test.php
+++ b/modules/gallery/tests/Gallery_Installer_Test.php
@@ -22,7 +22,7 @@
* This test case operates under the assumption that gallery_installer::install() is called by the
* test controller before it starts.
*/
-class Gallery_Installer_Test extends Unit_Test_Case {
+class Gallery_Installer_Test extends Gallery_Unit_Test_Case {
public function install_creates_dirs_test() {
$this->assert_true(file_exists(VARPATH . "albums"));
$this->assert_true(file_exists(VARPATH . "resizes"));
diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php
deleted file mode 100644
index f8cf6190..00000000
--- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php
+++ /dev/null
@@ -1,277 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Gallery_Rest_Helper_Test extends Unit_Test_Case {
- public function setup() {
- $this->_save = array($_GET, $_POST, $_SERVER, $_FILES);
- $this->_saved_active_user = identity::active_user();
- }
-
- public function teardown() {
- list($_GET, $_POST, $_SERVER, $_FILES) = $this->_save;
- identity::set_active_user($this->_saved_active_user);
- if (!empty($this->_user)) {
- try {
- $this->_user->delete();
- } catch (Exception $e) { }
- }
- }
-
- private function _create_user() {
- if (empty($this->_user)) {
- $this->_user = identity::create_user("access_test" . rand(), "Access Test", "password");
- $key = ORM::factory("user_access_token");
- $key->access_key = md5($this->_user->name . rand());
- $key->user_id = $this->_user->id;
- $key->save();
- identity::set_active_user($this->_user);
- }
- return $this->_user;
- }
-
- private function _create_album($parent=null) {
- $album_name = "rest_album_" . rand();
- if (empty($parent)) {
- $parent = ORM::factory("item", 1);
- }
- return album::create($parent, $album_name, $album_name, $album_name);
- }
-
- private function _create_image($parent=null) {
- $filename = MODPATH . "gallery/tests/test.jpg";
- $image_name = "rest_image_" . rand();
- if (empty($parent)) {
- $parent = ORM::factory("item", 1);
- }
- return photo::create($parent, $filename, "$image_name.jpg", $image_name);
- }
-
- public function gallery_rest_get_album_test() {
- $album = $this->_create_album();
- $child = $this->_create_album($album);
- $photo = $this->_create_image($child);
- $child->reload();
- $request = (object)array("arguments" => explode("/", $child->relative_url()));
-
- $this->assert_equal(
- json_encode(array("status" => "OK",
- "resource" =>
- array("type" => $child->type,
- "name" => $child->name,
- "path" => $child->relative_url(),
- "parent_path" => $album->relative_url(),
- "title" => $child->title,
- "thumb_url" => $child->thumb_url(),
- "thumb_size" => array("height" => $child->thumb_height,
- "width" => $child->thumb_width),
- "resize_url" => $child->resize_url(),
- "resize_size" => array("height" => 0,
- "width" => 0),
- "url" => $child->file_url(),
- "size" => array("height" => $child->height,
- "width" => $child->width),
- "description" => $child->description,
- "slug" => $child->slug,
- "children" => array(array(
- "type" => "photo",
- "has_children" => false,
- "path" => $photo->relative_url(),
- "thumb_url" => $photo->thumb_url(),
- "thumb_dimensions" => array(
- "width" => (string)$photo->thumb_width,
- "height" => (string)$photo->thumb_height),
- "has_thumb" => true,
- "title" => $photo->title))))),
- gallery_rest::get($request));
- }
-
- public function gallery_rest_get_photo_test() {
- $child = $this->_create_album();
- $photo = $this->_create_image($child);
- $request = (object)array("arguments" => explode("/", $photo->relative_url()));
-
- $this->assert_equal(
- json_encode(array("status" => "OK",
- "resource" =>
- array("type" => $photo->type,
- "name" => $photo->name,
- "path" => $photo->relative_url(),
- "parent_path" => $child->relative_url(),
- "title" => $photo->title,
- "thumb_url" => $photo->thumb_url(),
- "thumb_size" => array("height" => (string)$photo->thumb_height,
- "width" => (string)$photo->thumb_width),
- "resize_url" => $photo->resize_url(),
- "resize_size" => array("height" => $photo->resize_height,
- "width" => $photo->resize_width),
- "url" => $photo->file_url(),
- "size" => array("height" => (string)$photo->height,
- "width" => (string)$photo->width),
- "description" => $photo->description,
- "slug" => $photo->slug))),
- gallery_rest::get($request));
- }
-
- public function gallery_rest_put_album_no_path_test() {
- $request = (object)array("description" => "Updated description",
- "title" => "Updated Title",
- "name" => "new name");
-
- try {
- gallery_rest::put($request);
- } catch (Rest_Exception $e) {
- $this->assert_equal("400 Bad request", $e->getMessage());
- } catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
- }
- }
-
- public function gallery_rest_put_album_not_found_test() {
- $photo = $this->_create_image();
- $request = (object)array("arguments" => explode("/", $photo->relative_url() . rand()),
- "description" => "Updated description",
- "title" => "Updated Title",
- "name" => "new name");
-
- try {
- gallery_rest::put($request);
- } catch (Kohana_404_Exception $k404) {
- } catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
- }
- }
-
- public function gallery_rest_put_album_no_edit_permission_test() {
- $child = $this->_create_album();
- $this->_create_user();
- $request = (object)array("arguments" => explode("/", $child->relative_url()),
- "description" => "Updated description",
- "title" => "Updated Title",
- "name" => "new name");
-
- try {
- gallery_rest::put($request);
- } catch (Kohana_404_Exception $k404) {
- } catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
- }
- }
-
- public function gallery_rest_put_album_rename_conflict_test() {
- $child = $this->_create_album();
- $sibling = $this->_create_image();
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $child);
- $request = (object)array("arguments" => explode("/", $child->relative_url()),
- "description" => "Updated description",
- "title" => "Updated Title",
- "name" => $sibling->name);
-
- $this->assert_equal(
- json_encode(array("status" => "VALIDATE_ERROR",
- "fields" => array("slug" => "Duplicate Internet address"))),
- gallery_rest::put($request));
- }
-
- public function gallery_rest_put_album_test() {
- $child = $this->_create_album();
- $sibling = $this->_create_image();
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $child);
-
- $new_name = "new_album_name" . rand();
- $request = (object)array("arguments" => explode("/", $child->relative_url()),
- "description" => "Updated description",
- "title" => "Updated Title",
- "name" => $new_name);
-
- $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request));
- $child->reload();
- $this->assert_equal("Updated description", $child->description);
- $this->assert_equal("Updated Title", $child->title);
- $this->assert_equal($new_name, $child->name);
- }
-
- public function gallery_rest_put_photo_test() {
- $child = $this->_create_album();
- $photo = $this->_create_image($child);
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $child);
-
- $request = (object)array("arguments" => explode("/", $photo->relative_url()),
- "description" => "Updated description",
- "title" => "Updated Title",
- "name" => "new name");
-
- $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request));
- $photo->reload();
- $this->assert_equal("Updated description", $photo->description);
- $this->assert_equal("Updated Title", $photo->title);
- $this->assert_equal("new name", $photo->name);
- }
-
- public function gallery_rest_delete_album_test() {
- $album = $this->_create_album();
- $child = $this->_create_album($album);
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $album);
-
- $request = (object)array("arguments" => explode("/", $child->relative_url()));
-
- $this->assert_equal(json_encode(array("status" => "OK",
- "resource" => array(
- "parent_path" => $album->relative_url()))),
- gallery_rest::delete($request));
- $child->reload();
- $this->assert_false($child->loaded());
- }
-
- public function gallery_rest_delete_photo_test() {
- $album = $this->_create_album();
- $photo = $this->_create_image($album);
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $album);
-
- $request = (object)array("arguments" => explode("/", $photo->relative_url()));
-
- $this->assert_equal(json_encode(array("status" => "OK",
- "resource" => array(
- "parent_path" => $album->relative_url()))),
- gallery_rest::delete($request));
- $photo->reload();
- $this->assert_false($photo->loaded());
- }
-
- public function gallery_rest_post_album_test() {
- $album = $this->_create_album();
- $this->_create_user();
- access::allow(identity::registered_users(), "edit", $album);
-
- $new_path = $album->relative_url() . "/new%20child";
- $request = (object)array("arguments" => explode("/", $new_path));
-
- $this->assert_equal(json_encode(array("status" => "OK", "path" => $new_path)),
- gallery_rest::post($request));
- $album = ORM::factory("item")
- ->where("relative_url_cache", "=", $new_path)
- ->find();
- $this->assert_true($album->loaded());
- $this->assert_equal("new child", $album->slug);
- }
-}
diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php
index 1662b866..be318632 100644
--- a/modules/gallery/tests/Html_Helper_Test.php
+++ b/modules/gallery/tests/Html_Helper_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Html_Helper_Test extends Unit_Test_Case {
+class Html_Helper_Test extends Gallery_Unit_Test_Case {
public function clean_test() {
$safe_string = html::clean("hello <p >world</p>");
$this->assert_equal("hello &lt;p &gt;world&lt;/p&gt;",
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index f0c653c0..cdbdd324 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -17,12 +17,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Item_Helper_Test extends Unit_Test_Case {
+class Item_Helper_Test extends Gallery_Unit_Test_Case {
public function viewable_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), rand(), rand());
- $item = self::_create_random_item($album);
+ $album = test::random_album();
+ $item = test::random_photo($album);
+ $album->reload();
identity::set_active_user(identity::guest());
// We can see the item when permissions are granted
@@ -38,33 +38,8 @@ class Item_Helper_Test extends Unit_Test_Case {
ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
}
- public function validate_url_safe_test() {
- $input = new MockInput();
- $input->value = "Ab_cd-ef-d9";
- item::validate_url_safe($input);
- $this->assert_true(!isset($input->not_url_safe));
-
- $input->value = "ab&cd";
- item::validate_url_safe($input);
- $this->assert_equal(1, $input->not_url_safe);
- }
-
public function convert_filename_to_slug_test() {
$this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}"));
$this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!$@#^$@($!(@bar]}"));
}
-
- private static function _create_random_item($album) {
- // Set all required fields (values are irrelevant)
- $item = ORM::factory("item");
- $item->name = rand();
- $item->type = "photo";
- return $item->add_to_parent($album);
- }
}
-
-class MockInput {
- function add_error($error, $value) {
- $this->$error = $value;
- }
-} \ No newline at end of file
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index d03a03f4..1e77076a 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -17,22 +17,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Item_Model_Test extends Unit_Test_Case {
+class Item_Model_Test extends Gallery_Unit_Test_Case {
public function saving_sets_created_and_updated_dates_test() {
- $item = self::_create_random_item();
+ $item = test::random_photo();
$this->assert_true(!empty($item->created));
$this->assert_true(!empty($item->updated));
}
- private static function _create_random_item($root=null, $rand=null) {
- $root = $root ? $root : ORM::factory("item", 1);
- $rand = $rand ? $rand : rand();
- $item = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
- return $item;
- }
-
public function updating_doesnt_change_created_date_test() {
- $item = self::_create_random_item();
+ $item = test::random_photo();
// Force the creation date to something well known
db::build()
@@ -50,7 +43,7 @@ class Item_Model_Test extends Unit_Test_Case {
}
public function updating_view_count_only_doesnt_change_updated_date_test() {
- $item = self::_create_random_item();
+ $item = test::random_photo();
$item->reload();
$this->assert_equal(0, $item->view_count);
@@ -69,18 +62,16 @@ class Item_Model_Test extends Unit_Test_Case {
}
public function rename_photo_test() {
- // Create a test photo
- $item = self::_create_random_item();
+ $item = test::random_photo();
+ $original_name = $item->name;
file_put_contents($item->thumb_path(), "thumb");
file_put_contents($item->resize_path(), "resize");
file_put_contents($item->file_path(), "file");
- $original_name = $item->name;
- $new_name = rand();
-
// Now rename it
- $item->rename($new_name)->save();
+ $item->name = ($new_name = test::random_name($item));
+ $item->save();
// Expected: the name changed, the name is now baked into all paths, and all files were moved.
$this->assert_equal($new_name, $item->name);
@@ -93,10 +84,9 @@ class Item_Model_Test extends Unit_Test_Case {
}
public function rename_album_test() {
- // Create an album with a photo in it
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), rand(), rand());
- $photo = self::_create_random_item($album);
+ $album = test::random_album();
+ $photo = test::random_photo($album);
+ $album->reload();
file_put_contents($photo->thumb_path(), "thumb");
file_put_contents($photo->resize_path(), "resize");
@@ -104,10 +94,11 @@ class Item_Model_Test extends Unit_Test_Case {
$original_album_name = $album->name;
$original_photo_name = $photo->name;
- $new_album_name = rand();
+ $new_album_name = test::random_name();
// Now rename the album
- $album->rename($new_album_name)->save();
+ $album->name = $new_album_name;
+ $album->save();
$photo->reload();
// Expected:
@@ -120,9 +111,9 @@ class Item_Model_Test extends Unit_Test_Case {
$this->assert_equal($new_album_name, basename(dirname($album->thumb_path())));
$this->assert_equal($new_album_name, basename(dirname($album->resize_path())));
- $this->assert_same(0, strpos($photo->file_path(), $album->file_path()));
- $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path())));
- $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path())));
+ $this->assert_true(test::starts_with($photo->file_path(), $album->file_path()));
+ $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album->thumb_path())));
+ $this->assert_true(test::starts_with($photo->resize_path(), dirname($album->resize_path())));
$this->assert_equal("thumb", file_get_contents($photo->thumb_path()));
$this->assert_equal("resize", file_get_contents($photo->resize_path()));
@@ -130,81 +121,56 @@ class Item_Model_Test extends Unit_Test_Case {
}
public function item_rename_wont_accept_slash_test() {
- // Create a test photo
- $item = self::_create_random_item();
-
- $new_name = rand() . "/";
-
+ $item = test::random_photo();
try {
- $item->rename($new_name)->save();
- } catch (Exception $e) {
- // pass
+ $item->name = test::random_name() . "/";
+ $item->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(array("name" => "no_slashes"), $e->validation->errors());
return;
}
- $this->assert_false(true, "Item_Model::rename should not accept / characters");
+ $this->assert_true(false, "Shouldn't get here");
}
public function item_rename_fails_with_existing_name_test() {
// Create a test photo
- $item = self::_create_random_item();
- $item2 = self::_create_random_item();
-
- $new_name = $item2->name;
+ $item = test::random_photo();
+ $item2 = test::random_photo();
try {
- $item->rename($new_name)->save();
- } catch (Exception $e) {
- // pass
- $this->assert_true(strpos($e->getMessage(), "INVALID_RENAME_FILE_EXISTS") !== false,
- "incorrect exception.");
+ $item->name = $item2->name;
+ $item->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_true(in_array("conflict", $e->validation->errors()));
return;
}
- $this->assert_false(true, "Item_Model::rename should fail.");
- }
-
- public function save_original_values_test() {
- $item = self::_create_random_item();
- $item->title = "ORIGINAL_VALUE";
- $item->save();
- $item->title = "NEW_VALUE";
-
- $this->assert_same("ORIGINAL_VALUE", $item->original()->title);
- $this->assert_same("NEW_VALUE", $item->title);
- }
-
- public function urls_are_rawurlencoded_test() {
- $item = self::_create_random_item();
- $item->slug = "foo bar";
- $item->name = "foo bar.jpg";
- $item->save();
- $this->assert_equal("foo%20bar", $item->relative_url());
- $this->assert_equal("foo%20bar.jpg", $item->relative_path());
+ $this->assert_false(true, "rename should conflict");
}
public function move_album_test() {
- // Create an album with a photo in it
- $root = ORM::factory("item", 1);
- $album2 = album::create($root, rand(), rand(), rand());
- $album = album::create($album2, rand(), rand(), rand());
- $photo = self::_create_random_item($album);
+ $album2 = test::random_album();
+ $album1 = test::random_album($album2);
+ $photo = test::random_photo($album1);
file_put_contents($photo->thumb_path(), "thumb");
file_put_contents($photo->resize_path(), "resize");
file_put_contents($photo->file_path(), "file");
// Now move the album
- $album->move_to($root);
+ $album1->parent_id = item::root()->id;
+ $album1->save();
$photo->reload();
// Expected:
- // * the album dirs are all moved
+ // * album is not inside album2 anymore
// * the photo's paths are all inside the albums paths
// * the photo files are all still intact and accessible
- $this->assert_same(0, strpos($photo->file_path(), $album->file_path()));
- $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path())));
- $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path())));
+ $this->assert_false(test::starts_with($album2->file_path(), $album1->file_path()));
+ $this->assert_true(test::starts_with($photo->file_path(), $album1->file_path()));
+ $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album1->thumb_path())));
+ $this->assert_true(test::starts_with($photo->resize_path(), dirname($album1->resize_path())));
$this->assert_equal("thumb", file_get_contents($photo->thumb_path()));
$this->assert_equal("resize", file_get_contents($photo->resize_path()));
@@ -212,71 +178,162 @@ class Item_Model_Test extends Unit_Test_Case {
}
public function move_photo_test() {
- // Create an album with a photo in it
- $root = ORM::factory("item", 1);
- $album2 = album::create($root, rand(), rand(), rand());
- $album = album::create($album2, rand(), rand(), rand());
- $photo = self::_create_random_item($album);
+ $album1 = test::random_album();
+ $photo = test::random_photo($album1);
+
+ $album2 = test::random_album();
file_put_contents($photo->thumb_path(), "thumb");
file_put_contents($photo->resize_path(), "resize");
file_put_contents($photo->file_path(), "file");
- // Now move the album
- $photo->move_to($album2);
- $photo->reload();
+ // Now move the photo
+ $photo->parent_id = $album2->id;
+ $photo->save();
// Expected:
- // * the album dirs are all moved
- // * the photo's paths are all inside the albums paths
+ // * the photo's paths are inside the album2 not album1
// * the photo files are all still intact and accessible
- $this->assert_same(0, strpos($photo->file_path(), $album->file_path()));
- $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path())));
- $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path())));
+ $this->assert_true(test::starts_with($photo->file_path(), $album2->file_path()));
+ $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album2->thumb_path())));
+ $this->assert_true(test::starts_with($photo->resize_path(), dirname($album2->resize_path())));
$this->assert_equal("thumb", file_get_contents($photo->thumb_path()));
$this->assert_equal("resize", file_get_contents($photo->resize_path()));
$this->assert_equal("file", file_get_contents($photo->file_path()));
}
- public function move_album_fails_invalid_target_test() {
- // Create an album with a photo in it
- $root = ORM::factory("item", 1);
- $name = rand();
- $album = album::create($root, $name, $name, $name);
- $source = album::create($album, $name, $name, $name);
+ public function move_album_fails_conflicting_target_test() {
+ $album = test::random_album();
+ $source = test::random_album_unsaved($album);
+ $source->name = $album->name;
+ $source->save();
+
+ // $source and $album have the same name, so if we move $source into the root they should
+ // conflict.
try {
- $source->move_to($root);
- } catch (Exception $e) {
- // pass
- $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false,
- "incorrect exception.");
+ $source->parent_id = item::root()->id;
+ $source->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(
+ array("name" => "conflict", "slug" => "conflict"), $e->validation->errors());
return;
}
+ $this->assert_true(false, "Shouldn't get here");
+ }
+
+ public function move_album_fails_wrong_target_type_test() {
+ $album = test::random_album();
+ $photo = test::random_photo();
+
+ // $source and $album have the same name, so if we move $source into the root they should
+ // conflict.
- $this->assert_false(true, "Item_Model::rename should not accept / characters");
+ try {
+ $album->parent_id = $photo->id;
+ $album->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors());
+ return;
+ }
+ $this->assert_true(false, "Shouldn't get here");
}
- public function move_photo_fails_invalid_target_test() {
- // Create an album with a photo in it
- $root = ORM::factory("item", 1);
- $photo_name = rand();
- $photo1 = self::_create_random_item($root, $photo_name);
- $name = rand();
- $album = album::create($root, $name, $name, $name);
- $photo2 = self::_create_random_item($album, $photo_name);
+ public function move_photo_fails_conflicting_target_test() {
+ $photo1 = test::random_photo();
+ $album = test::random_album();
+ $photo2 = test::random_photo_unsaved($album);
+ $photo2->name = $photo1->name;
+ $photo2->save();
+
+ // $photo1 and $photo2 have the same name, so if we move $photo1 into the root they should
+ // conflict.
try {
- $photo2->move_to($root);
+ $photo2->parent_id = item::root()->id;
+ $photo2->save();
} catch (Exception $e) {
// pass
- $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false,
- "incorrect exception.");
+ $this->assert_equal(
+ array("name" => "conflict", "slug" => "conflict"), $e->validation->errors());
return;
}
+ $this->assert_true(false, "Shouldn't get here");
+ }
+
+ public function move_album_inside_descendent_fails_test() {
+ $album1 = test::random_album();
+ $album2 = test::random_album($album1);
+ $album3 = test::random_album($album2);
+
+ try {
+ $album1->parent_id = $album3->id;
+ $album1->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors());
+ return;
+ }
+ $this->assert_true(false, "Shouldn't get here");
+ }
- $this->assert_false(true, "Item_Model::rename should not accept / characters");
+
+ public function basic_validation_test() {
+ $item = ORM::factory("item");
+ $item->album_cover_item_id = rand(); // invalid
+ $item->description = str_repeat("x", 70000); // invalid
+ $item->name = null;
+ $item->parent_id = rand();
+ $item->slug = null;
+ $item->sort_column = "bogus";
+ $item->sort_order = "bogus";
+ $item->title = null;
+ $item->type = "bogus";
+ try {
+ $item->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_same(array("description" => "length",
+ "name" => "required",
+ "slug" => "required",
+ "title" => "required",
+ "album_cover_item_id" => "invalid_item",
+ "parent_id" => "invalid",
+ "sort_column" => "invalid",
+ "sort_order" => "invalid",
+ "type" => "invalid"),
+ $e->validation->errors());
+ return;
+ }
+
+ $this->assert_false(true, "Shouldn't get here");
+ }
+
+ public function slug_is_url_safe_test() {
+ try {
+ $album = test::random_album_unsaved();
+ $album->slug = "illegal chars! !@#@#$!@~";
+ $album->save();
+ $this->assert_true(false, "Shouldn't be able to save");
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_same(array("slug" => "not_url_safe"), $e->validation->errors());
+ }
+
+ // This should work
+ $album->slug = "the_quick_brown_fox";
+ $album->save();
+ }
+
+ public function cant_change_item_type_test() {
+ $photo = test::random_photo();
+ try {
+ $photo->type = "movie";
+ $photo->mime_type = "video/x-flv";
+ $photo->save();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_same(array("type" => "read_only"), $e->validation->errors());
+ return; // pass
+ }
+ $this->assert_true(false, "Shouldn't get here");
}
}
diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php
new file mode 100644
index 00000000..8ce6bc43
--- /dev/null
+++ b/modules/gallery/tests/Item_Rest_Helper_Test.php
@@ -0,0 +1,223 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
+ public function resolve_test() {
+ $album = test::random_album();
+ $resolved = rest::resolve(rest::url("item", $album));
+ $this->assert_equal($album->id, $resolved->id);
+ }
+
+ public function get_scope_test() {
+ $album1 = test::random_album();
+ $photo1 = test::random_photo($album1);
+ $album2 = test::random_album($album1);
+ $photo2 = test::random_photo($album2);
+ $album1->reload();
+
+ // No scope is the same as "direct"
+ $request->url = rest::url("item", $album1);
+ $request->params = new stdClass();
+ $this->assert_equal_array(
+ array("url" => rest::url("item", $album1),
+ "resource" => $album1->as_array(),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array()))),
+ item_rest::get($request));
+
+ $request->url = rest::url("item", $album1);
+ $request->params->scope = "direct";
+ $this->assert_equal_array(
+ array("url" => rest::url("item", $album1),
+ "resource" => $album1->as_array(),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array()))),
+ item_rest::get($request));
+
+ $request->url = rest::url("item", $album1);
+ $request->params->scope = "all";
+ $this->assert_equal_array(
+ array("url" => rest::url("item", $album1),
+ "resource" => $album1->as_array(),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2),
+ rest::url("item", $photo2)),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array()))),
+ item_rest::get($request));
+ }
+
+ public function get_children_like_test() {
+ $album1 = test::random_album();
+ $photo1 = test::random_photo($album1);
+ $photo2 = test::random_photo_unsaved($album1);
+ $photo2->name = "foo.jpg";
+ $photo2->save();
+ $album1->reload();
+
+ $request->url = rest::url("item", $album1);
+ $request->params->name = "foo";
+ $this->assert_equal_array(
+ array("url" => rest::url("item", $album1),
+ "resource" => $album1->as_array(),
+ "members" => array(
+ rest::url("item", $photo2)),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array()))),
+ item_rest::get($request));
+ }
+
+ public function get_children_type_test() {
+ $album1 = test::random_album();
+ $photo1 = test::random_photo($album1);
+ $album2 = test::random_album($album1);
+ $album1->reload();
+
+ $request->url = rest::url("item", $album1);
+ $request->params->type = "album";
+ $this->assert_equal_array(
+ array("url" => rest::url("item", $album1),
+ "resource" => $album1->as_array(),
+ "members" => array(
+ rest::url("item", $album2)),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array() ))),
+ item_rest::get($request));
+ }
+
+ public function update_album_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ $request->params->title = "my new title";
+
+ item_rest::put($request);
+ $this->assert_equal("my new title", $album1->reload()->title);
+ }
+
+ public function update_album_illegal_value_fails_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ $request->params->title = "my new title";
+ $request->params->slug = "not url safe";
+
+ try {
+ item_rest::put($request);
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors());
+ return;
+ }
+ $this->assert_true(false, "Shouldn't get here");
+ }
+
+ public function add_album_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ $request->params->type = "album";
+ $request->params->name = "my album";
+ $request->params->title = "my album";
+ $response = item_rest::post($request);
+ $new_album = rest::resolve($response["url"]);
+
+ $this->assert_true($new_album->is_album());
+ $this->assert_equal($album1->id, $new_album->parent_id);
+ }
+
+ public function add_album_illegal_value_fails_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ $request->params->type = "album";
+ $request->params->name = "my album";
+ $request->params->title = "my album";
+ $request->params->slug = "not url safe";
+
+ try {
+ item_rest::post($request);
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors());
+ return;
+ }
+ $this->assert_true(false, "Shouldn't get here");
+ }
+
+
+ public function add_photo_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ $request->params->type = "photo";
+ $request->params->name = "my photo.jpg";
+ $request->file = MODPATH . "gallery/tests/test.jpg";
+ $response = item_rest::post($request);
+ $new_photo = rest::resolve($response["url"]);
+
+ $this->assert_true($new_photo->is_photo());
+ $this->assert_equal($album1->id, $new_photo->parent_id);
+ }
+
+ public function delete_album_test() {
+ $album1 = test::random_album();
+ access::allow(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ item_rest::delete($request);
+
+ $album1->reload();
+ $this->assert_false($album1->loaded());
+ }
+
+ public function delete_album_fails_without_permission_test() {
+ $album1 = test::random_album();
+ access::deny(identity::everybody(), "edit", $album1);
+
+ $request->url = rest::url("item", $album1);
+ try {
+ item_rest::delete($request);
+ } catch (Exception $e) {
+ $this->assert_equal("@todo FORBIDDEN", $e->getMessage());
+ return;
+ }
+ $this->assert_true(false, "Shouldn't get here");
+ }
+}
diff --git a/modules/gallery/tests/Locales_Helper_Test.php b/modules/gallery/tests/Locales_Helper_Test.php
index 4c03d8d4..a2680928 100644
--- a/modules/gallery/tests/Locales_Helper_Test.php
+++ b/modules/gallery/tests/Locales_Helper_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Locales_Helper_Test extends Unit_Test_Case {
+class Locales_Helper_Test extends Gallery_Unit_Test_Case {
static $installed_locales;
static $default_locale;
diff --git a/modules/gallery/tests/Menu_Test.php b/modules/gallery/tests/Menu_Test.php
index c91aee0b..643aa727 100644
--- a/modules/gallery/tests/Menu_Test.php
+++ b/modules/gallery/tests/Menu_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Menu_Test extends Unit_Test_Case {
+class Menu_Test extends Gallery_Unit_Test_Case {
public function find_menu_item_test() {
$menu = new Menu(true);
$menu
diff --git a/modules/gallery/tests/Movie_Helper_Test.php b/modules/gallery/tests/Movie_Helper_Test.php
deleted file mode 100644
index 23544934..00000000
--- a/modules/gallery/tests/Movie_Helper_Test.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Movie_Helper_Test extends Unit_Test_Case {
- public function create_movie_shouldnt_allow_names_with_slash_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $movie = movie::create($root, MODPATH . "gallery/tests/test.flv", "$rand/.flv", $rand, $rand);
- } catch (Exception $e) {
- // pass
- return;
- }
-
- $this->assert_true(false, "Shouldn't create a movie with / in the name");
- }
-
- public function create_movie_shouldnt_allow_names_with_trailing_periods_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $movie = movie::create($root, MODPATH . "gallery/tests/test.flv", "$rand.flv.", $rand, $rand);
- } catch (Exception $e) {
- $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage());
- return;
- }
-
- $this->assert_true(false, "Shouldn't create a movie with trailing . in the name");
- }
-
- public function create_movie_creates_reasonable_slug_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $movie = movie::create(
- $album, MODPATH . "gallery/tests/test.flv", "This (is) my file%name.flv", $rand, $rand);
-
- $this->assert_equal("This-is-my-file-name", $movie->slug);
- }
-}
diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php
index 69b6bea9..5e741537 100644
--- a/modules/gallery/tests/ORM_MPTT_Test.php
+++ b/modules/gallery/tests/ORM_MPTT_Test.php
@@ -17,21 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class ORM_MPTT_Test extends Unit_Test_Case {
-
- private function create_item_and_add_to_parent($parent) {
- $album = album::create($parent, rand(), "test album");
- return $album;
- }
+class ORM_MPTT_Test extends Gallery_Unit_Test_Case {
public function add_to_parent_test() {
- $root = ORM::factory("item", 1);
- $album = ORM::factory("item");
- $album->type = "album";
- $album->rand_key = ((float)mt_rand()) / (float)mt_getrandmax();
- $album->sort_column = "weight";
- $album->sort_order = "ASC";
- $album->add_to_parent($root);
+ $album = test::random_album();
$this->assert_equal($album->parent()->right_ptr - 2, $album->left_ptr);
$this->assert_equal($album->parent()->right_ptr - 1, $album->right_ptr);
@@ -40,12 +29,11 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function add_hierarchy_test() {
- $root = ORM::factory("item", 1);
- $album1 = self::create_item_and_add_to_parent($root);
- $album1_1 = self::create_item_and_add_to_parent($album1);
- $album1_2 = self::create_item_and_add_to_parent($album1);
- $album1_1_1 = self::create_item_and_add_to_parent($album1_1);
- $album1_1_2 = self::create_item_and_add_to_parent($album1_1);
+ $album1 = test::random_album();
+ $album1_1 = test::random_album($album1);
+ $album1_2 = test::random_album($album1);
+ $album1_1_1 = test::random_album($album1_1);
+ $album1_1_2 = test::random_album($album1_1);
$album1->reload();
$this->assert_equal(9, $album1->right_ptr - $album1->left_ptr);
@@ -55,12 +43,11 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function delete_hierarchy_test() {
- $root = ORM::factory("item", 1);
- $album1 = self::create_item_and_add_to_parent($root);
- $album1_1 = self::create_item_and_add_to_parent($album1);
- $album1_2 = self::create_item_and_add_to_parent($album1);
- $album1_1_1 = self::create_item_and_add_to_parent($album1_1);
- $album1_1_2 = self::create_item_and_add_to_parent($album1_1);
+ $album1 = test::random_album();
+ $album1_1 = test::random_album($album1);
+ $album1_2 = test::random_album($album1);
+ $album1_1_1 = test::random_album($album1_1);
+ $album1_1_2 = test::random_album($album1_1);
$album1_1->delete();
$album1->reload();
@@ -70,17 +57,17 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function move_to_test() {
- $root = ORM::factory("item", 1);
- $album1 = album::create($root, "move_to_test_1", "move_to_test_1");
- $album1_1 = album::create($album1, "move_to_test_1_1", "move_to_test_1_1");
- $album1_2 = album::create($album1, "move_to_test_1_2", "move_to_test_1_2");
- $album1_1_1 = album::create($album1_1, "move_to_test_1_1_1", "move_to_test_1_1_1");
- $album1_1_2 = album::create($album1_1, "move_to_test_1_1_2", "move_to_test_1_1_2");
+ $album1 = test::random_album();
+ $album1_1 = test::random_album($album1);
+ $album1_2 = test::random_album($album1);
+ $album1_1_1 = test::random_album($album1_1);
+ $album1_1_2 = test::random_album($album1_1);
$album1_2->reload();
$album1_1_1->reload();
- $album1_1_1->move_to($album1_2);
+ $album1_1_1->parent_id = $album1_2->id;
+ $album1_1_1->save();
$album1_1->reload();
$album1_2->reload();
@@ -89,39 +76,38 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$this->assert_equal(3, $album1_2->right_ptr - $album1_2->left_ptr);
$this->assert_equal(
- array($album1_1_2->id => "move_to_test_1_1_2"),
+ array($album1_1_2->id => $album1_1_2->name),
$album1_1->children()->select_list());
$this->assert_equal(
- array($album1_1_1->id => "move_to_test_1_1_1"),
+ array($album1_1_1->id => $album1_1_1->name),
$album1_2->children()->select_list());
}
public function cant_move_parent_into_own_subtree_test() {
- $album1 = album::create(item::root(), "move_to_test", "move_to_test");
- $album2 = album::create($album1, "move_to_test", "move_to_test");
- $album3 = album::create($album2, "move_to_test", "move_to_test");
+ $album1 = test::random_album(item::root());
+ $album2 = test::random_album($album1);
+ $album3 = test::random_album($album2);
try {
- $album1->move_to($album3);
- $self->assert_true(false, "We should be unable to move an item inside its own hierarchy");
+ $album1->parent_id = $album3->id;
+ $album1->save();
+ $this->assert_true(false, "We should be unable to move an item inside its own hierarchy");
} catch (Exception $e) {
// pass
}
}
public function parent_test() {
- $root = ORM::factory("item", 1);
- $album = self::create_item_and_add_to_parent($root);
+ $album = test::random_album();
$parent = ORM::factory("item", 1);
$this->assert_equal($parent->id, $album->parent()->id);
}
public function parents_test() {
- $root = ORM::factory("item", 1);
- $outer = self::create_item_and_add_to_parent($root);
- $inner = self::create_item_and_add_to_parent($outer);
+ $outer = test::random_album();
+ $inner = test::random_album($outer);
$parent_ids = array();
foreach ($inner->parents() as $parent) {
@@ -131,10 +117,9 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function children_test() {
- $root = ORM::factory("item", 1);
- $outer = self::create_item_and_add_to_parent($root);
- $inner1 = self::create_item_and_add_to_parent($outer);
- $inner2 = self::create_item_and_add_to_parent($outer);
+ $outer = test::random_album();
+ $inner1 = test::random_album($outer);
+ $inner2 = test::random_album($outer);
$child_ids = array();
foreach ($outer->children() as $child) {
@@ -144,48 +129,27 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function children_limit_test() {
- $root = ORM::factory("item", 1);
- $outer = self::create_item_and_add_to_parent($root);
- $inner1 = self::create_item_and_add_to_parent($outer);
- $inner2 = self::create_item_and_add_to_parent($outer);
+ $outer = test::random_album();
+ $inner1 = test::random_album($outer);
+ $inner2 = test::random_album($outer);
$this->assert_equal(array($inner2->id => $inner2->name),
$outer->children(1, 1)->select_list('id'));
}
public function children_count_test() {
- $root = ORM::factory("item", 1);
- $outer = self::create_item_and_add_to_parent($root);
- $inner1 = self::create_item_and_add_to_parent($outer);
- $inner2 = self::create_item_and_add_to_parent($outer);
+ $outer = test::random_album();
+ $inner1 = test::random_album($outer);
+ $inner2 = test::random_album($outer);
$this->assert_equal(2, $outer->children_count());
}
public function descendant_test() {
- $root = ORM::factory("item", 1);
-
- $parent = ORM::factory("item");
- $parent->type = "album";
- $parent->rand_key = ((float)mt_rand()) / (float)mt_getrandmax();
- $parent->sort_column = "weight";
- $parent->sort_order = "ASC";
- $parent->add_to_parent($root);
-
- $photo = ORM::factory("item");
- $photo->type = "photo";
- $photo->add_to_parent($parent);
-
- $album1 = ORM::factory("item");
- $album1->type = "album";
- $album1->rand_key = ((float)mt_rand()) / (float)mt_getrandmax();
- $album1->sort_column = "weight";
- $album1->sort_order = "ASC";
- $album1->add_to_parent($parent);
-
- $photo1 = ORM::factory("item");
- $photo1->type = "photo";
- $photo1->add_to_parent($album1);
+ $parent = test::random_album();
+ $photo = test::random_photo($parent);
+ $album1 = test::random_album($parent);
+ $photo1 = test::random_photo($album1);
$parent->reload();
@@ -195,36 +159,20 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function descendant_limit_test() {
- $root = ORM::factory("item", 1);
-
- $parent = self::create_item_and_add_to_parent($root);
- $album1 = self::create_item_and_add_to_parent($parent);
- $album2 = self::create_item_and_add_to_parent($parent);
- $album3 = self::create_item_and_add_to_parent($parent);
-
+ $parent = test::random_album();
+ $album1 = test::random_album($parent);
+ $album2 = test::random_album($parent);
+ $album3 = test::random_album($parent);
$parent->reload();
+
$this->assert_equal(2, $parent->descendants(2)->count());
}
public function descendant_count_test() {
- $root = ORM::factory("item", 1);
-
- $parent = ORM::factory("item");
- $parent->type = "album";
- $parent->add_to_parent($root);
-
- $photo = ORM::factory("item");
- $photo->type = "photo";
- $photo->add_to_parent($parent);
-
- $album1 = ORM::factory("item");
- $album1->type = "album";
- $album1->add_to_parent($parent);
-
- $photo1 = ORM::factory("item");
- $photo1->type = "photo";
- $photo1->add_to_parent($album1);
-
+ $parent = test::random_album();
+ $photo = test::random_photo($parent);
+ $album1 = test::random_album($parent);
+ $photo1 = test::random_photo($album1);
$parent->reload();
$this->assert_equal(3, $parent->descendants_count());
diff --git a/modules/gallery/tests/Photo_Helper_Test.php b/modules/gallery/tests/Photo_Helper_Test.php
deleted file mode 100644
index 97923f90..00000000
--- a/modules/gallery/tests/Photo_Helper_Test.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Photo_Helper_Test extends Unit_Test_Case {
- public function create_photo_test() {
- $rand = rand();
-
- $filename = MODPATH . "gallery/tests/test.jpg";
- $image_info = getimagesize($filename);
-
- $root = ORM::factory("item", 1);
- $photo = photo::create($root, $filename, "$rand.jpg", $rand, $rand);
-
- $this->assert_equal(VARPATH . "albums/$rand.jpg", $photo->file_path());
- $this->assert_equal(VARPATH . "thumbs/{$rand}.jpg", $photo->thumb_path());
- $this->assert_equal(VARPATH . "resizes/{$rand}.jpg", $photo->resize_path());
-
- $this->assert_true(is_file($photo->file_path()), "missing: {$photo->file_path()}");
- $this->assert_true(is_file($photo->resize_path()), "missing: {$photo->resize_path()}");
- $this->assert_true(is_file($photo->thumb_path()), "missing: {$photo->thumb_path()}");
-
- $this->assert_equal($root->id, $photo->parent_id); // MPTT tests cover other hierarchy checks
- $this->assert_equal("$rand.jpg", $photo->name);
- $this->assert_equal($rand, $photo->title);
- $this->assert_equal($rand, $photo->description);
- $this->assert_equal("image/jpeg", $photo->mime_type);
- $this->assert_equal($image_info[0], $photo->width);
- $this->assert_equal($image_info[1], $photo->height);
-
- $this->assert_equal($photo->parent()->right_ptr - 2, $photo->left_ptr);
- $this->assert_equal($photo->parent()->right_ptr - 1, $photo->right_ptr);
- }
-
- public function create_conflicting_photo_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $photo1 = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
- $photo2 = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
- $this->assert_true($photo1->name != $photo2->name);
- }
-
- public function create_photo_with_no_extension_test() {
- $root = ORM::factory("item", 1);
- try {
- photo::create($root, "/tmp", "name", "title", "description");
- $this->assert_false("should fail with an exception");
- } catch (Exception $e) {
- // pass
- }
- }
-
- public function thumb_url_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
- $this->assert_equal("http://./var/thumbs/{$rand}.jpg?m={$photo->updated}", $photo->thumb_url());
- }
-
- public function resize_url_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $photo = photo::create($album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
-
- $this->assert_equal(
- "http://./var/resizes/{$rand}/{$rand}.jpg?m={$photo->updated}", $photo->resize_url());
- }
-
- public function file_url_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $photo = photo::create($album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
-
- $this->assert_equal(
- "http://./var/albums/{$rand}/{$rand}.jpg?m={$photo->updated}", $photo->file_url());
- }
-
- public function create_photo_creates_reasonable_slug_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $album = album::create($root, $rand, $rand, $rand);
- $photo = photo::create(
- $album, MODPATH . "gallery/tests/test.jpg", "This (is) my file%name.jpg", $rand, $rand);
-
- $this->assert_equal("This-is-my-file-name", $photo->slug);
- }
-
- public function create_photo_shouldnt_allow_names_with_slash_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand/.jpg", $rand, $rand);
- } catch (Exception $e) {
- // pass
- return;
- }
-
- $this->assert_true(false, "Shouldn't create a photo with / in the name");
- }
-
- public function create_photo_silently_trims_trailing_periods_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- try {
- $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg.", $rand, $rand);
- } catch (Exception $e) {
- $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage());
- return;
- }
-
- $this->assert_true(false, "Shouldn't create a photo with trailing . in the name");
- }
-}
diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php
index b6c6df47..50d49fcc 100644
--- a/modules/gallery/tests/Photos_Controller_Test.php
+++ b/modules/gallery/tests/Photos_Controller_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Photos_Controller_Test extends Unit_Test_Case {
+class Photos_Controller_Test extends Gallery_Unit_Test_Case {
public function setup() {
$this->_save = array($_POST, $_SERVER);
$_SERVER["HTTP_REFERER"] = "HTTP_REFERER";
@@ -29,19 +29,14 @@ class Photos_Controller_Test extends Unit_Test_Case {
public function change_photo_test() {
$controller = new Photos_Controller();
- $root = ORM::factory("item", 1);
- $photo = photo::create(
- $root, MODPATH . "gallery/tests/test.jpg", "test.jpeg",
- "test", "test", identity::active_user()->id, "slug");
- $orig_name = $photo->name;
+ $photo = test::random_photo();
- $_POST["filename"] = "test.jpeg";
- $_POST["name"] = "new name";
+ $_POST["name"] = "new name.jpg";
$_POST["title"] = "new title";
$_POST["description"] = "new description";
$_POST["slug"] = "new-slug";
$_POST["csrf"] = access::csrf_token();
- access::allow(identity::everybody(), "edit", $root);
+ access::allow(identity::everybody(), "edit", item::root());
ob_start();
$controller->update($photo->id);
@@ -53,26 +48,25 @@ class Photos_Controller_Test extends Unit_Test_Case {
$this->assert_equal("new-slug", $photo->slug);
$this->assert_equal("new title", $photo->title);
$this->assert_equal("new description", $photo->description);
-
- // We don't change the name, yet.
- $this->assert_equal($orig_name, $photo->name);
+ $this->assert_equal("new name.jpg", $photo->name);
}
public function change_photo_no_csrf_fails_test() {
$controller = new Photos_Controller();
- $root = ORM::factory("item", 1);
- $photo = photo::create(
- $root, MODPATH . "gallery/tests/test.jpg", "test.jpg", "test", "test");
- $_POST["name"] = "new name";
+ $photo = test::random_photo();
+
+ $_POST["name"] = "new name.jpg";
$_POST["title"] = "new title";
$_POST["description"] = "new description";
- access::allow(identity::everybody(), "edit", $root);
+ $_POST["slug"] = "new slug";
+ access::allow(identity::everybody(), "edit", item::root());
try {
- $controller->_update($photo);
+ $controller->update($photo);
$this->assert_true(false, "This should fail");
} catch (Exception $e) {
// pass
+ $this->assert_same("@todo FORBIDDEN", $e->getMessage());
}
}
}
diff --git a/modules/gallery/tests/SafeString_Test.php b/modules/gallery/tests/SafeString_Test.php
index 2c07d934..7002a874 100644
--- a/modules/gallery/tests/SafeString_Test.php
+++ b/modules/gallery/tests/SafeString_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class SafeString_Test extends Unit_Test_Case {
+class SafeString_Test extends Gallery_Unit_Test_Case {
public function toString_escapes_for_html_test() {
$safe_string = new SafeString("hello <p>world</p>");
$this->assert_equal("hello &lt;p&gt;world&lt;/p&gt;",
diff --git a/modules/gallery/tests/Sendmail_Test.php b/modules/gallery/tests/Sendmail_Test.php
index f3a8d897..bc57e434 100644
--- a/modules/gallery/tests/Sendmail_Test.php
+++ b/modules/gallery/tests/Sendmail_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Sendmail_Test extends Unit_Test_Case {
+class Sendmail_Test extends Gallery_Unit_Test_Case {
public function setup() {
Kohana_Config::instance()->set("sendmail.from", "from@gallery3.com");
}
diff --git a/modules/gallery/tests/Url_Security_Test.php b/modules/gallery/tests/Url_Security_Test.php
index de25880f..255b3909 100644
--- a/modules/gallery/tests/Url_Security_Test.php
+++ b/modules/gallery/tests/Url_Security_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Url_Security_Test extends Unit_Test_Case {
+class Url_Security_Test extends Gallery_Unit_Test_Case {
public function setup() {
$this->save = array(Router::$current_uri, Router::$complete_uri, $_GET);
}
diff --git a/modules/gallery/tests/Var_Test.php b/modules/gallery/tests/Var_Test.php
index 355d94a7..fb19da7a 100644
--- a/modules/gallery/tests/Var_Test.php
+++ b/modules/gallery/tests/Var_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Var_Test extends Unit_Test_Case {
+class Var_Test extends Gallery_Unit_Test_Case {
public function add_parameter_test() {
module::set_var("gallery", "Parameter", "original value");
$this->assert_equal("original value", module::get_var("gallery", "Parameter"));
diff --git a/modules/gallery/tests/Xss_Security_Test.php b/modules/gallery/tests/Xss_Security_Test.php
index b296d97c..a39a069d 100644
--- a/modules/gallery/tests/Xss_Security_Test.php
+++ b/modules/gallery/tests/Xss_Security_Test.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Xss_Security_Test extends Unit_Test_Case {
+class Xss_Security_Test extends Gallery_Unit_Test_Case {
public function find_unescaped_variables_in_views_test() {
$found = array();
foreach (glob("*/*/views/*.php") as $view) {
diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt
index da7108d8..0aa26057 100644
--- a/modules/gallery/tests/controller_auth_data.txt
+++ b/modules/gallery/tests/controller_auth_data.txt
@@ -19,12 +19,12 @@ modules/gallery/controllers/quick.php form_edit
modules/gallery/controllers/simple_uploader.php start DIRTY_AUTH
modules/gallery/controllers/simple_uploader.php finish DIRTY_AUTH
modules/gallery/controllers/upgrader.php index DIRTY_AUTH
-modules/gallery/controllers/user_profile.php show DIRTY_CSRF|DIRTY_AUTH
+modules/gallery/controllers/user_profile.php show DIRTY_AUTH
modules/gallery/controllers/user_profile.php contact DIRTY_AUTH
modules/gallery/controllers/user_profile.php send DIRTY_AUTH
modules/gallery/controllers/welcome_message.php index DIRTY_AUTH
-modules/rest/controllers/rest.php access_key DIRTY_CSRF|DIRTY_AUTH
-modules/rest/controllers/rest.php __call DIRTY_AUTH
+modules/rest/controllers/rest.php index DIRTY_CSRF|DIRTY_AUTH
+modules/rest/controllers/rest.php __call DIRTY_CSRF|DIRTY_AUTH
modules/rss/controllers/rss.php feed DIRTY_CSRF|DIRTY_AUTH
modules/search/controllers/search.php index DIRTY_CSRF|DIRTY_AUTH
modules/server_add/controllers/admin_server_add.php autocomplete DIRTY_CSRF