summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/controllers/welcome.php6
-rw-r--r--core/helpers/album.php13
-rw-r--r--core/helpers/photo.php15
-rw-r--r--core/tests/Access_Helper_Test.php26
-rw-r--r--core/tests/Album_Helper_Test.php14
-rw-r--r--core/tests/Items_Controller_Test.php6
-rw-r--r--core/tests/ORM_MPTT_Test.php11
-rw-r--r--core/tests/Photo_Helper_Test.php21
-rw-r--r--core/tests/Var_Test.php9
9 files changed, 62 insertions, 59 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index c9415c57..082dd390 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -201,7 +201,7 @@ class Welcome_Controller extends Template_Controller {
$photo_count = 0;
foreach (glob("$path/*.[Jj][Pp][Gg]") as $file) {
set_time_limit(30);
- photo::create($parent->id, $file, basename($file), basename($file));
+ photo::create($parent, $file, basename($file), basename($file));
$photo_count++;
}
@@ -232,12 +232,12 @@ class Welcome_Controller extends Template_Controller {
if ($type == "album") {
$thumb_size = module::get_var("core", "thumb_size");
$parents[] = album::create(
- $parent->id, "rnd_" . rand(), "Rnd $i", "random album $i", $owner_id)
+ $parent, "rnd_" . rand(), "Rnd $i", "random album $i", $owner_id)
->save();
$album_count++;
} else {
$photo_index = rand(0, count($test_images) - 1);
- photo::create($parent->id, $test_images[$photo_index], basename($test_images[$photo_index]),
+ photo::create($parent, $test_images[$photo_index], basename($test_images[$photo_index]),
"rnd_" . rand(), "sample thumb", $owner_id);
$photo_count++;
}
diff --git a/core/helpers/album.php b/core/helpers/album.php
index 53af0079..70b05006 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -32,7 +32,11 @@ class album_Core {
* @param string $description (optional) the longer description of this album
* @return Item_Model
*/
- static function create($parent_id, $name, $title, $description=null, $owner_id=null) {
+ static function create($parent, $name, $title, $description=null, $owner_id=null) {
+ if (!$parent->loaded || $parent->type != "album") {
+ throw new Exception("@todo INVALID_PARENT");
+ }
+
$album = ORM::factory("item");
$album->type = "album";
$album->title = $title;
@@ -43,17 +47,12 @@ class album_Core {
$album->resize_dirty = 1;
while (ORM::factory("item")
- ->where("parent_id", $parent_id)
+ ->where("parent_id", $parent->id)
->where("name", $album->name)
->find()->id) {
$album->name = "{$name}-" . rand();
}
- $parent = ORM::factory("item", $parent_id);
- if (!$parent->loaded) {
- throw new Exception("@todo INVALID_PARENT_ID");
- }
-
$album = $album->add_to_parent($parent);
mkdir($album->file_path());
mkdir(dirname($album->thumb_path()));
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index 8c826e1c..d8fc2595 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -33,7 +33,11 @@ class photo_Core {
* @param string $description (optional) the longer description of this photo
* @return Item_Model
*/
- static function create($parent_id, $filename, $name, $title, $description=null, $owner_id=null) {
+ static function create($parent, $filename, $name, $title, $description=null, $owner_id=null) {
+ if (!$parent->loaded || $parent->type != "album") {
+ throw new Exception("@todo INVALID_PARENT");
+ }
+
if (!is_file($filename)) {
throw new Exception("@todo MISSING_IMAGE_FILE");
}
@@ -63,7 +67,7 @@ class photo_Core {
// Randomize the name if there's a conflict
while (ORM::Factory("item")
- ->where("parent_id", $parent_id)
+ ->where("parent_id", $parent->id)
->where("name", $photo->name)
->find()->id) {
// @todo Improve this. Random numbers are not user friendly
@@ -71,11 +75,6 @@ class photo_Core {
}
// This saves the photo
- $parent = ORM::factory("item", $parent_id);
- if (!$parent->loaded) {
- throw new Exception("@todo INVALID_PARENT_ID");
- }
-
$photo->add_to_parent($parent);
copy($filename, $photo->file_path());
@@ -91,6 +90,8 @@ class photo_Core {
$parent->save();
graphics::generate($parent);
}
+
+ return $photo;
}
static function get_add_form($parent) {
diff --git a/core/tests/Access_Helper_Test.php b/core/tests/Access_Helper_Test.php
index 3141078d..6177723b 100644
--- a/core/tests/Access_Helper_Test.php
+++ b/core/tests/Access_Helper_Test.php
@@ -84,7 +84,7 @@ 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->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
access::allow(group::everybody(), "view", $album);
$photo = ORM::factory("item");
@@ -97,7 +97,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function can_allow_deny_and_reset_intent_test() {
$root = ORM::factory("item", 1);
- $album = album::create($root->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
$intent = ORM::factory("access_intent")->where("item_id", $album)->find();
// Allow
@@ -149,7 +149,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function cant_view_child_of_hidden_parent_test() {
$root = ORM::factory("item", 1);
- $album = album::create($root->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
$root->reload();
access::deny(group::everybody(), "view", $root);
@@ -161,7 +161,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function view_permissions_propagate_down_test() {
$root = ORM::factory("item", 1);
- $album = album::create($root->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
access::allow(group::everybody(), "view", $root);
access::reset(group::everybody(), "view", $album);
@@ -171,10 +171,10 @@ class Access_Helper_Test extends Unit_Test_Case {
public function can_toggle_view_permissions_propagate_down_test() {
$root = ORM::factory("item", 1);
- $album1 = album::create($root->id, rand(), "test album");
- $album2 = album::create($album1->id, rand(), "test album");
- $album3 = album::create($album2->id, rand(), "test album");
- $album4 = album::create($album3->id, rand(), "test album");
+ $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->reload();
$album2->reload();
@@ -197,7 +197,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function revoked_view_permissions_cant_be_allowed_lower_down_test() {
$root = ORM::factory("item", 1);
- $album = album::create($root->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
$root->reload();
access::deny(group::everybody(), "view", $root);
@@ -215,7 +215,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function non_view_permissions_propagate_down_test() {
$root = ORM::factory("item", 1);
- $album = album::create($root->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
access::allow(group::everybody(), "edit", $root);
access::reset(group::everybody(), "edit", $album);
@@ -224,11 +224,11 @@ class Access_Helper_Test extends Unit_Test_Case {
public function non_view_permissions_can_be_revoked_lower_down_test() {
$root = ORM::factory("item", 1);
- $outer = album::create($root->id, rand(), "test album");
+ $outer = album::create($root, rand(), "test album");
$outer_photo = ORM::factory("item")->add_to_parent($outer);
access::add_item($outer_photo);
- $inner = album::create($outer->id, rand(), "test album");
+ $inner = album::create($outer, rand(), "test album");
$inner_photo = ORM::factory("item")->add_to_parent($inner);
access::add_item($inner_photo);
@@ -272,7 +272,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->id, rand(), "test album");
+ $album = album::create($root, rand(), "test album");
$this->assert_false(file_exists($album->file_path() . "/.htaccess"));
diff --git a/core/tests/Album_Helper_Test.php b/core/tests/Album_Helper_Test.php
index 1d9388d9..d085ca88 100644
--- a/core/tests/Album_Helper_Test.php
+++ b/core/tests/Album_Helper_Test.php
@@ -20,7 +20,8 @@
class Album_Helper_Test extends Unit_Test_Case {
public function create_album_test() {
$rand = rand();
- $album = album::create(1, $rand, $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());
@@ -38,20 +39,23 @@ class Album_Helper_Test extends Unit_Test_Case {
public function create_conflicting_album_test() {
$rand = rand();
- $album1 = album::create(1, $rand, $rand, $rand);
- $album2 = album::create(1, $rand, $rand, $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();
- $album = album::create(1, $rand, $rand, $rand);
+ $root = ORM::factory("item", 1);
+ $album = album::create($root, $rand, $rand, $rand);
$this->assert_equal("http://./var/thumbs/$rand/.album.jpg", $album->thumb_url());
}
public function resize_url_test() {
$rand = rand();
- $album = album::create(1, $rand, $rand, $rand);
+ $root = ORM::factory("item", 1);
+ $album = album::create($root, $rand, $rand, $rand);
$this->assert_equal("http://./var/resizes/$rand/.album.jpg", $album->resize_url());
}
}
diff --git a/core/tests/Items_Controller_Test.php b/core/tests/Items_Controller_Test.php
index 784177b5..85ff3e03 100644
--- a/core/tests/Items_Controller_Test.php
+++ b/core/tests/Items_Controller_Test.php
@@ -20,7 +20,8 @@
class Items_Controller_Test extends Unit_Test_Case {
public function change_item_test() {
$controller = new Items_Controller();
- $album = album::create(1, "test", "test");
+ $root = ORM::factory("item", 1);
+ $album = album::create($root, "test", "test");
$_POST["title"] = "new title";
$_POST["description"] = "new description";
@@ -31,7 +32,8 @@ class Items_Controller_Test extends Unit_Test_Case {
public function change_item_test_with_return() {
$controller = new Items_Controller();
- $album = album::create(1, "test", "test");
+ $root = ORM::factory("item", 1);
+ $album = album::create($root, "test", "test");
$_POST["title"] = "item_title";
$_POST["description"] = "item_description";
$_POST["__return"] = "item_description";
diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php
index b969e287..36f1d78b 100644
--- a/core/tests/ORM_MPTT_Test.php
+++ b/core/tests/ORM_MPTT_Test.php
@@ -59,11 +59,12 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function move_to_test() {
- $album1 = album::create(1, "move_to_test_1", "move_to_test_1");
- $album1_1 = album::create($album1->id, "move_to_test_1_1", "move_to_test_1_1");
- $album1_2 = album::create($album1->id, "move_to_test_1_2", "move_to_test_1_2");
- $album1_1_1 = album::create($album1_1->id, "move_to_test_1_1_1", "move_to_test_1_1_1");
- $album1_1_2 = album::create($album1_1->id, "move_to_test_1_1_2", "move_to_test_1_1_2");
+ $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_2->reload();
$album1_1_1->reload();
diff --git a/core/tests/Photo_Helper_Test.php b/core/tests/Photo_Helper_Test.php
index f31509a3..2219a846 100644
--- a/core/tests/Photo_Helper_Test.php
+++ b/core/tests/Photo_Helper_Test.php
@@ -24,7 +24,8 @@ class Photo_Helper_Test extends Unit_Test_Case {
$filename = DOCROOT . "core/tests/test.jpg";
$image_info = getimagesize($filename);
- $photo = photo::create(1, $filename, "$rand.jpg", $rand, $rand);
+ $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());
@@ -34,7 +35,7 @@ class Photo_Helper_Test extends Unit_Test_Case {
$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(1, $photo->parent_id); // MPTT tests will cover other hierarchy checks
+ $this->assert_equal($root, $photo->parent_id); // MPTT tests will cover other hierarchy checks
$this->assert_equal("$rand.jpg", $photo->name);
$this->assert_equal($rand, $photo->title);
$this->assert_equal($rand, $photo->description);
@@ -48,14 +49,16 @@ class Photo_Helper_Test extends Unit_Test_Case {
public function create_conflicting_photo_test() {
$rand = rand();
- $photo1 = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
- $photo2 = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $root = ORM::factory("item", 1);
+ $photo1 = photo::create($root, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $photo2 = photo::create($root, DOCROOT . "core/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(1, "/tmp", "name", "title", "description");
+ photo::create($root, "/tmp", "name", "title", "description");
$this->assert_false("should fail with an exception");
} catch (Exception $e) {
// pass
@@ -64,14 +67,16 @@ class Photo_Helper_Test extends Unit_Test_Case {
public function thumb_url_test() {
$rand = rand();
- $photo = photo::create(1, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $root = ORM::factory("item", 1);
+ $photo = photo::create($root, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
$this->assert_equal("http://./var/thumbs/{$rand}.jpg", $photo->thumb_url());
}
public function resize_url_test() {
$rand = rand();
- $album = album::create(1, $rand, $rand, $rand);
- $photo = photo::create($album->id, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
+ $root = ORM::factory("item", 1);
+ $album = album::create($root, $rand, $rand, $rand);
+ $photo = photo::create($album, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand);
$this->assert_equal("http://./var/resizes/{$rand}/{$rand}.jpg", $photo->resize_url());
}
diff --git a/core/tests/Var_Test.php b/core/tests/Var_Test.php
index 272a39fa..e186a7c2 100644
--- a/core/tests/Var_Test.php
+++ b/core/tests/Var_Test.php
@@ -24,14 +24,5 @@ class Var_Test extends Unit_Test_Case {
module::set_var("core", "Parameter", "updated value");
$this->assert_equal("updated value", module::get_var("core", "Parameter"));
-
- module::set_var("core", "Parameter2", "new parameter");
- $core = module::get("core");
-
- $params = $core->vars->select_list("name", "value");
- $this->assert_false(empty($params["Parameter"]));
- $this->assert_equal("updated value", $params["Parameter"]);
- $this->assert_false(empty($params["Parameter2"]));
- $this->assert_equal("new parameter", $params["Parameter2"]);
}
} \ No newline at end of file