diff options
author | Chad Kieffer <ckieffer@abel.local> | 2010-05-14 17:16:22 -0600 |
---|---|---|
committer | Chad Kieffer <ckieffer@abel.local> | 2010-05-14 17:16:22 -0600 |
commit | 163dd0eb931ea6fa0917bb08df0a0cc0b73f5576 (patch) | |
tree | a545845082f856d1b8b6315d82456634c8cae579 /modules | |
parent | d98b85f7d3142676e6b4f407a18ed81564823f88 (diff) | |
parent | 9affa8ebbd539396d71f19003b91af577a8a183e (diff) |
Merge branch 'master' of github.com:gallery/gallery3
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 11 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 13 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Model_Test.php | 8 |
3 files changed, 31 insertions, 1 deletions
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index d01b2956..9b3aa82d 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -97,6 +97,17 @@ class gallery_event_Core { static function item_deleted($item) { access::delete_item($item); + + $parent = $item->parent(); + if (!$parent->album_cover_item_id) { + // Assume we deleted the album cover and pick a new one. Choosing the first photo in the + // album is logical, but it's not the most efficient in the case where we're deleting all + // the photos in the album one at a time since we'll probably delete them in order which + // means that we'll be resetting the album cover each time. + if ($child = $parent->children(1)->current()) { + item::make_album_cover($child); + } + } } static function item_moved($item, $old_parent) { diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 295871a5..4771b11a 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -54,7 +54,6 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_same($dst_album->id, $photo->parent_id); } - public function move_updates_album_covers_test() { // 2 photos in the source album $src_album = test::random_album(); @@ -106,4 +105,16 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_not_same("{$rand}.jpg", $photo2->name); $this->assert_not_same($rand, $photo2->slug); } + + public function delete_cover_photo_picks_new_album_cover() { + $album = test::random_album(); + $photo1 = test::random_photo($album); + // At this point, $photo1 is the album cover. We verify this in + // Item_Model_Test::first_photo_becomes_album_cover + $photo2 = test::random_photo($album); + $photo1->delete(); + $album->reload(); + + $this->assert_same($photo2->id, $album->album_cover_item_id); + } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 28d6fba7..15aa2d8c 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -363,4 +363,12 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_true(!array_key_exists("parent_id", $result)); $this->assert_true(!array_key_exists("album_cover_item_id", $result)); } + + 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); + } } |