Minor: added basic unit test cases to access class

skala
Yannick Warnier 12 years ago
parent 41bbdcef0b
commit ed455504b8
  1. 44
      main/inc/lib/access_token.class.php
  2. 8
      main/inc/lib/access_url_edit_courses_to_url_functions.lib.php
  3. 8
      main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php
  4. 9
      main/inc/lib/access_url_edit_users_to_url_functions.lib.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()
{

@ -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;

@ -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;

@ -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;

Loading…
Cancel
Save