From ed455504b8131835c17c916fd0bcefe11b10709e Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 15 Feb 2013 21:25:57 -0500 Subject: [PATCH] Minor: added basic unit test cases to access class --- main/inc/lib/access_token.class.php | 44 ++++++++++++------- ..._url_edit_courses_to_url_functions.lib.php | 8 ++++ ...url_edit_sessions_to_url_functions.lib.php | 8 +++- ...ss_url_edit_users_to_url_functions.lib.php | 9 +++- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/main/inc/lib/access_token.class.php b/main/inc/lib/access_token.class.php index 03081ed8e8..683241cddf 100644 --- a/main/inc/lib/access_token.class.php +++ b/main/inc/lib/access_token.class.php @@ -35,6 +35,11 @@ class AccessToken { + /** + * Makes sure the static token exists and is a reference to an AccessToken + * object + * @assert () !== null + */ static function empty_token() { static $result = null; @@ -45,9 +50,12 @@ class AccessToken } /** - * - * @param type $string + * Parses a given string to find a token + * @param string A base64-encoded string * @return AccessToken + * @assert ('') !== null + * @assert (base64_encode('a/b')) !== null + * @assert (base64_encode('a/b/c')) !== null */ static function parse($string) { @@ -69,11 +77,12 @@ class AccessToken } /** - * - * @param int $id - * @param int $user_id - * @param string $key + * Creates a token based on an ID, an user ID and a key + * @param int ID + * @param int User id + * @param string Key * @return AccessToken + * @assert (0, 0, 'a') !== null */ static function create($id, $user_id, $key) { @@ -86,10 +95,11 @@ class AccessToken protected $key = ''; /** - * - * @param int $id - * @param int $user_id - * @param string $key + * Constructor + * @param int ID + * @param int User ID + * @param string Key + * @assert (1,1,1) === null */ function __construct($id, $user_id, $key) { @@ -100,8 +110,8 @@ class AccessToken /** * The user_api_key id. - * * @return int + * @assert () > 0 */ function get_id() { @@ -109,9 +119,9 @@ class AccessToken } /** - * User id. - * + * User id * @return string + * @assert () > 0 */ function get_user_id() { @@ -120,8 +130,8 @@ class AccessToken /** * User api key. - * * @return string + * @assert () !== null */ function get_key() { @@ -130,8 +140,8 @@ class AccessToken /** * True if the token is an empty token. I.e. a no access token. - * * @return bool + * @assert () === true */ function is_empty() { @@ -141,8 +151,8 @@ class AccessToken /** * Validate token against the database. Returns true if token is valid, * false otherwise. - * * @return boolean + * @assert () === false */ function is_valid() { @@ -171,8 +181,8 @@ class AccessToken /** * Returns a string representation of the token that can be passed in a url or a form. * The string representation can be parsed by calling AccessToken::parse(); - * * @return string + * @assert () !== null */ function __toString() { diff --git a/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php b/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php index 03fe262a1b..37619ba403 100644 --- a/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php +++ b/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php @@ -20,6 +20,14 @@ require_once ('xajax/xajax.inc.php'); */ class Accessurleditcoursestourl { + /** + * Search for a list of available courses by title or code, based on + * a given string + * @param string String to search for + * @param int Deprecated param + * @return string A formatted, xajax answer block + * @assert () === false + */ function search_courses($needle, $id) { global $tbl_course; diff --git a/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php b/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php index b7eee2edf3..88d41670ec 100644 --- a/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php +++ b/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php @@ -19,7 +19,13 @@ require_once ('xajax/xajax.inc.php'); * @author Ricardo Rodriguez - Separated the function and code */ class Accessurleditsessionstourl { - + /** + * Search sessions by name, based on a search string + * @param string Search string + * @param int Deprecated param + * @return string Xajax response block + * @assert () === false + */ function search_sessions($needle, $id) { global $tbl_session; diff --git a/main/inc/lib/access_url_edit_users_to_url_functions.lib.php b/main/inc/lib/access_url_edit_users_to_url_functions.lib.php index 90e54476c9..92cd023676 100644 --- a/main/inc/lib/access_url_edit_users_to_url_functions.lib.php +++ b/main/inc/lib/access_url_edit_users_to_url_functions.lib.php @@ -21,7 +21,14 @@ require_once ('xajax/xajax.inc.php'); */ class Accessurledituserstourl { - + /** + * Search users by username, firstname or lastname, based on the given + * search string + * @param string Search string + * @param int Deprecated param + * @return string Xajax response block + * @assert () === false + */ function search_users($needle, $id) { global $tbl_user, $tbl_access_url_rel_user;