summaryrefslogtreecommitdiff
path: root/tests/TestBaseApi.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-03-25 19:26:21 +0100
committerChristian Weiske <cweiske@cweiske.de>2011-03-25 19:26:21 +0100
commitdb71e63467a26afb8265979f8c8071935ec349b4 (patch)
treed8984f0207c90c47f10698dafd9116162eabf758 /tests/TestBaseApi.php
parentd6e99db40dc88de1782099b30941075ebc8dfa97 (diff)
downloadsemanticscuttle-db71e63467a26afb8265979f8c8071935ec349b4.tar.gz
semanticscuttle-db71e63467a26afb8265979f8c8071935ec349b4.tar.bz2
begin with ajax unittests - but they do not work yet
Diffstat (limited to 'tests/TestBaseApi.php')
-rw-r--r--tests/TestBaseApi.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index dacdecd..b7c1921 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -84,6 +84,9 @@ class TestBaseApi extends TestBase
* the request object with authentication details, so that
* the user is logged in.
*
+ * Useful for HTTP API methods only, cannot be used with
+ * "normal" HTML pages since they do not support HTTP auth.
+ *
* @param string $urlSuffix Suffix for the URL
* @param mixed $auth If user authentication is needed (true/false)
* or array with username and password
@@ -109,5 +112,38 @@ class TestBaseApi extends TestBase
return array($req, $uid);
}
+
+
+ /**
+ * Creates a user and a HTTP_Request2 object, does a normal login
+ * and prepares the cookies for the HTTP request object so that
+ * the user is seen as logged in when requesting any HTML page.
+ *
+ * Useful for testing HTML pages or ajax URLs.
+ *
+ * @param string $urlSuffix Suffix for the URL
+ * @param mixed $auth If user authentication is needed (true/false)
+ * or array with username and password
+ *
+ * @return array(HTTP_Request2, integer) HTTP request object and user id
+ *
+ * @uses getRequest()
+ */
+ protected function getLoggedInRequest($urlSuffix = null, $auth = true)
+ {
+ $req = $this->getRequest($urlSuffix);
+ if (is_array($auth)) {
+ list($username, $password) = $auth;
+ } else {
+ $username = 'testuser';
+ $password = 'testpassword';
+ }
+ $uid = $this->addUser($username, $password);
+
+ //FIXME: login via the login form, check if it worked
+ //FIXME: prepare new request with cookie
+ return array($req, $uid);
+ }
+
}
?> \ No newline at end of file