From 59b6cd30e621ffeba55f23012e3ede42a4905e78 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 30 Mar 2010 13:53:14 -0700 Subject: Rename "user_access_tokens" table to "user_access_keys" as step 1 of a multi step process to refer to REST access keys as "access_key" everywhere. Bump the rest module to version 2. --- modules/rest/tests/Rest_Controller_Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/rest/tests/Rest_Controller_Test.php') diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 21be8300..e8b9dbd0 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -34,14 +34,14 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { // There's no access key at first $this->assert_false( - ORM::factory("user_access_token")->where("user_id", "=", $user->id)->find()->loaded()); + ORM::factory("user_access_key")->where("user_id", "=", $user->id)->find()->loaded()); $_POST["user"] = $user->name; $_POST["password"] = "password"; $response = test::call_and_capture(array(new Rest_Controller(), "index")); $expected = - ORM::factory("user_access_token")->where("user_id", "=", $user->id)->find()->access_key; + ORM::factory("user_access_key")->where("user_id", "=", $user->id)->find()->access_key; // Now there is an access key, and it was returned $this->assert_equal(json_encode($expected), $response); -- cgit v1.2.3 From ca977dce516b9e2ca9539db69fce188ed33d971c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 30 Mar 2010 14:01:40 -0700 Subject: Rename "access_token" to "access_key" in the code for consistency. --- modules/rest/controllers/rest.php | 6 +++--- modules/rest/helpers/rest.php | 8 ++++---- modules/rest/tests/Rest_Controller_Test.php | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'modules/rest/tests/Rest_Controller_Test.php') diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 9f9b9aff..29334cea 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -34,7 +34,7 @@ class Rest_Controller extends Controller { auth::login($user); - $key = rest::get_access_token($user->id); + $key = rest::get_access_key($user->id); rest::reply($key->access_key); } @@ -55,10 +55,10 @@ class Rest_Controller extends Controller { } $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method)); - $request->access_token = $input->server("HTTP_X_GALLERY_REQUEST_KEY"); + $request->access_key = $input->server("HTTP_X_GALLERY_REQUEST_KEY"); $request->url = url::abs_current(true); - rest::set_active_user($request->access_token); + rest::set_active_user($request->access_key); $handler_class = "{$function}_rest"; $handler_method = $request->method; diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index e87ee91c..49999520 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -37,13 +37,13 @@ class rest_Core { } } - static function set_active_user($access_token) { - if (empty($access_token)) { + static function set_active_user($access_key) { + if (empty($access_key)) { throw new Rest_Exception("Forbidden", 403); } $key = ORM::factory("user_access_key") - ->where("access_key", "=", $access_token) + ->where("access_key", "=", $access_key) ->find(); if (!$key->loaded()) { @@ -58,7 +58,7 @@ class rest_Core { identity::set_active_user($user); } - static function get_access_token($user_id) { + static function get_access_key($user_id) { $key = ORM::factory("user_access_key") ->where("user_id", "=", $user_id) ->find(); diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index e8b9dbd0..6d09b214 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -21,7 +21,7 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { public function setup() { $this->_save = array($_GET, $_POST, $_SERVER); - $key = rest::get_access_token(1); // admin user + $key = rest::get_access_key(1); // admin user $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $key->access_key; } @@ -82,11 +82,11 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { $_SERVER["REQUEST_METHOD"] = "GET"; $_GET["key"] = "value"; - $key = rest::get_access_token(1); // admin user + $key = rest::get_access_key(1); // admin user $this->assert_array_equal_to_json( array("params" => array("key" => "value"), "method" => "get", - "access_token" => $key->access_key, + "access_key" => $key->access_key, "url" => "http://./index.php/gallery_unit_test"), test::call_and_capture(array(new Rest_Controller(), "mock"))); } @@ -95,11 +95,11 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { $_SERVER["REQUEST_METHOD"] = "POST"; $_POST["key"] = "value"; - $key = rest::get_access_token(1); // admin user + $key = rest::get_access_key(1); // admin user $this->assert_array_equal_to_json( array("params" => array("key" => "value"), "method" => "post", - "access_token" => $key->access_key, + "access_key" => $key->access_key, "url" => "http://./index.php/gallery_unit_test"), test::call_and_capture(array(new Rest_Controller(), "mock"))); } @@ -109,11 +109,11 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "put"; $_POST["key"] = "value"; - $key = rest::get_access_token(1); // admin user + $key = rest::get_access_key(1); // admin user $this->assert_array_equal_to_json( array("params" => array("key" => "value"), "method" => "put", - "access_token" => $key->access_key, + "access_key" => $key->access_key, "url" => "http://./index.php/gallery_unit_test"), test::call_and_capture(array(new Rest_Controller(), "mock"))); } @@ -123,11 +123,11 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { $_SERVER["HTTP_X_GALLERY_REQUEST_METHOD"] = "delete"; $_POST["key"] = "value"; - $key = rest::get_access_token(1); // admin user + $key = rest::get_access_key(1); // admin user $this->assert_array_equal_to_json( array("params" => array("key" => "value"), "method" => "delete", - "access_token" => $key->access_key, + "access_key" => $key->access_key, "url" => "http://./index.php/gallery_unit_test"), test::call_and_capture(array(new Rest_Controller(), "mock"))); } -- cgit v1.2.3 From af71df3d0f6bbed29446df1801d16d28acbf927c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 17 Apr 2010 15:35:09 -0700 Subject: Update tests to reflect recent changes to the REST API. --- modules/gallery/tests/Item_Rest_Helper_Test.php | 70 ++++++++++++++----------- modules/rest/tests/Rest_Controller_Test.php | 1 + modules/tag/tests/Tag_Item_Rest_Helper_Test.php | 2 +- modules/tag/tests/Tag_Rest_Helper_Test.php | 32 +---------- modules/tag/tests/Tags_Rest_Helper_Test.php | 8 +-- 5 files changed, 49 insertions(+), 64 deletions(-) (limited to 'modules/rest/tests/Rest_Controller_Test.php') diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index bef95668..0b5e0471 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -42,13 +42,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo1), - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -56,13 +57,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo1), - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -70,14 +72,15 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array())), "members" => array( rest::url("item", $photo1), rest::url("item", $album2), rest::url("item", $photo2)), - "relationships" => array( - "tags" => array( - "url" => rest::url("item_tags", $album1), - "members" => array()))), + ), item_rest::get($request)); } @@ -96,12 +99,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $photo2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array()))), + "members" => array())), + "members" => array( + rest::url("item", $photo2)), + ), item_rest::get($request)); } @@ -118,12 +122,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), - "members" => array( - rest::url("item", $album2)), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), - "members" => array() ))), + "members" => array())), + "members" => array( + rest::url("item", $album2)), + ), item_rest::get($request)); } @@ -134,7 +139,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->title = "my new title"; + $request->params->entity = new stdClass(); + $request->params->entity->title = "my new title"; item_rest::put($request); $this->assert_equal("my new title", $album1->reload()->title); @@ -147,8 +153,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->title = "my new title"; - $request->params->slug = "not url safe"; + $request->params->entity = new stdClass(); + $request->params->entity->title = "my new title"; + $request->params->entity->slug = "not url safe"; try { item_rest::put($request); @@ -166,9 +173,10 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "album"; + $request->params->entity->name = "my album"; + $request->params->entity->title = "my album"; $response = item_rest::post($request); $new_album = rest::resolve($response["url"]); @@ -183,10 +191,11 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; - $request->params->slug = "not url safe"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "album"; + $request->params->entity->name = "my album"; + $request->params->entity->title = "my album"; + $request->params->entity->slug = "not url safe"; try { item_rest::post($request); @@ -205,8 +214,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); - $request->params->type = "photo"; - $request->params->name = "my photo.jpg"; + $request->params->entity = new stdClass(); + $request->params->entity->type = "photo"; + $request->params->entity->name = "my photo.jpg"; $request->file = MODPATH . "gallery/tests/test.jpg"; $response = item_rest::post($request); $new_photo = rest::resolve($response["url"]); diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 6d09b214..fe83283d 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -27,6 +27,7 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { public function teardown() { list($_GET, $_POST, $_SERVER) = $this->_save; + identity::set_active_user(identity::admin_user()); } public function login_test() { diff --git a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php index e5acab93..533f832d 100644 --- a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php @@ -32,7 +32,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->url = rest::url("tag_item", $tag, item::root()); $this->assert_equal_array( array("url" => rest::url("tag_item", $tag, item::root()), - "members" => array( + "entity" => array( "tag" => rest::url("tag", $tag), "item" => rest::url("item", item::root()))), tag_item_rest::get($request)); diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index f4d5a14a..a8aa89d4 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -67,41 +67,13 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { tag_rest::get($request)); } - public function post_test() { - $tag = test::random_tag(); - - // Create an editable item to be tagged - $album = test::random_album(); - access::allow(identity::everybody(), "edit", $album); - - // Add the album to the tag - $request = new stdClass(); - $request->url = rest::url("tag", $tag); - $request->params = new stdClass(); - $request->params->url = rest::url("item", $album); - $this->assert_equal_array( - array("url" => rest::url("tag_item", $tag, $album)), - tag_rest::post($request)); - } - - public function post_with_no_item_url_test() { - $request = new stdClass(); - try { - tag_rest::post($request); - } catch (Rest_Exception $e) { - $this->assert_equal(400, $e->getCode()); - return; - } - - $this->assert_true(false, "Shouldn't get here"); - } - public function put_test() { $tag = test::random_tag(); $request = new stdClass(); $request->url = rest::url("tag", $tag); $request->params = new stdClass(); - $request->params->name = "new name"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "new name"; tag_rest::put($request); $this->assert_equal("new name", $tag->reload()->name); diff --git a/modules/tag/tests/Tags_Rest_Helper_Test.php b/modules/tag/tests/Tags_Rest_Helper_Test.php index a0ebc8c3..99332c7c 100644 --- a/modules/tag/tests/Tags_Rest_Helper_Test.php +++ b/modules/tag/tests/Tags_Rest_Helper_Test.php @@ -45,11 +45,12 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { } public function post_test() { - access::allow(identity::everybody(), "edit", item::root()); + identity::set_active_user(identity::guest()); $request = new stdClass(); $request->params = new stdClass(); - $request->params->name = "test tag"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "test tag"; $this->assert_equal( array("url" => url::site("rest/tag/1")), tags_rest::post($request)); @@ -63,7 +64,8 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { try { $request = new stdClass(); $request->params = new stdClass(); - $request->params->name = "test tag"; + $request->params->entity = new stdClass(); + $request->params->entity->name = "test tag"; tags_rest::post($request); } catch (Exception $e) { $this->assert_equal(403, $e->getCode()); -- cgit v1.2.3