diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-06-07 23:12:52 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-06-07 23:12:52 -0700 |
commit | 6425d41eddd44091b2d83ba3c3734cc6990ca581 (patch) | |
tree | 94c6ad398edb6a72879b17772aab5670a1371b84 /modules/gallery/tests | |
parent | 98fce83de5f772482382bfabdbcd94c25ecdbb1a (diff) |
Add a "preserve_ids" global query parameter for REST requests that
indicates that we shouldn't opportunistically convert ids into REST
urls.
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r-- | modules/gallery/tests/Item_Model_Test.php | 4 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Rest_Helper_Test.php | 21 | ||||
-rw-r--r-- | modules/gallery/tests/Items_Rest_Helper_Test.php | 35 |
3 files changed, 42 insertions, 18 deletions
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 9d3f54f2..6c5882c4 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -357,7 +357,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(); + $result = $album->as_restful_array(false); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); @@ -369,7 +369,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(false); + $result = $album->as_restful_array(true); $this->assert_same(item::root()->id, $result["parent_id"]); $this->assert_same($photo->id, $result["album_cover_item_id"]); $this->assert_true(!array_key_exists("parent", $result)); diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 0b5e0471..5a80d66b 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -28,6 +28,17 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal($album->id, $resolved->id); } + public function get_with_ids_test() { + $photo1 = test::random_photo(item::root()); + $request = new stdClass(); + $request->url = rest::url("item", $photo1); + $request->params = new stdClass(); + $request->params->preserve_ids = 1; + + $response = item_rest::get($request); + $this->assert_equal(item::root()->id, $response["entity"]["parent_id"]); // Spot check + } + public function get_scope_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); @@ -41,7 +52,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -56,7 +67,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -71,7 +82,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -98,7 +109,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -121,7 +132,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 94bf912a..3efd677d 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -34,13 +34,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -67,7 +67,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -94,7 +94,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), @@ -119,13 +119,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -146,7 +146,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $root = ORM::factory("item", 1); $restful_root = array( "url" => rest::url("item", $root), - "entity" => $root->as_restful_array(), + "entity" => $root->as_restful_array(false), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { @@ -155,12 +155,12 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestor_for = rest::url("item", $photo2); + $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -170,7 +170,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2)), ), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -178,11 +178,24 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), - "entity" => $photo2->as_restful_array(), + "entity" => $photo2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); } + + public function get_ancestor_with_ids_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->ancestors_for = rest::url("item", $photo1); + $request->params->preserve_ids = 1; + + $response = items_rest::get($request); + $this->assert_same(item::root()->id, $response[1]["entity"]["parent_id"]); // Spot check + } } |