From d78ea4bc0aaa0e40f54f2ac703fbb690722aac42 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 30 Mar 2010 13:18:03 -0700 Subject: Checkpoint --- modules/gallery/tests/xss_data.txt | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index a3ca31f4..afad9e13 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -70,12 +70,12 @@ modules/gallery/views/admin_graphics_imagemagick.html.php 2 DIRTY_ATTR $is_ modules/gallery/views/admin_graphics_imagemagick.html.php 2 DIRTY_ATTR $tk->installed?" g-installed-toolkit":" g-unavailable" modules/gallery/views/admin_graphics_imagemagick.html.php 18 DIRTY $tk->error modules/gallery/views/admin_languages.html.php 43 DIRTY access::csrf_form_field() -modules/gallery/views/admin_languages.html.php 60 DIRTY_ATTR (isset($installed_locales[$code]))?"g-available":"" -modules/gallery/views/admin_languages.html.php 60 DIRTY_ATTR ($default_locale==$code)?" g-selected":"" -modules/gallery/views/admin_languages.html.php 61 DIRTY form::checkbox("installed_locales[]",$code,isset($installed_locales[$code])) -modules/gallery/views/admin_languages.html.php 62 DIRTY $display_name -modules/gallery/views/admin_languages.html.php 64 DIRTY form::radio("default_locale",$code,($default_locale==$code),((isset($installed_locales[$code]))?'':'disabled="disabled"')) -modules/gallery/views/admin_languages.html.php 109 DIRTY $share_translations_form +modules/gallery/views/admin_languages.html.php 61 DIRTY_ATTR (isset($installed_locales[$code]))?"g-available":"" +modules/gallery/views/admin_languages.html.php 61 DIRTY_ATTR ($default_locale==$code)?" g-selected":"" +modules/gallery/views/admin_languages.html.php 62 DIRTY form::checkbox("installed_locales[]",$code,isset($installed_locales[$code])) +modules/gallery/views/admin_languages.html.php 63 DIRTY $display_name +modules/gallery/views/admin_languages.html.php 65 DIRTY form::radio("default_locale",$code,($default_locale==$code),((isset($installed_locales[$code]))?'':'disabled="disabled"')) +modules/gallery/views/admin_languages.html.php 110 DIRTY $share_translations_form modules/gallery/views/admin_maintenance.html.php 24 DIRTY_ATTR text::alternate("g-odd","g-even") modules/gallery/views/admin_maintenance.html.php 24 DIRTY_ATTR log::severity_class($task->severity) modules/gallery/views/admin_maintenance.html.php 25 DIRTY_ATTR log::severity_class($task->severity) @@ -121,10 +121,10 @@ modules/gallery/views/admin_themes.html.php 76 DIRTY $info- modules/gallery/views/admin_themes.html.php 78 DIRTY $info->description modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url modules/gallery/views/error_404.html.php 14 DIRTY $login_form -modules/gallery/views/form_uploadify.html.php 30 DIRTY_JS url::file("lib/uploadify/uploadify.swf") -modules/gallery/views/form_uploadify.html.php 31 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") -modules/gallery/views/form_uploadify.html.php 35 DIRTY_JS url::file("lib/uploadify/cancel.png") -modules/gallery/views/form_uploadify.html.php 36 DIRTY_JS $simultaneous_upload_limit +modules/gallery/views/form_uploadify.html.php 9 DIRTY_JS url::file("lib/uploadify/uploadify.swf") +modules/gallery/views/form_uploadify.html.php 10 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") +modules/gallery/views/form_uploadify.html.php 14 DIRTY_JS url::file("lib/uploadify/cancel.png") +modules/gallery/views/form_uploadify.html.php 15 DIRTY_JS $simultaneous_upload_limit modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form")) modules/gallery/views/in_place_edit.html.php 3 DIRTY access::csrf_form_field() modules/gallery/views/in_place_edit.html.php 6 DIRTY form::input("input",$form["input"]," class=\"textbox\"") @@ -320,19 +320,20 @@ modules/user/views/admin_users_group.html.php 24 DIRTY_JS $group modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $width modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $height modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $url -themes/admin_wind/views/admin.html.php 16 DIRTY_JS $theme->url() -themes/admin_wind/views/admin.html.php 33 DIRTY $theme->admin_head() -themes/admin_wind/views/admin.html.php 37 DIRTY $theme->admin_page_top() -themes/admin_wind/views/admin.html.php 45 DIRTY $theme->admin_header_top() -themes/admin_wind/views/admin.html.php 46 DIRTY_JS item::root()->url() -themes/admin_wind/views/admin.html.php 49 DIRTY $theme->user_menu() -themes/admin_wind/views/admin.html.php 51 DIRTY $theme->admin_menu() -themes/admin_wind/views/admin.html.php 53 DIRTY $theme->admin_header_bottom() -themes/admin_wind/views/admin.html.php 60 DIRTY $content -themes/admin_wind/views/admin.html.php 66 DIRTY $sidebar -themes/admin_wind/views/admin.html.php 71 DIRTY $theme->admin_footer() -themes/admin_wind/views/admin.html.php 73 DIRTY $theme->admin_credits() -themes/admin_wind/views/admin.html.php 77 DIRTY $theme->admin_page_bottom() +themes/admin_wind/views/admin.html.php 9 DIRTY $page_title +themes/admin_wind/views/admin.html.php 22 DIRTY_JS $theme->url() +themes/admin_wind/views/admin.html.php 39 DIRTY $theme->admin_head() +themes/admin_wind/views/admin.html.php 43 DIRTY $theme->admin_page_top() +themes/admin_wind/views/admin.html.php 51 DIRTY $theme->admin_header_top() +themes/admin_wind/views/admin.html.php 52 DIRTY_JS item::root()->url() +themes/admin_wind/views/admin.html.php 55 DIRTY $theme->user_menu() +themes/admin_wind/views/admin.html.php 57 DIRTY $theme->admin_menu() +themes/admin_wind/views/admin.html.php 59 DIRTY $theme->admin_header_bottom() +themes/admin_wind/views/admin.html.php 66 DIRTY $content +themes/admin_wind/views/admin.html.php 72 DIRTY $sidebar +themes/admin_wind/views/admin.html.php 77 DIRTY $theme->admin_footer() +themes/admin_wind/views/admin.html.php 79 DIRTY $theme->admin_credits() +themes/admin_wind/views/admin.html.php 83 DIRTY $theme->admin_page_bottom() themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor themes/admin_wind/views/block.html.php 5 DIRTY $id themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id -- cgit v1.2.3 From 78db1bb339042f3aadb5a61bfe26ddd20c4b8951 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 4 Apr 2010 14:27:39 -0700 Subject: Fix a bug where if the file name is composed of entirely illegal characters, we'll get an empty slug. Partial fix for #1086. --- modules/gallery/models/item.php | 6 ++++++ modules/gallery/tests/Item_Model_Test.php | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 6ede5109..1026264f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -332,6 +332,12 @@ class Item_Model extends ORM_MPTT { $tmp = pathinfo($this->name, PATHINFO_FILENAME); $tmp = preg_replace("/[^A-Za-z0-9-_]+/", "-", $tmp); $this->slug = trim($tmp, "-"); + + // If the filename is all invalid characters, then the slug may be empty here. Pick a + // random value. + if (empty($this->slug)) { + $this->slug = (string)rand(1000, 9999); + } } // Get the width, height and mime type from our data file for photos and movies. diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index d0676292..8ab85a30 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -324,6 +324,12 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $album->save(); } + public function name_with_only_invalid_chars_is_still_valid_test() { + $album = test::random_album_unsaved(); + $album->name = "[]"; + $album->save(); + } + public function cant_change_item_type_test() { $photo = test::random_photo(); try { -- cgit v1.2.3 From c9edb943f99704a649612afa6ae7825b2e6bc44e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 10 Apr 2010 17:01:48 -0700 Subject: Fix a bug introduced when we patched the "disallowed global data" security check. Not sure why the patch worked for some and not for others, but this should resolve it either way. Fixes ticket #1123. --- modules/gallery/libraries/MY_Input.php | 2 +- modules/gallery/tests/Input_Library_Test.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 modules/gallery/tests/Input_Library_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/libraries/MY_Input.php b/modules/gallery/libraries/MY_Input.php index 703136c7..1d5949e8 100644 --- a/modules/gallery/libraries/MY_Input.php +++ b/modules/gallery/libraries/MY_Input.php @@ -26,6 +26,6 @@ class Input extends Input_Core { * @return string */ public function clean_input_keys($str) { - return preg_replace('#^[\pL0-9:_.-]++$#uD', '_', $str); + return preg_replace('#[^a-zA-Z0-9:_.-]+#', '_', $str); } } diff --git a/modules/gallery/tests/Input_Library_Test.php b/modules/gallery/tests/Input_Library_Test.php new file mode 100644 index 00000000..06641323 --- /dev/null +++ b/modules/gallery/tests/Input_Library_Test.php @@ -0,0 +1,25 @@ +assert_same("foo_bar", $input->clean_input_keys("foo|bar")); + } +} \ No newline at end of file -- cgit v1.2.3 From af71df3d0f6bbed29446df1801d16d28acbf927c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 17 Apr 2010 15:35:09 -0700 Subject: Update tests to reflect recent changes to the REST API. --- modules/gallery/tests/Item_Rest_Helper_Test.php | 70 ++++++++++++++----------- modules/rest/tests/Rest_Controller_Test.php | 1 + modules/tag/tests/Tag_Item_Rest_Helper_Test.php | 2 +- modules/tag/tests/Tag_Rest_Helper_Test.php | 32 +---------- modules/tag/tests/Tags_Rest_Helper_Test.php | 8 +-- 5 files changed, 49 insertions(+), 64 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index bef95668..0b5e0471 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -42,13 +42,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo1), - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -56,13 +57,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo1), - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -70,14 +72,15 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array())), "members" => array( rest::url("item", $photo1), rest::url("item", $album2), rest::url("item", $photo2)), - "relationships" => array( - "tags" => array( - "url" => rest::url("item_tags", $album1), - "members" => array()))), + ), item_rest::get($request)); } @@ -96,12 +99,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo2)), + ), item_rest::get($request)); } @@ -118,12 +122,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array() ))), + "members" => array())), + "members" => array( + rest::url("item", $album2)), + ), item_rest::get($request)); } @@ -134,7 +139,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->title = "my new title"; + $request->params->entity = new stdClass(); + $request->params->entity->title = "my new title"; item_rest::put($request); $this->assert_equal("my new title", $album1->reload()->title); @@ -147,8 +153,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->title = "my new title"; - $request->params->slug = "not url safe"; + $request->params->entity = new stdClass(); + $request->params->entity->title = "my new title"; + $request->params->entity->slug = "not url safe"; try { item_rest::put($request); @@ -166,9 +173,10 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "album"; + $request->params->entity->name = "my album"; + $request->params->entity->title = "my album"; $response = item_rest::post($request); $new_album = rest::resolve($response["url"]); @@ -183,10 +191,11 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; - $request->params->slug = "not url safe"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "album"; + $request->params->entity->name = "my album"; + $request->params->entity->title = "my album"; + $request->params->entity->slug = "not url safe"; try { item_rest::post($request); @@ -205,8 +214,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "photo"; - $request->params->name = "my photo.jpg"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "photo"; + $request->params->entity->name = "my photo.jpg"; $request->file = MODPATH . "gallery/tests/test.jpg"; $response = item_rest::post($request); $new_photo = rest::resolve($response["url"]); diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 6d09b214..fe83283d 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -27,6 +27,7 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { public function teardown() { list($_GET, $_POST, $_SERVER) = $this->_save; + identity::set_active_user(identity::admin_user()); } public function login_test() { diff --git a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php index e5acab93..533f832d 100644 --- a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php @@ -32,7 +32,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->url = rest::url("tag_item", $tag, item::root()); $this->assert_equal_array( array("url" => rest::url("tag_item", $tag, item::root()), - "members" => array( + "entity" => array( "tag" => rest::url("tag", $tag), "item" => rest::url("item", item::root()))), tag_item_rest::get($request)); diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index f4d5a14a..a8aa89d4 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -67,41 +67,13 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { tag_rest::get($request)); } - public function post_test() { - $tag = test::random_tag(); - - // Create an editable item to be tagged - $album = test::random_album(); - access::allow(identity::everybody(), "edit", $album); - - // Add the album to the tag - $request = new stdClass(); - $request->url = rest::url("tag", $tag); - $request->params = new stdClass(); - $request->params->url = rest::url("item", $album); - $this->assert_equal_array( - array("url" => rest::url("tag_item", $tag, $album)), - tag_rest::post($request)); - } - - public function post_with_no_item_url_test() { - $request = new stdClass(); - try { - tag_rest::post($request); - } catch (Rest_Exception $e) { - $this->assert_equal(400, $e->getCode()); - return; - } - - $this->assert_true(false, "Shouldn't get here"); - } - public function put_test() { $tag = test::random_tag(); $request = new stdClass(); $request->url = rest::url("tag", $tag); $request->params = new stdClass(); - $request->params->name = "new name"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "new name"; tag_rest::put($request); $this->assert_equal("new name", $tag->reload()->name); diff --git a/modules/tag/tests/Tags_Rest_Helper_Test.php b/modules/tag/tests/Tags_Rest_Helper_Test.php index a0ebc8c3..99332c7c 100644 --- a/modules/tag/tests/Tags_Rest_Helper_Test.php +++ b/modules/tag/tests/Tags_Rest_Helper_Test.php @@ -45,11 +45,12 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { } public function post_test() { - access::allow(identity::everybody(), "edit", item::root()); + identity::set_active_user(identity::guest()); $request = new stdClass(); $request->params = new stdClass(); - $request->params->name = "test tag"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "test tag"; $this->assert_equal( array("url" => url::site("rest/tag/1")), tags_rest::post($request)); @@ -63,7 +64,8 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { try { $request = new stdClass(); $request->params = new stdClass(); - $request->params->name = "test tag"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "test tag"; tags_rest::post($request); } catch (Exception $e) { $this->assert_equal(403, $e->getCode()); -- cgit v1.2.3 From 4068e80f0678ab8f71a9262630383d7fef79547a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 22 Apr 2010 22:24:44 -0700 Subject: Update test to reflect slug change in 78db1bb339042f3aadb5a61bfe26ddd20c4b8951 --- modules/gallery/tests/Item_Model_Test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 8ab85a30..28d6fba7 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -295,7 +295,6 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { } catch (ORM_Validation_Exception $e) { $this->assert_same(array("description" => "length", "name" => "required", - "slug" => "required", "title" => "required", "album_cover_item_id" => "invalid_item", "parent_id" => "invalid", -- cgit v1.2.3 From 9affa8ebbd539396d71f19003b91af577a8a183e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 10 May 2010 22:11:59 -0700 Subject: Pick a new album cover when the photo that's the current cover is deleted. Fixes ticket #1083. --- modules/gallery/helpers/gallery_event.php | 11 +++++++++++ modules/gallery/tests/Item_Helper_Test.php | 13 ++++++++++++- modules/gallery/tests/Item_Model_Test.php | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index d723cc1b..2416f2e5 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); + } } -- cgit v1.2.3