summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2013-01-24 12:46:26 -0800
committerBharat Mediratta <bharat@menalto.com>2013-01-24 12:46:26 -0800
commit6830ac4542f1afda275fcdf332e25ce35e53d0e7 (patch)
tree18c2b1e7770bd97b5f03875d04af749bb69a94bd /modules
parentc9a30e3b7e3b85b645a987d7024572345091364a (diff)
parent126727b4f2fa521d8b8dd45b6b4c26431efdfd66 (diff)
Merge pull request #99 from shadlaws/fix_1955
#1955 - Make unit test photos unique.
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/tests/Item_Model_Test.php8
-rw-r--r--modules/gallery_unit_test/helpers/test.php28
2 files changed, 32 insertions, 4 deletions
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index a7eba1ad..c45bbc3c 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -66,7 +66,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
}
public function rename_photo_test() {
- $item = test::random_photo();
+ $item = test::random_unique_photo();
$original_name = $item->name;
$thumb_file = file_get_contents($item->thumb_path());
@@ -89,7 +89,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
public function rename_album_test() {
$album = test::random_album();
- $photo = test::random_photo($album);
+ $photo = test::random_unique_photo($album);
$album->reload();
$thumb_file = file_get_contents($photo->thumb_path());
@@ -152,7 +152,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
public function move_album_test() {
$album2 = test::random_album();
$album1 = test::random_album($album2);
- $photo = test::random_photo($album1);
+ $photo = test::random_unique_photo($album1);
$thumb_file = file_get_contents($photo->thumb_path());
$resize_file = file_get_contents($photo->resize_path());
@@ -180,7 +180,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
public function move_photo_test() {
$album1 = test::random_album();
- $photo = test::random_photo($album1);
+ $photo = test::random_unique_photo($album1);
$album2 = test::random_album();
diff --git a/modules/gallery_unit_test/helpers/test.php b/modules/gallery_unit_test/helpers/test.php
index 3ccb35ca..75cf9b33 100644
--- a/modules/gallery_unit_test/helpers/test.php
+++ b/modules/gallery_unit_test/helpers/test.php
@@ -63,6 +63,34 @@ class test_Core {
return test::random_photo_unsaved($parent)->save()->reload();
}
+ // If a test compares photo file contents (i.e. file_get_contents), it's best to use this
+ // function to guarantee uniqueness.
+ static function random_unique_photo_unsaved($parent=null) {
+ $rand = test::random_string(6);
+ $photo = ORM::factory("item");
+ $photo->type = "photo";
+ $photo->parent_id = $parent ? $parent->id : 1;
+ if (function_exists("gd_info")) {
+ // Make image unique - color the black dot of test.jpg to the 6-digit hex code of rand.
+ $image = imagecreatefromjpeg(MODPATH . "gallery/tests/test.jpg");
+ imagefilter($image, IMG_FILTER_COLORIZE,
+ hexdec(substr($rand, 0, 2)), hexdec(substr($rand, 2, 2)), hexdec(substr($rand, 4, 2)));
+ imagejpeg($image, TMPPATH . "test_$rand.jpg");
+ imagedestroy($image);
+ $photo->set_data_file(TMPPATH . "test_$rand.jpg");
+ } else {
+ // Just use the black dot.
+ $photo->set_data_file(MODPATH . "gallery/tests/test.jpg");
+ }
+ $photo->name = "name_$rand.jpg";
+ $photo->title = "title_$rand";
+ return $photo;
+ }
+
+ static function random_unique_photo($parent=null) {
+ return test::random_unique_photo_unsaved($parent)->save()->reload();
+ }
+
static function random_user($password="password") {
$rand = "name_" . test::random_string(6);
return identity::create_user($rand, $rand, $password, "$rand@rand.com");