From 8dc34dade882768feb8100d7041d94c7d446b818 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Jan 2013 00:51:31 -0500 Subject: Add unit tests for data_rest. While I'm in there, get rid of the clause that returns nothing when the album has no album cover - we'll fail before that if the album's thumbnail is missing, and if it's not missing then we'll have something to serve even if it's out of date. --- modules/gallery/tests/Data_Rest_Helper_Test.php | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 modules/gallery/tests/Data_Rest_Helper_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Data_Rest_Helper_Test.php b/modules/gallery/tests/Data_Rest_Helper_Test.php new file mode 100644 index 00000000..feec6d32 --- /dev/null +++ b/modules/gallery/tests/Data_Rest_Helper_Test.php @@ -0,0 +1,102 @@ +assert_equal($photo->id, $resolved->id); + } + + public function resolve_needs_permission_test() { + $album = test::random_album(); + $photo = test::random_photo($album); + $album->reload(); // new photo changed the album in the db + + access::deny(identity::everybody(), "view", $album); + identity::set_active_user(identity::guest()); + + try { + data_rest::resolve($photo->id); + $this->assert_true(false); + } catch (Kohana_404_Exception $e) { + // pass + } + } + + public function basic_get_test() { + $photo = test::random_photo(); + + $request = new stdClass(); + $request->url = rest::url("data", $photo, "thumb"); + $request->params = new stdClass(); + + $request->params->size = "thumb"; + $this->assert_same($photo->thumb_path(), data_rest::get($request)); + + $request->params->size = "resize"; + $this->assert_same($photo->resize_path(), data_rest::get($request)); + + $request->params->size = "full"; + $this->assert_same($photo->file_path(), data_rest::get($request)); + } + + public function illegal_access_test() { + $album = test::random_album(); + $photo = test::random_photo($album); + $album->reload(); + + access::deny(identity::everybody(), "view", $album); + identity::set_active_user(identity::guest()); + + $request = new stdClass(); + $request->url = rest::url("data", $photo, "thumb"); + $request->params = new stdClass(); + $request->params->size = "thumb"; + + try { + data_rest::get($request); + $this->assert_true(false); + } catch (Kohana_404_Exception $e) { + // pass + } + } + + public function missing_file_test() { + $photo = test::random_photo(); + + $request = new stdClass(); + $request->url = rest::url("data", $photo, "thumb"); + $request->params = new stdClass(); + $request->params->size = "thumb"; + + unlink($photo->thumb_path()); // oops! + + try { + data_rest::get($request); + $this->assert_true(false); + } catch (Kohana_404_Exception $e) { + // pass + } + } +} -- cgit v1.2.3