summaryrefslogtreecommitdiff
path: root/modules/gallery_unit_test/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2013-01-24 18:14:28 -0500
committerBharat Mediratta <bharat@menalto.com>2013-01-24 18:14:28 -0500
commit03535786307c60f0f79ce4f773c9c1a8e43826ed (patch)
tree5ef1329cfaea5ab43dd9d28cb8aa48c0a34e1eed /modules/gallery_unit_test/helpers
parent86a2759062ee3dbf93f4c17c7499e3f506035047 (diff)
parent98d09c3740f1c19e477a71bdb44791306d7bd05b (diff)
Merge branch 'master' of github.com:gallery/gallery3
Diffstat (limited to 'modules/gallery_unit_test/helpers')
-rw-r--r--modules/gallery_unit_test/helpers/test.php28
1 files changed, 28 insertions, 0 deletions
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");