Skip to content

Commit

Permalink
Update tests to reflect recent changes to the REST API.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Apr 17, 2010
1 parent 10f849c commit af71df3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 64 deletions.
70 changes: 40 additions & 30 deletions modules/gallery/tests/Item_Rest_Helper_Test.php
Expand Up @@ -42,42 +42,45 @@ public function get_scope_test() {
$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);
$request->params->scope = "direct";
$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);
$request->params->scope = "all";
$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));
}

Expand All @@ -96,12 +99,13 @@ public function get_children_like_test() {
$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));
}

Expand All @@ -118,12 +122,13 @@ public function get_children_type_test() {
$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));
}

Expand All @@ -134,7 +139,8 @@ public function update_album_test() {
$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);
Expand All @@ -147,8 +153,9 @@ public function update_album_illegal_value_fails_test() {
$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);
Expand All @@ -166,9 +173,10 @@ public function add_album_test() {
$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"]);

Expand All @@ -183,10 +191,11 @@ public function add_album_illegal_value_fails_test() {
$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);
Expand All @@ -205,8 +214,9 @@ public function add_photo_test() {
$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"]);
Expand Down
1 change: 1 addition & 0 deletions modules/rest/tests/Rest_Controller_Test.php
Expand Up @@ -27,6 +27,7 @@ public function setup() {

public function teardown() {
list($_GET, $_POST, $_SERVER) = $this->_save;
identity::set_active_user(identity::admin_user());
}

public function login_test() {
Expand Down
2 changes: 1 addition & 1 deletion modules/tag/tests/Tag_Item_Rest_Helper_Test.php
Expand Up @@ -32,7 +32,7 @@ public function get_test() {
$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));
Expand Down
32 changes: 2 additions & 30 deletions modules/tag/tests/Tag_Rest_Helper_Test.php
Expand Up @@ -67,41 +67,13 @@ public function get_with_no_relationships_test() {
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);
Expand Down
8 changes: 5 additions & 3 deletions modules/tag/tests/Tags_Rest_Helper_Test.php
Expand Up @@ -45,11 +45,12 @@ public function get_test() {
}

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));
Expand All @@ -63,7 +64,8 @@ public function post_fails_without_permissions_test() {
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());
Expand Down

0 comments on commit af71df3

Please sign in to comment.