2008-12-20 22:49:32 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2012-02-27 09:46:39 -08:00
|
|
|
* Copyright (C) 2000-2012 Bharat Mediratta
|
2008-12-20 22:49:32 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2010-01-19 22:38:19 -08:00
|
|
|
class Item_Model_Test extends Gallery_Unit_Test_Case {
|
2010-06-08 20:59:24 -07:00
|
|
|
public function teardown() {
|
|
|
|
|
identity::set_active_user(identity::admin_user());
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-20 22:49:32 +00:00
|
|
|
public function saving_sets_created_and_updated_dates_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
2008-12-20 22:49:32 +00:00
|
|
|
$this->assert_true(!empty($item->created));
|
|
|
|
|
$this->assert_true(!empty($item->updated));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-11 05:19:09 +00:00
|
|
|
public function updating_doesnt_change_created_date_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
2008-12-20 22:49:32 +00:00
|
|
|
|
|
|
|
|
// Force the creation date to something well known
|
2009-12-21 11:30:34 -08:00
|
|
|
db::build()
|
|
|
|
|
->update("items")
|
|
|
|
|
->set("created", 0)
|
|
|
|
|
->set("updated", 0)
|
|
|
|
|
->where("id", "=", $item->id)
|
|
|
|
|
->execute();
|
2008-12-20 22:49:32 +00:00
|
|
|
$item->reload();
|
|
|
|
|
$item->title = "foo"; // force a change
|
|
|
|
|
$item->save();
|
|
|
|
|
|
|
|
|
|
$this->assert_true(empty($item->created));
|
|
|
|
|
$this->assert_true(!empty($item->updated));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updating_view_count_only_doesnt_change_updated_date_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
2008-12-20 22:49:32 +00:00
|
|
|
$item->reload();
|
2010-01-18 12:37:20 -08:00
|
|
|
$this->assert_equal(0, $item->view_count);
|
2008-12-20 22:49:32 +00:00
|
|
|
|
|
|
|
|
// Force the updated date to something well known
|
2009-12-21 11:30:34 -08:00
|
|
|
db::build()
|
|
|
|
|
->update("items")
|
|
|
|
|
->set("updated", 0)
|
|
|
|
|
->where("id", "=", $item->id)
|
|
|
|
|
->execute();
|
2008-12-20 22:49:32 +00:00
|
|
|
$item->reload();
|
|
|
|
|
$item->view_count++;
|
|
|
|
|
$item->save();
|
|
|
|
|
|
|
|
|
|
$this->assert_same(1, $item->view_count);
|
|
|
|
|
$this->assert_true(empty($item->updated));
|
|
|
|
|
}
|
2009-05-16 03:29:14 +00:00
|
|
|
|
2009-10-24 10:08:48 -07:00
|
|
|
public function rename_photo_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
2010-01-18 20:14:09 -08:00
|
|
|
$original_name = $item->name;
|
2009-05-16 03:29:14 +00:00
|
|
|
|
|
|
|
|
file_put_contents($item->thumb_path(), "thumb");
|
|
|
|
|
file_put_contents($item->resize_path(), "resize");
|
|
|
|
|
file_put_contents($item->file_path(), "file");
|
|
|
|
|
|
|
|
|
|
// Now rename it
|
2010-01-18 20:14:09 -08:00
|
|
|
$item->name = ($new_name = test::random_name($item));
|
2010-01-17 20:54:08 -08:00
|
|
|
$item->save();
|
2009-05-16 03:29:14 +00:00
|
|
|
|
|
|
|
|
// Expected: the name changed, the name is now baked into all paths, and all files were moved.
|
|
|
|
|
$this->assert_equal($new_name, $item->name);
|
|
|
|
|
$this->assert_equal($new_name, basename($item->file_path()));
|
|
|
|
|
$this->assert_equal($new_name, basename($item->thumb_path()));
|
|
|
|
|
$this->assert_equal($new_name, basename($item->resize_path()));
|
|
|
|
|
$this->assert_equal("thumb", file_get_contents($item->thumb_path()));
|
|
|
|
|
$this->assert_equal("resize", file_get_contents($item->resize_path()));
|
|
|
|
|
$this->assert_equal("file", file_get_contents($item->file_path()));
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-24 10:08:48 -07:00
|
|
|
public function rename_album_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$album = test::random_album();
|
|
|
|
|
$photo = test::random_photo($album);
|
2010-01-17 21:03:15 -08:00
|
|
|
$album->reload();
|
2009-05-16 03:29:14 +00:00
|
|
|
|
|
|
|
|
file_put_contents($photo->thumb_path(), "thumb");
|
|
|
|
|
file_put_contents($photo->resize_path(), "resize");
|
|
|
|
|
file_put_contents($photo->file_path(), "file");
|
|
|
|
|
|
|
|
|
|
$original_album_name = $album->name;
|
|
|
|
|
$original_photo_name = $photo->name;
|
2010-01-18 20:14:09 -08:00
|
|
|
$new_album_name = test::random_name();
|
2009-05-16 03:29:14 +00:00
|
|
|
|
|
|
|
|
// Now rename the album
|
2010-01-17 21:03:15 -08:00
|
|
|
$album->name = $new_album_name;
|
|
|
|
|
$album->save();
|
2009-05-16 03:29:14 +00:00
|
|
|
$photo->reload();
|
|
|
|
|
|
|
|
|
|
// Expected:
|
|
|
|
|
// * the album name changed.
|
|
|
|
|
// * the album dirs are all moved
|
|
|
|
|
// * the photo's paths are all inside the albums paths
|
|
|
|
|
// * the photo files are all still intact and accessible
|
|
|
|
|
$this->assert_equal($new_album_name, $album->name);
|
|
|
|
|
$this->assert_equal($new_album_name, basename($album->file_path()));
|
|
|
|
|
$this->assert_equal($new_album_name, basename(dirname($album->thumb_path())));
|
|
|
|
|
$this->assert_equal($new_album_name, basename(dirname($album->resize_path())));
|
|
|
|
|
|
2010-01-18 22:55:16 -08:00
|
|
|
$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())));
|
2009-05-16 03:29:14 +00:00
|
|
|
|
|
|
|
|
$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()));
|
|
|
|
|
}
|
2009-05-16 03:37:14 +00:00
|
|
|
|
|
|
|
|
public function item_rename_wont_accept_slash_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
2009-05-16 03:37:14 +00:00
|
|
|
try {
|
2010-01-18 22:51:40 -08:00
|
|
|
$item->name = test::random_name() . "/";
|
|
|
|
|
$item->save();
|
2010-01-18 21:12:26 -08:00
|
|
|
} catch (ORM_Validation_Exception $e) {
|
2010-01-18 22:51:40 -08:00
|
|
|
$this->assert_equal(array("name" => "no_slashes"), $e->validation->errors());
|
|
|
|
|
return;
|
2009-05-16 03:37:14 +00:00
|
|
|
}
|
2010-01-18 22:51:40 -08:00
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
2009-05-16 03:37:14 +00:00
|
|
|
}
|
2009-07-16 11:19:34 -07:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
public function item_rename_over_existing_name_gets_uniqified_test() {
|
2009-10-24 10:08:48 -07:00
|
|
|
// Create a test photo
|
2010-01-17 20:53:32 -08:00
|
|
|
$item = test::random_photo();
|
|
|
|
|
$item2 = test::random_photo();
|
2009-10-24 10:08:48 -07:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
$item->name = $item2->name;
|
|
|
|
|
$item->save();
|
2010-01-17 21:49:48 -08:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
// foo.jpg should become foo-####.jpg
|
|
|
|
|
$this->assert_true(
|
|
|
|
|
preg_match("/" . str_replace(".jpg", "", $item2->name) . "-\d+\.jpg/", $item->name));
|
2009-10-24 10:08:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function move_album_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$album2 = test::random_album();
|
2010-01-18 22:51:40 -08:00
|
|
|
$album1 = test::random_album($album2);
|
|
|
|
|
$photo = test::random_photo($album1);
|
2009-10-24 10:08:48 -07:00
|
|
|
|
|
|
|
|
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
|
2010-01-18 22:51:40 -08:00
|
|
|
$album1->parent_id = item::root()->id;
|
|
|
|
|
$album1->save();
|
2009-10-24 10:08:48 -07:00
|
|
|
$photo->reload();
|
|
|
|
|
|
|
|
|
|
// Expected:
|
2010-01-18 21:12:26 -08:00
|
|
|
// * album is not inside album2 anymore
|
2009-10-24 10:08:48 -07:00
|
|
|
// * the photo's paths are all inside the albums paths
|
|
|
|
|
// * the photo files are all still intact and accessible
|
|
|
|
|
|
2010-01-18 22:51:40 -08:00
|
|
|
$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())));
|
2009-10-24 10:08:48 -07:00
|
|
|
|
|
|
|
|
$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_photo_test() {
|
2010-01-18 21:12:26 -08:00
|
|
|
$album1 = test::random_album();
|
|
|
|
|
$photo = test::random_photo($album1);
|
|
|
|
|
|
2010-01-17 20:53:32 -08:00
|
|
|
$album2 = test::random_album();
|
2009-10-24 10:08:48 -07:00
|
|
|
|
|
|
|
|
file_put_contents($photo->thumb_path(), "thumb");
|
|
|
|
|
file_put_contents($photo->resize_path(), "resize");
|
|
|
|
|
file_put_contents($photo->file_path(), "file");
|
|
|
|
|
|
2010-01-18 21:12:26 -08:00
|
|
|
// Now move the photo
|
|
|
|
|
$photo->parent_id = $album2->id;
|
|
|
|
|
$photo->save();
|
2009-10-24 10:08:48 -07:00
|
|
|
|
|
|
|
|
// Expected:
|
2010-01-18 21:12:26 -08:00
|
|
|
// * the photo's paths are inside the album2 not album1
|
2009-10-24 10:08:48 -07:00
|
|
|
// * the photo files are all still intact and accessible
|
|
|
|
|
|
2010-01-18 22:55:16 -08:00
|
|
|
$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())));
|
2009-10-24 10:08:48 -07:00
|
|
|
|
|
|
|
|
$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()));
|
|
|
|
|
}
|
2009-11-06 23:19:48 -08:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
public function move_album_with_conflicting_target_gets_uniqified_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$album = test::random_album();
|
2010-01-18 21:12:26 -08:00
|
|
|
$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
|
2010-09-11 23:37:12 -07:00
|
|
|
// conflict and get randomized
|
2009-10-24 10:08:48 -07:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
$source->parent_id = item::root()->id;
|
|
|
|
|
$source->save();
|
|
|
|
|
|
|
|
|
|
// foo should become foo-####
|
|
|
|
|
$this->assert_true(preg_match("/{$album->name}-\d+/", $source->name));
|
|
|
|
|
$this->assert_true(preg_match("/{$album->slug}-\d+/", $source->slug));
|
2009-10-24 10:08:48 -07:00
|
|
|
}
|
|
|
|
|
|
2010-01-18 21:14:43 -08:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$album->parent_id = $photo->id;
|
|
|
|
|
$album->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors());
|
2010-01-18 22:51:40 -08:00
|
|
|
return;
|
2010-01-18 21:14:43 -08:00
|
|
|
}
|
2010-01-18 22:51:40 -08:00
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
2010-01-18 21:14:43 -08:00
|
|
|
}
|
|
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
public function move_photo_with_conflicting_target_gets_uniqified_test() {
|
2010-01-17 20:53:32 -08:00
|
|
|
$photo1 = test::random_photo();
|
|
|
|
|
$album = test::random_album();
|
2010-01-18 21:12:26 -08:00
|
|
|
$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
|
2010-09-11 23:37:12 -07:00
|
|
|
// conflict and get uniqified.
|
2009-10-24 10:08:48 -07:00
|
|
|
|
2010-09-11 23:37:12 -07:00
|
|
|
$photo2->parent_id = item::root()->id;
|
|
|
|
|
$photo2->save();
|
|
|
|
|
|
|
|
|
|
// foo.jpg should become foo-####.jpg
|
|
|
|
|
$this->assert_true(
|
|
|
|
|
preg_match("/" . str_replace(".jpg", "", $photo1->name) . "-\d+\.jpg/", $photo2->name));
|
|
|
|
|
|
|
|
|
|
// foo should become foo
|
|
|
|
|
$this->assert_true(preg_match("/{$photo1->slug}/", $photo2->name));
|
2009-10-24 10:08:48 -07:00
|
|
|
}
|
2010-01-17 23:45:18 -08:00
|
|
|
|
2010-01-18 21:12:26 -08:00
|
|
|
public function move_album_inside_descendent_fails_test() {
|
2010-01-18 22:51:40 -08:00
|
|
|
$album1 = test::random_album();
|
|
|
|
|
$album2 = test::random_album($album1);
|
2010-01-18 21:12:26 -08:00
|
|
|
$album3 = test::random_album($album2);
|
|
|
|
|
|
|
|
|
|
try {
|
2010-01-18 22:51:40 -08:00
|
|
|
$album1->parent_id = $album3->id;
|
|
|
|
|
$album1->save();
|
2010-01-18 21:12:26 -08:00
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors());
|
2010-01-18 22:51:40 -08:00
|
|
|
return;
|
2010-01-18 21:12:26 -08:00
|
|
|
}
|
2010-01-18 22:51:40 -08:00
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
2010-01-18 21:12:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-17 23:45:18 -08:00
|
|
|
public function basic_validation_test() {
|
|
|
|
|
$item = ORM::factory("item");
|
2010-12-15 14:57:00 -08:00
|
|
|
$item->album_cover_item_id = random::int(); // invalid
|
2010-01-17 23:45:18 -08:00
|
|
|
$item->description = str_repeat("x", 70000); // invalid
|
|
|
|
|
$item->name = null;
|
2010-12-15 14:57:00 -08:00
|
|
|
$item->parent_id = random::int();
|
2010-01-17 23:45:18 -08:00
|
|
|
$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",
|
|
|
|
|
"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");
|
|
|
|
|
}
|
2010-01-18 23:38:39 -08:00
|
|
|
|
|
|
|
|
public function slug_is_url_safe_test() {
|
|
|
|
|
try {
|
2010-01-19 21:20:36 -08:00
|
|
|
$album = test::random_album_unsaved();
|
2010-01-18 23:38:39 -08:00
|
|
|
$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();
|
|
|
|
|
}
|
2010-01-19 21:20:36 -08:00
|
|
|
|
2010-04-04 14:27:39 -07:00
|
|
|
public function name_with_only_invalid_chars_is_still_valid_test() {
|
|
|
|
|
$album = test::random_album_unsaved();
|
|
|
|
|
$album->name = "[]";
|
|
|
|
|
$album->save();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-19 21:20:36 -08:00
|
|
|
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) {
|
2012-05-05 18:52:44 -07:00
|
|
|
$this->assert_same(
|
|
|
|
|
array("name" => "illegal_data_file_extension", "type" => "read_only"),
|
|
|
|
|
$e->validation->errors());
|
|
|
|
|
return; // pass
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function photo_files_must_have_an_extension_test() {
|
|
|
|
|
try {
|
|
|
|
|
$photo = test::random_photo_unsaved();
|
|
|
|
|
$photo->mime_type = "image/jpeg";
|
|
|
|
|
$photo->name = "no_extension";
|
|
|
|
|
$photo->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_same(array("name" => "illegal_data_file_extension"), $e->validation->errors());
|
|
|
|
|
return; // pass
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function movie_files_must_have_an_extension_test() {
|
|
|
|
|
try {
|
|
|
|
|
$movie = test::random_photo_unsaved();
|
|
|
|
|
$movie->type = "movie";
|
|
|
|
|
$movie->mime_type = "video/x-flv";
|
|
|
|
|
$movie->name = "no_extension";
|
|
|
|
|
$movie->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_same(array("name" => "illegal_data_file_extension"), $e->validation->errors());
|
2010-01-19 21:20:36 -08:00
|
|
|
return; // pass
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
2010-01-27 21:52:18 -08:00
|
|
|
|
|
|
|
|
public function cant_delete_root_album_test() {
|
|
|
|
|
try {
|
|
|
|
|
item::root()->delete();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_same(array("id" => "cant_delete_root_album"), $e->validation->errors());
|
|
|
|
|
return; // pass
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
2010-01-30 23:36:11 -08:00
|
|
|
|
|
|
|
|
public function as_restful_array_test() {
|
|
|
|
|
$album = test::random_album();
|
|
|
|
|
$photo = test::random_photo($album);
|
|
|
|
|
$album->reload();
|
|
|
|
|
|
2010-06-09 20:49:32 -07:00
|
|
|
$result = $album->as_restful_array();
|
2010-01-30 23:36:11 -08:00
|
|
|
$this->assert_same(rest::url("item", item::root()), $result["parent"]);
|
|
|
|
|
$this->assert_same(rest::url("item", $photo), $result["album_cover"]);
|
|
|
|
|
$this->assert_true(!array_key_exists("parent_id", $result));
|
|
|
|
|
$this->assert_true(!array_key_exists("album_cover_item_id", $result));
|
|
|
|
|
}
|
2010-05-10 22:11:59 -07:00
|
|
|
|
2010-06-08 20:59:24 -07:00
|
|
|
public function as_restful_array_with_edit_bit_test() {
|
2010-12-28 22:00:25 -08:00
|
|
|
$response = item::root()->as_restful_array();
|
2010-06-08 20:59:24 -07:00
|
|
|
$this->assert_true($response["can_edit"]);
|
|
|
|
|
|
|
|
|
|
identity::set_active_user(identity::guest());
|
2010-12-28 22:00:25 -08:00
|
|
|
$response = item::root()->as_restful_array();
|
2010-06-08 20:59:24 -07:00
|
|
|
$this->assert_false($response["can_edit"]);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-10 22:11:59 -07:00
|
|
|
public function first_photo_becomes_album_cover() {
|
|
|
|
|
$album = test::random_album();
|
|
|
|
|
$photo = test::random_photo($album);
|
|
|
|
|
$album->reload();
|
|
|
|
|
|
|
|
|
|
$this->assert_same($photo->id, $album->album_cover_item_id);
|
|
|
|
|
}
|
2010-08-07 22:18:28 -07:00
|
|
|
|
|
|
|
|
public function replace_data_file_test() {
|
|
|
|
|
// Random photo is modules/gallery/tests/test.jpg which is 1024x768 and 6232 bytes.
|
|
|
|
|
$photo = test::random_photo();
|
|
|
|
|
$this->assert_equal(1024, $photo->width);
|
|
|
|
|
$this->assert_equal(768, $photo->height);
|
|
|
|
|
$this->assert_equal(6232, filesize($photo->file_path()));
|
|
|
|
|
|
|
|
|
|
// Random photo is gallery/images/imagemagick.jpg is 114x118 and 20337 bytes
|
|
|
|
|
$photo->set_data_file(MODPATH . "gallery/images/imagemagick.jpg");
|
|
|
|
|
$photo->save();
|
|
|
|
|
|
|
|
|
|
$this->assert_equal(114, $photo->width);
|
|
|
|
|
$this->assert_equal(118, $photo->height);
|
|
|
|
|
$this->assert_equal(20337, filesize($photo->file_path()));
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 01:12:26 -06:00
|
|
|
public function replace_data_file_type_test() {
|
2010-08-07 22:18:28 -07:00
|
|
|
// Random photo is modules/gallery/tests/test.jpg
|
|
|
|
|
$photo = test::random_photo();
|
2011-07-21 01:12:26 -06:00
|
|
|
$this->assert_equal(1024, $photo->width);
|
|
|
|
|
$this->assert_equal(768, $photo->height);
|
|
|
|
|
$this->assert_equal(6232, filesize($photo->file_path()));
|
|
|
|
|
$this->assert_equal("image/jpeg", $photo->mime_type);
|
|
|
|
|
$orig_name = $photo->name;
|
|
|
|
|
|
|
|
|
|
// Random photo is gallery/images/graphicsmagick.png is 104x76 and 1486 bytes
|
2010-08-07 22:18:28 -07:00
|
|
|
$photo->set_data_file(MODPATH . "gallery/images/graphicsmagick.png");
|
2011-07-21 01:12:26 -06:00
|
|
|
$photo->save();
|
|
|
|
|
|
|
|
|
|
$this->assert_equal(104, $photo->width);
|
|
|
|
|
$this->assert_equal(76, $photo->height);
|
|
|
|
|
$this->assert_equal(1486, filesize($photo->file_path()));
|
|
|
|
|
$this->assert_equal("image/png", $photo->mime_type);
|
|
|
|
|
$this->assert_equal("png", pathinfo($photo->name, PATHINFO_EXTENSION));
|
|
|
|
|
$this->assert_equal(pathinfo($orig_name, PATHINFO_FILENAME), pathinfo($photo->name, PATHINFO_FILENAME));
|
|
|
|
|
}
|
2010-08-07 22:18:28 -07:00
|
|
|
|
2011-07-21 01:12:26 -06:00
|
|
|
public function unsafe_data_file_replacement_test() {
|
2010-08-07 22:18:28 -07:00
|
|
|
try {
|
2011-07-21 01:12:26 -06:00
|
|
|
$photo = test::random_photo();
|
|
|
|
|
$photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php");
|
2010-08-07 22:18:28 -07:00
|
|
|
$photo->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
2012-05-05 18:52:44 -07:00
|
|
|
$this->assert_same(array("mime_type" => "invalid", "name" => "illegal_data_file_extension"),
|
|
|
|
|
$e->validation->errors());
|
2010-08-07 22:18:28 -07:00
|
|
|
return; // pass
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
2010-11-09 12:48:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function urls_test() {
|
|
|
|
|
$photo = test::random_photo();
|
|
|
|
|
$this->assert_true(
|
2010-12-15 14:57:00 -08:00
|
|
|
preg_match("|http://./var/resizes/name_\w+\.jpg\?m=\d+|", $photo->resize_url()),
|
2010-11-09 12:48:07 -08:00
|
|
|
$photo->resize_url() . " is malformed");
|
|
|
|
|
$this->assert_true(
|
2010-12-15 14:57:00 -08:00
|
|
|
preg_match("|http://./var/thumbs/name_\w+\.jpg\?m=\d+|", $photo->thumb_url()),
|
2010-11-09 12:48:07 -08:00
|
|
|
$photo->thumb_url() . " is malformed");
|
|
|
|
|
$this->assert_true(
|
2010-12-15 14:57:00 -08:00
|
|
|
preg_match("|http://./var/albums/name_\w+\.jpg\?m=\d+|", $photo->file_url()),
|
2010-11-09 12:48:07 -08:00
|
|
|
$photo->file_url() . " is malformed");
|
2010-08-07 22:18:28 -07:00
|
|
|
|
2010-11-09 12:48:07 -08:00
|
|
|
// Albums have special thumbnails. Empty album has cachebuster of 0 since it has no thumbnail
|
|
|
|
|
$album = test::random_album();
|
|
|
|
|
$this->assert_true(
|
2010-12-15 14:57:00 -08:00
|
|
|
preg_match("|http://./var/thumbs/name_\w+/\.album\.jpg\?m=0|", $album->thumb_url()),
|
2010-11-09 12:48:07 -08:00
|
|
|
$album->thumb_url() . " is malformed");
|
|
|
|
|
|
|
|
|
|
$photo = test::random_photo($album);
|
|
|
|
|
$this->assert_true(
|
2010-12-15 14:57:00 -08:00
|
|
|
preg_match("|http://./var/thumbs/name_\w+/\.album\.jpg\?m=\d+|", $album->thumb_url()),
|
2010-11-09 12:48:07 -08:00
|
|
|
$album->thumb_url() . " is malformed");
|
2010-08-07 22:18:28 -07:00
|
|
|
}
|
2010-12-14 21:18:40 -08:00
|
|
|
|
|
|
|
|
public function legal_extension_test() {
|
|
|
|
|
foreach (array("test.gif", "test.GIF", "test.Gif", "test.jpeg", "test.JPG") as $name) {
|
|
|
|
|
$photo = test::random_photo_unsaved(item::root());
|
|
|
|
|
$photo->name = $name;
|
|
|
|
|
$photo->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function illegal_extension_test() {
|
2012-05-17 20:25:27 -07:00
|
|
|
foreach (array("test.php", "test.PHP", "test.php5", "test.php4",
|
|
|
|
|
"test.pl", "test.php.png") as $name) {
|
2010-12-14 21:18:40 -08:00
|
|
|
try {
|
|
|
|
|
$photo = test::random_photo_unsaved(item::root());
|
|
|
|
|
$photo->name = $name;
|
|
|
|
|
$photo->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_equal(array("name" => "illegal_data_file_extension"),
|
|
|
|
|
$e->validation->errors());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-05 18:52:44 -07:00
|
|
|
|
|
|
|
|
public function cant_rename_to_illegal_extension_test() {
|
|
|
|
|
foreach (array("test.php.test", "test.php", "test.PHP",
|
|
|
|
|
"test.php5", "test.php4", "test.pl") as $name) {
|
|
|
|
|
try {
|
|
|
|
|
$photo = test::random_photo(item::root());
|
|
|
|
|
$photo->name = $name;
|
|
|
|
|
$photo->save();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
$this->assert_equal(array("name" => "illegal_data_file_extension"),
|
|
|
|
|
$e->validation->errors());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$this->assert_true(false, "Shouldn't get here");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-21 15:01:31 -07:00
|
|
|
|
|
|
|
|
public function albums_can_have_two_dots_in_name_test() {
|
|
|
|
|
$album = test::random_album_unsaved(item::root());
|
|
|
|
|
$album->name = $album->name . ".foo.bar";
|
|
|
|
|
$album->save();
|
|
|
|
|
}
|
2008-12-20 22:49:32 +00:00
|
|
|
}
|