Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

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: 382 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

webservice_test:: (8 methods):
  setUp()
  test_init_service_class()
  test_update_token_lastaccess()
  get_active_tokens_provider()
  test_get_active_tokens()
  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.


get_active_tokens_provider()   X-Ref
Data provider for {@see test_get_active_tokens}

return: array

test_get_active_tokens(int $validuntil, bool $expectedactive)   X-Ref
Test getting active tokens for a user

param: int $validuntil
param: bool $expectedactive

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