From 8bf73d4b4c5e609cd4bc9b6ea54d32faeefef19b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 20 Jan 2010 00:52:32 -0800 Subject: New test for tags_rest.php --- modules/tag/tests/Tags_Rest_Helper_Test.php | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 modules/tag/tests/Tags_Rest_Helper_Test.php (limited to 'modules') diff --git a/modules/tag/tests/Tags_Rest_Helper_Test.php b/modules/tag/tests/Tags_Rest_Helper_Test.php new file mode 100644 index 00000000..dd922013 --- /dev/null +++ b/modules/tag/tests/Tags_Rest_Helper_Test.php @@ -0,0 +1,68 @@ +query("TRUNCATE {tags}"); + Database::instance()->query("TRUNCATE {items_tags}"); + } catch (Exception $e) { } + $this->_save = array($_GET, $_POST, $_SERVER); + } + + public function teardown() { + list($_GET, $_POST, $_SERVER) = $this->_save; + } + + public function get_test() { + tag::add(item::root(), "t1"); + tag::add(item::root(), "t2"); + + $request = new stdClass(); + $this->assert_equal_array( + array( + "members" => array( + "t1" => rest::url("tag", ORM::factory("tag")->where("name", "=", "t1")->find()), + "t2" => rest::url("tag", ORM::factory("tag")->where("name", "=", "t2")->find()))), + tags_rest::get($request)); + } + + public function post_test() { + access::allow(identity::everybody(), "edit", item::root()); + + $request->params->name = "test tag"; + $this->assert_equal( + array("url" => url::site("rest/tag/test%20tag")), + tags_rest::post($request)); + } + + public function post_fails_without_permissions_test() { + access::deny(identity::everybody(), "edit", item::root()); + + try { + $request->params->name = "test tag"; + tags_rest::post($request); + } catch (Exception $e) { + $this->assert_equal(403, $e->getCode()); + return; + } + $this->assert_true(false, "Shouldnt get here"); + } + +} -- cgit v1.2.3