Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Unit tests for the webservice component.

Copyright: 2016 Jun Pataleta <jun@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 342 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

webservice_test:: (6 methods):
  setUp()
  test_init_service_class()
  test_update_token_lastaccess()
  check_params()
  get_struct_info()
  in_keydesc()

webservice_dummy:: (8 methods):
  __construct()
  set_token()
  parse_request()
  send_response()
  send_error()
  run()
  get_service_methods()
  get_service_structs()


Class: webservice_test  - X-Ref

Unit tests for the webservice component.

setUp()   X-Ref
Setup.


test_init_service_class()   X-Ref
Test init_service_class().


test_update_token_lastaccess()   X-Ref
Tests update_token_lastaccess() function.


check_params($type, $methoddesc, $servicestructs)   X-Ref
Utility method that tests the parameter type of a method info's input/output parameter.

param: string $type The parameter type that is being evaluated.
param: mixed $methoddesc The method description of the WS function.
param: array $servicestructs The list of generated service struct classes.

get_struct_info($structarray, $structclass)   X-Ref
Gets the struct information from the list of struct classes based on the given struct class name.

param: array $structarray The list of generated struct classes.
param: string $structclass The name of the struct class.
return: object|null The struct class info, or null if it's not found.

in_keydesc(external_single_structure $keydesc, $propertyname)   X-Ref
Searches the keys of the given external_single_structure object if it contains a certain property name.

param: external_single_structure $keydesc
param: string $propertyname The property name to be searched for.
return: bool True if the property name is found in $keydesc. False, otherwise.

Class: webservice_dummy  - X-Ref

Class webservice_dummy.

Dummy webservice class for testing the webservice_base_server class and enable us to expose variables we want to test.

__construct($authmethod)   X-Ref
webservice_dummy constructor.

param: int $authmethod The authentication method.

set_token($token)   X-Ref
Token setter method.

param: string $token The web service token.

parse_request()   X-Ref
This method parses the request input, it needs to get:
1/ user authentication - username+password or token
2/ function name
3/ function parameters


send_response()   X-Ref
Send the result of function call to the WS client.


send_error($ex = null)   X-Ref
Send the error information to the WS client.

param: exception $ex

run()   X-Ref
run() method implementation.


get_service_methods()   X-Ref
Getter method of servicemethods array.

return: array

get_service_structs()   X-Ref
Getter method of servicestructs array.

return: array