public function move_leaves_empty_album_with_no_album_cover_test() { $src_album = test::random_album(); $photo = test::random_photo($src_album); item::move($photo, item::root()); $src_album->reload(); $this->assert_false($src_album->album_cover_item_id); }
public function get_children_type_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); $album2 = test::random_album($album1); $album1->reload(); $request->url = rest::url("item", $album1); $request->params->type = "album"; $this->assert_equal_array(array("url" => rest::url("item", $album1), "entity" => $album1->as_array(), "members" => array(rest::url("item", $album2)), "relationships" => array("tags" => array("url" => rest::url("item_tags", $album1), "members" => array()))), item_rest::get($request)); }
public function build_breadcrumbs_for_item_test() { $album = test::random_album(); $item = test::random_photo($album); $expected = array(); $expected[] = Breadcrumb::instance(item::root()->title, item::root()->url("show={$album->id}"))->set_first(); $expected[] = Breadcrumb::instance($album->title, $album->url("show={$item->id}")); $expected[] = Breadcrumb::instance($item->title, $item->url())->set_last(); $this->assert_equal($expected, Breadcrumb::array_from_item_parents($item)); }
private function _get_proxy() { $album = test::random_album(); $photo = test::random_photo($album); access::deny(identity::everybody(), "view_full", $album); access::deny(identity::registered_users(), "view_full", $album); $proxy = ORM::factory("digibug_proxy"); $proxy->uuid = random::hash(); $proxy->item_id = $photo->id; return $proxy->save(); }
public function viewable_test() { $album = test::random_album(); $item = test::random_photo($album); $album->reload(); identity::set_active_user(identity::guest()); // We can see the item when permissions are granted access::allow(identity::everybody(), "view", $album); $this->assert_equal(1, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); // We can't see the item when permissions are denied access::deny(identity::everybody(), "view", $album); $this->assert_equal(0, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); }
public function change_photo_no_csrf_fails_test() { $controller = new Photos_Controller(); $photo = test::random_photo(); $_POST["name"] = "new name.jpg"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; $_POST["slug"] = "new slug"; access::allow(identity::everybody(), "edit", item::root()); try { $controller->update($photo); $this->assert_true(false, "This should fail"); } catch (Exception $e) { // pass $this->assert_same("@todo FORBIDDEN", $e->getMessage()); } }
public function get_ancestors_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); $album2 = test::random_album($album1); $photo2 = test::random_photo($album2); $album1->reload(); $album2->reload(); $root = ORM::factory("item", 1); $restful_root = array("url" => rest::url("item", $root), "entity" => $root->as_restful_array(), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { $restful_root["members"][] = rest::url("item", $child); } $request = new stdClass(); $request->params = new stdClass(); $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array(array($restful_root, array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album1)), "tags" => array("url" => rest::url("item_tags", $album1), "members" => array())), "members" => array(rest::url("item", $photo1), rest::url("item", $album2))), array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album2)), "tags" => array("url" => rest::url("item_tags", $album2), "members" => array())), "members" => array(rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), "entity" => $photo2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $photo2)), "tags" => array("url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); }
public function as_restful_array_test() { $album = test::random_album(); $photo = test::random_photo($album); $album->reload(); $result = $album->as_restful_array(); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); $this->assert_true(!array_key_exists("album_cover_item_id", $result)); }
public function urls_test() { $photo = test::random_photo(); $this->assert_true(preg_match("|http://./var/resizes/name_\\w+\\.jpg\\?m=\\d+|", $photo->resize_url()), $photo->resize_url() . " is malformed"); $this->assert_true(preg_match("|http://./var/thumbs/name_\\w+\\.jpg\\?m=\\d+|", $photo->thumb_url()), $photo->thumb_url() . " is malformed"); $this->assert_true(preg_match("|http://./var/albums/name_\\w+\\.jpg\\?m=\\d+|", $photo->file_url()), $photo->file_url() . " is malformed"); // Albums have special thumbnails. Empty album has cachebuster of 0 since it has no thumbnail $album = test::random_album(); $this->assert_true(preg_match("|http://./var/thumbs/name_\\w+/\\.album\\.jpg\\?m=0|", $album->thumb_url()), $album->thumb_url() . " is malformed"); $photo = test::random_photo($album); $this->assert_true(preg_match("|http://./var/thumbs/name_\\w+/\\.album\\.jpg\\?m=\\d+|", $album->thumb_url()), $album->thumb_url() . " is malformed"); }
public function moved_items_inherit_new_permissions_test() { identity::set_active_user(identity::lookup_user_by_name("admin")); $public_album = test::random_album(); $public_photo = test::random_photo($public_album); access::allow(identity::everybody(), "view", $public_album); access::allow(identity::everybody(), "edit", $public_album); item::root()->reload(); // Account for MPTT changes $private_album = test::random_album(); access::deny(identity::everybody(), "view", $private_album); access::deny(identity::everybody(), "edit", $private_album); $private_photo = test::random_photo($private_album); // Make sure that we now have a public photo and private photo. $this->assert_true(access::group_can(identity::everybody(), "view", $public_photo)); $this->assert_false(access::group_can(identity::everybody(), "view", $private_photo)); // Swap the photos item::move($public_photo, $private_album); $private_album->reload(); // Reload to get new MPTT pointers and cached perms. $public_album->reload(); $private_photo->reload(); $public_photo->reload(); item::move($private_photo, $public_album); $private_album->reload(); // Reload to get new MPTT pointers and cached perms. $public_album->reload(); $private_photo->reload(); $public_photo->reload(); // Make sure that the public_photo is now private, and the private_photo is now public. $this->assert_false(access::group_can(identity::everybody(), "view", $public_photo)); $this->assert_false(access::group_can(identity::everybody(), "edit", $public_photo)); $this->assert_true(access::group_can(identity::everybody(), "view", $private_photo)); $this->assert_true(access::group_can(identity::everybody(), "edit", $private_photo)); }
public function cant_rename_to_illegal_extension_test() { foreach (array("test.php.test", "test.php", "test.PHP", "test.php5", "test.php4", "test.pl") as $name) { try { $photo = test::random_photo(item::root()); $photo->name = $name; $photo->save(); } catch (ORM_Validation_Exception $e) { $this->assert_equal(array("name" => "illegal_data_file_extension"), $e->validation->errors()); continue; } $this->assert_true(false, "Shouldn't get here"); } }
public function delete_cover_photo_picks_new_album_cover_test() { $parent = test::random_album(); $album = test::random_album($parent); $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(); $parent->reload(); $this->assert_same($photo2->id, $album->album_cover_item_id); $this->assert_same($photo2->id, $parent->album_cover_item_id); }
public function get_file_metadata_test() { $photo = test::random_photo(); $this->assert_equal(array(1024, 768, "image/jpeg", "jpg"), photo::get_file_metadata($photo->file_path())); }
public function resequence_child_weights_test() { $album = test::random_album_unsaved(); $album->sort_column = "id"; $album->save(); $photo1 = test::random_photo($album); $photo2 = test::random_photo($album); $this->assert_true($photo2->weight > $photo1->weight); $album->reload(); $album->sort_order = "DESC"; $album->save(); item::resequence_child_weights($album); $this->assert_equal(2, $photo1->reload()->weight); $this->assert_equal(1, $photo2->reload()->weight); }
public function missing_file_test() { $photo = test::random_photo(); $_SERVER["REQUEST_URI"] = url::file("var/albums/{$photo->name}"); unlink($photo->file_path()); $controller = new File_Proxy_Controller(); try { $controller->__call("", array()); $this->assert_true(false); } catch (Kohana_404_Exception $e) { $this->assert_same(7, $e->test_fail_code); } }
public function descendant_count_test() { $parent = test::random_album(); $photo = test::random_photo($parent); $album1 = test::random_album($parent); $photo1 = test::random_photo($album1); $parent->reload(); $this->assert_equal(3, $parent->descendants_count()); $this->assert_equal(2, $parent->descendants_count(array(array("type", "=", "photo")))); $this->assert_equal(1, $parent->descendants_count(array(array("type", "=", "album")))); }
public function cache_buster_test() { $photo = test::random_photo(); $this->assert_same(url::abs_site("rest/data/{$photo->id}?size=thumb&m=" . filemtime($photo->thumb_path())), data_rest::url($photo, "thumb")); }
public function generate_album_cover_from_bad_photo_test() { $album = test::random_album(); $photo = test::random_photo($album); $album->reload(); // At this point, the photo is valid and has a valid resize and thumb. Make it garble. file_put_contents($photo->file_path(), test::lorem_ipsum(200)); // Regenerate album from garbled photo. $photo->thumb_dirty = 1; $photo->save(); $album->thumb_dirty = 1; try { graphics::generate($album); $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // Exception expected } // Check that the image got replaced with a missing image placeholder $this->assert_same(file_get_contents(MODPATH . "gallery/images/missing_photo.jpg"), file_get_contents($album->thumb_path())); // Check that the items table got updated with new metadata $this->assert_equal(array(200, 200), array($album->thumb_width, $album->thumb_height)); // Check that the images are marked as dirty $this->assert_equal(1, $album->thumb_dirty); }
public function fix_conflict_when_base_names_identical_between_jpg_png_flv_test() { $parent = test::random_album(); $item1 = test::random_photo($parent); $item2 = test::random_photo($parent); $item3 = test::random_movie($parent); $item1_orig_base = pathinfo($item1->name, PATHINFO_FILENAME); $item2_orig_slug = $item2->slug; $item3_orig_slug = $item3->slug; $item2->set_data_file(MODPATH . "gallery/images/graphicsmagick.png"); $item2->name = "{$item1_orig_base}.png"; $item2->save(); $item3->name = "{$item1_orig_base}.flv"; $item3->save(); // item2 and item3 have same base name as item1 - conflict resolved by renaming with -01 and -02. $this->assert_same("{$item1_orig_base}-01.png", $item2->name); $this->assert_same("{$item2_orig_slug}-01", $item2->slug); $this->assert_same("{$item1_orig_base}-02.flv", $item3->name); $this->assert_same("{$item3_orig_slug}-02", $item3->slug); }
public function cant_change_item_type_test() { $photo = test::random_photo(); try { $photo->type = "movie"; $photo->mime_type = "video/x-flv"; $photo->save(); } catch (ORM_Validation_Exception $e) { $this->assert_same(array("type" => "read_only"), $e->validation->errors()); return; // pass } $this->assert_true(false, "Shouldn't get here"); }