summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-20 00:08:13 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-20 00:08:13 -0800
commit5f83da41e405dd274634fa520c5c08bfd885164a (patch)
tree6f4334a371096a178bfa3547a34c6fdc30dd9796
parent5119d58e7ff06e1ba922d73bf47aefd242dc888f (diff)
Rewrite the tests to be simpler and more direct.
-rw-r--r--modules/rest/tests/Rest_Controller_Test.php133
1 files changed, 68 insertions, 65 deletions
diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php
index e0663252..377f5334 100644
--- a/modules/rest/tests/Rest_Controller_Test.php
+++ b/modules/rest/tests/Rest_Controller_Test.php
@@ -59,84 +59,87 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case {
$this->assert_true(false, "Shouldn't get here");
}
- public function rest_get_resource_no_request_key_test_() {
+ public function get_test() {
$_SERVER["REQUEST_METHOD"] = "GET";
- $photo = $this->_create_image();
-
- $this->assert_equal(
- json_encode(array("status" => "OK", "message" => (string)t("Processed"),
- "photo" => array("path" => $photo->relative_url(),
- "title" => $photo->title,
- "thumb_url" => $photo->thumb_url(),
- "description" => $photo->description,
- "internet_address" => $photo->slug))),
- $this->_call_controller("rest", explode("/", $photo->relative_url())));
+ $_GET["key"] = "value";
+
+ $this->assert_array_equal_to_json(
+ array("params" => array("key" => "value"),
+ "method" => "get",
+ "access_token" => null,
+ "url" => "http://./index.php/gallery_unit_test"),
+ test::call_and_capture(array(new Rest_Controller(), "mock")));
}
- public function rest_get_resource_invalid_key_test_() {
- list ($access_key, $user) = $this->_create_user();
- $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = md5($access_key); // screw up the access key;
- $_SERVER["REQUEST_METHOD"] = "GET";
+ public function get_with_access_key_test() {
+ $key = rest::get_access_token(1); // admin user
- try {
- $this->_call_controller();
- } catch (Rest_Exception $e) {
- $this->assert_equal(403, $e->getCode());
- $this->assert_equal("Forbidden", $e->getMessage());
- } catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
- }
- }
-
- public function rest_get_resource_no_user_for_key_test_() {
- list ($access_key, $user) = $this->_create_user();
$_SERVER["REQUEST_METHOD"] = "GET";
- $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key;
+ $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $key->access_key;
+ $_GET["key"] = "value";
+
+ $this->assert_array_equal_to_json(
+ array("params" => array("key" => "value"),
+ "method" => "get",
+ "access_token" => $key->access_key,
+ "url" => "http://./index.php/gallery_unit_test"),
+ test::call_and_capture(array(new Rest_Controller(), "mock")));
+ }
- $user->delete();
+ public function post_test() {
+ $_SERVER["REQUEST_METHOD"] = "POST";
+ $_POST["key"] = "value";
- $photo = $this->_create_image();
+ $this->assert_array_equal_to_json(
+ array("params" => array("key" => "value"),
+ "method" => "post",
+ "access_token" => null,
+ "url" => "http://./index.php/gallery_unit_test"),
+ test::call_and_capture(array(new Rest_Controller(), "mock")));
+ }
- try {
- $this->_call_controller("rest", explode("/", $photo->relative_url()));
- } catch (Rest_Exception $e) {
- $this->assert_equal(403, $e->getCode());
- $this->assert_equal("Forbidden", $e->getMessage());
- } catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
- }
+ public function put_test() {
+ $_SERVER["REQUEST_METHOD"] = "POST";
+ $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "put";
+ $_POST["key"] = "value";
+
+ $this->assert_array_equal_to_json(
+ array("params" => array("key" => "value"),
+ "method" => "put",
+ "access_token" => null,
+ "url" => "http://./index.php/gallery_unit_test"),
+ test::call_and_capture(array(new Rest_Controller(), "mock")));
}
- public function rest_get_resource_no_handler_test_() {
- list ($access_key, $user) = $this->_create_user();
- $_SERVER["REQUEST_METHOD"] = "GET";
- $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key;
- $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "PUT";
- $photo = $this->_create_image();
+ public function delete_test() {
+ $_SERVER["REQUEST_METHOD"] = "POST";
+ $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "delete";
+ $_POST["key"] = "value";
+
+ $this->assert_array_equal_to_json(
+ array("params" => array("key" => "value"),
+ "method" => "delete",
+ "access_token" => null,
+ "url" => "http://./index.php/gallery_unit_test"),
+ test::call_and_capture(array(new Rest_Controller(), "mock")));
+ }
+ public function bogus_method_test() {
+ $_SERVER["REQUEST_METHOD"] = "POST";
+ $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "BOGUS";
try {
- $this->_call_controller("rest", explode("/", $photo->relative_url()));
- } catch (Rest_Exception $e) {
- $this->assert_equal(501, $e->getCode());
- $this->assert_equal("Not Implemented", $e->getMessage());
+ test::call_and_capture(array(new Rest_Controller(), "mock"));
} catch (Exception $e) {
- $this->assert_false(true, $e->__toString());
+ $this->assert_equal(403, $e->getCode());
+ return;
}
- }
-
- public function rest_get_resource_test_() {
- list ($access_key, $user) = $this->_create_user();
- $_SERVER["REQUEST_METHOD"] = "GET";
- $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key;
-
- $photo = $this->_create_image();
- $this->assert_equal(
- json_encode(array("status" => "OK", "message" => (string)t("Processed"),
- "photo" => array("path" => $photo->relative_url(),
- "title" => $photo->title,
- "thumb_url" => $photo->thumb_url(),
- "description" => $photo->description,
- "internet_address" => $photo->slug))),
- $this->_call_controller("rest", explode("/", $photo->relative_url())));
+ $this->assert_true(false, "Shouldn't get here");
}
}
+
+class mock_rest {
+ function get($request) { return $request; }
+ function post($request) { return $request; }
+ function put($request) { return $request; }
+ function delete($request) { return $request; }
+} \ No newline at end of file