Permalink
Browse files

Prevent accidentally deleting the root album.

  • Loading branch information...
1 parent ec0f89f commit 212633d05a5a8abb77a744a69c61d6e3051b73c5 @bharat bharat committed Jan 28, 2010
Showing with 16 additions and 0 deletions.
  1. +6 −0 modules/gallery/models/item.php
  2. +10 −0 modules/gallery/tests/Item_Model_Test.php
@@ -71,6 +71,12 @@ public function is_movie() {
}
public function delete() {
+ if ($this->id == 1) {
+ $v = new Validation(array("id"));
+ $v->add_error("id", "cant_delete_root_album");
+ ORM_Validation_Exception::handle_validation($this->table_name, $v);
+ }
+
$old = clone $this;
module::event("item_before_delete", $this);
@@ -336,4 +336,14 @@ public function cant_change_item_type_test() {
}
$this->assert_true(false, "Shouldn't get here");
}
+
+ public function cant_delete_root_album_test() {
+ try {
+ item::root()->delete();
+ } catch (ORM_Validation_Exception $e) {
+ $this->assert_same(array("id" => "cant_delete_root_album"), $e->validation->errors());
+ return; // pass
+ }
+ $this->assert_true(false, "Shouldn't get here");
+ }
}

0 comments on commit 212633d

Please sign in to comment.