2008-11-04 21:24:42 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2009-05-13 20:04:58 +00:00
|
|
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
2008-11-04 21:24:42 +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.
|
|
|
|
|
*/
|
2008-11-09 23:49:09 +00:00
|
|
|
class Photo_Helper_Test extends Unit_Test_Case {
|
2008-11-04 21:24:42 +00:00
|
|
|
public function create_photo_test() {
|
|
|
|
|
$rand = rand();
|
2008-11-19 22:45:30 +00:00
|
|
|
|
2009-05-27 16:15:00 -07:00
|
|
|
$filename = MODPATH . "gallery/tests/test.jpg";
|
2008-11-19 22:45:30 +00:00
|
|
|
$image_info = getimagesize($filename);
|
|
|
|
|
|
2008-12-23 04:36:09 +00:00
|
|
|
$root = ORM::factory("item", 1);
|
|
|
|
|
$photo = photo::create($root, $filename, "$rand.jpg", $rand, $rand);
|
2008-11-04 21:24:42 +00:00
|
|
|
|
2008-11-05 07:13:46 +00:00
|
|
|
$this->assert_equal(VARPATH . "albums/$rand.jpg", $photo->file_path());
|
2008-12-17 04:45:35 +00:00
|
|
|
$this->assert_equal(VARPATH . "thumbs/{$rand}.jpg", $photo->thumb_path());
|
|
|
|
|
$this->assert_equal(VARPATH . "resizes/{$rand}.jpg", $photo->resize_path());
|
2008-11-04 21:24:42 +00:00
|
|
|
|
2008-11-05 07:13:46 +00:00
|
|
|
$this->assert_true(is_file($photo->file_path()), "missing: {$photo->file_path()}");
|
2008-11-04 21:24:42 +00:00
|
|
|
$this->assert_true(is_file($photo->resize_path()), "missing: {$photo->resize_path()}");
|
2008-12-17 04:45:35 +00:00
|
|
|
$this->assert_true(is_file($photo->thumb_path()), "missing: {$photo->thumb_path()}");
|
2008-11-04 21:24:42 +00:00
|
|
|
|
2009-03-17 18:09:21 +00:00
|
|
|
$this->assert_equal($root->id, $photo->parent_id); // MPTT tests cover other hierarchy checks
|
2008-11-04 21:24:42 +00:00
|
|
|
$this->assert_equal("$rand.jpg", $photo->name);
|
|
|
|
|
$this->assert_equal($rand, $photo->title);
|
|
|
|
|
$this->assert_equal($rand, $photo->description);
|
2008-11-19 03:39:12 +00:00
|
|
|
$this->assert_equal("image/jpeg", $photo->mime_type);
|
2008-11-19 22:45:30 +00:00
|
|
|
$this->assert_equal($image_info[0], $photo->width);
|
|
|
|
|
$this->assert_equal($image_info[1], $photo->height);
|
2008-11-04 21:24:42 +00:00
|
|
|
|
2009-07-25 19:06:54 +02:00
|
|
|
$this->assert_equal($photo->parent()->right_ptr - 2, $photo->left_ptr);
|
|
|
|
|
$this->assert_equal($photo->parent()->right_ptr - 1, $photo->right_ptr);
|
2008-11-04 21:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create_conflicting_photo_test() {
|
|
|
|
|
$rand = rand();
|
2008-12-23 04:36:09 +00:00
|
|
|
$root = ORM::factory("item", 1);
|
2009-05-27 16:15:00 -07:00
|
|
|
$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);
|
2008-11-04 21:24:42 +00:00
|
|
|
$this->assert_true($photo1->name != $photo2->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create_photo_with_no_extension_test() {
|
2008-12-23 04:36:09 +00:00
|
|
|
$root = ORM::factory("item", 1);
|
2008-11-04 21:24:42 +00:00
|
|
|
try {
|
2008-12-23 04:36:09 +00:00
|
|
|
photo::create($root, "/tmp", "name", "title", "description");
|
2008-11-04 21:24:42 +00:00
|
|
|
$this->assert_false("should fail with an exception");
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
// pass
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-05 07:13:46 +00:00
|
|
|
|
2008-12-17 04:45:35 +00:00
|
|
|
public function thumb_url_test() {
|
2008-11-05 07:13:46 +00:00
|
|
|
$rand = rand();
|
2008-12-23 04:36:09 +00:00
|
|
|
$root = ORM::factory("item", 1);
|
2009-05-27 16:15:00 -07:00
|
|
|
$photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
|
2009-09-08 21:52:15 -07:00
|
|
|
$this->assert_equal("http://./var/thumbs/{$rand}.jpg?m={$photo->updated}", $photo->thumb_url());
|
2008-11-05 07:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function resize_url_test() {
|
|
|
|
|
$rand = rand();
|
2008-12-23 04:36:09 +00:00
|
|
|
$root = ORM::factory("item", 1);
|
|
|
|
|
$album = album::create($root, $rand, $rand, $rand);
|
2009-05-27 16:15:00 -07:00
|
|
|
$photo = photo::create($album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand);
|
2008-11-05 09:42:47 +00:00
|
|
|
|
2010-01-02 13:47:28 -08:00
|
|
|
$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());
|
2009-09-07 15:41:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2008-11-05 07:13:46 +00:00
|
|
|
}
|
2009-05-16 03:48:56 +00:00
|
|
|
|
|
|
|
|
public function create_photo_shouldnt_allow_names_with_slash_test() {
|
|
|
|
|
$rand = rand();
|
|
|
|
|
$root = ORM::factory("item", 1);
|
|
|
|
|
try {
|
2009-05-27 16:15:00 -07:00
|
|
|
$photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand/.jpg", $rand, $rand);
|
2009-05-16 03:48:56 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
// pass
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assert_true(false, "Shouldn't create a photo with / in the name");
|
|
|
|
|
}
|
2009-05-16 22:20:16 +00:00
|
|
|
|
|
|
|
|
public function create_photo_silently_trims_trailing_periods_test() {
|
|
|
|
|
$rand = rand();
|
|
|
|
|
$root = ORM::factory("item", 1);
|
|
|
|
|
try {
|
2009-05-27 16:15:00 -07:00
|
|
|
$photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg.", $rand, $rand);
|
2009-05-16 22:20:16 +00:00
|
|
|
} 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");
|
|
|
|
|
}
|
2008-11-04 21:24:42 +00:00
|
|
|
}
|