diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 03:29:14 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 03:29:14 +0000 |
commit | 59db5456d42d3a300cce661a9b5f7da069c26893 (patch) | |
tree | b69a1a9e2a564a89dace935eb31b1626b2f9ad7c /core/tests/Item_Model_Test.php | |
parent | 9d272f29624db8a6513c609c7edfd57853ac5304 (diff) |
Implement Item_Model::rename(), with unit tests.
Diffstat (limited to 'core/tests/Item_Model_Test.php')
-rw-r--r-- | core/tests/Item_Model_Test.php | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/core/tests/Item_Model_Test.php b/core/tests/Item_Model_Test.php index 31d7b18e..40915360 100644 --- a/core/tests/Item_Model_Test.php +++ b/core/tests/Item_Model_Test.php @@ -29,12 +29,7 @@ class Item_Model_Test extends Unit_Test_Case { /* Set all required fields (values are irrelevant) */ $item->name = rand(); $item->type = "photo"; - $item->left = 1; - $item->right = 1; - $item->level = 1; - $item->parent_id = 1; - $item->save(); - return $item; + return $item->add_to_parent(ORM::factory("item", 1)); } public function updating_doesnt_change_created_date_test() { @@ -66,4 +61,68 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_same(1, $item->view_count); $this->assert_true(empty($item->updated)); } + + public function move_photo_test() { + // Create a test photo + $item = self::create_random_item(); + + file_put_contents($item->thumb_path(), "thumb"); + file_put_contents($item->resize_path(), "resize"); + file_put_contents($item->file_path(), "file"); + + $original_name = $item->name; + $new_name = rand(); + + // Now rename it + $item->rename($new_name)->save(); + + // Expected: the name changed, the name is now baked into all paths, and all files were moved. + $this->assert_equal($new_name, $item->name); + $this->assert_equal($new_name, basename($item->file_path())); + $this->assert_equal($new_name, basename($item->thumb_path())); + $this->assert_equal($new_name, basename($item->resize_path())); + $this->assert_equal("thumb", file_get_contents($item->thumb_path())); + $this->assert_equal("resize", file_get_contents($item->resize_path())); + $this->assert_equal("file", file_get_contents($item->file_path())); + } + + public function move_album_test() { + // Create an album with a photo in it + $root = ORM::factory("item", 1); + $album = album::create($root, rand(), rand(), rand()); + $photo = ORM::factory("item"); + $photo->name = rand(); + $photo->type = "photo"; + $photo->add_to_parent($album); + + file_put_contents($photo->thumb_path(), "thumb"); + file_put_contents($photo->resize_path(), "resize"); + file_put_contents($photo->file_path(), "file"); + + $original_album_name = $album->name; + $original_photo_name = $photo->name; + $new_album_name = rand(); + + // Now rename the album + $album->rename($new_album_name)->save(); + $photo->reload(); + + // Expected: + // * the album name changed. + // * the album dirs are all moved + // * the photo's paths are all inside the albums paths + // * the photo files are all still intact and accessible + $this->assert_equal($new_album_name, $album->name); + $this->assert_equal($new_album_name, basename($album->file_path())); + $this->assert_equal($new_album_name, basename(dirname($album->thumb_path()))); + $this->assert_equal($new_album_name, basename(dirname($album->resize_path()))); + + $this->assert_same(0, strpos($photo->file_path(), $album->file_path())); + $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path()))); + $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path()))); + + $this->assert_equal("thumb", file_get_contents($photo->thumb_path())); + $this->assert_equal("resize", file_get_contents($photo->resize_path())); + $this->assert_equal("file", file_get_contents($photo->file_path())); + } } |