Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 225 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

post_state_test:: (7 methods):
  setUpBeforeClass()
  test_component_names()
  components_provider()
  test_invalid_agent()
  test_post_state()
  states_provider()
  get_external_class()

extends:: (2 methods):
  validate_component()
  post_state_data()


Class: post_state_test  - X-Ref

Unit tests for xAPI post state webservice.

setUpBeforeClass()   X-Ref
Setup to ensure that fixtures are loaded.


test_component_names(string $component, ?string $expected)   X-Ref
Testing different component names on valid states.

param: string $component component name
param: string|null $expected expected results

components_provider()   X-Ref
Data provider for the test_component_names tests.

return: array

test_invalid_agent()   X-Ref
Testing invalid agent.


test_post_state(string $stateid, ?string $expected)   X-Ref
Testing valid/invalid state.

param: string $stateid The xAPI state id.
param: string|null $expected Expected results.
return: void

states_provider()   X-Ref
Data provider for the test_post_state tests.

return: array

get_external_class()   X-Ref
Return a xAPI external webservice class to operate.

The test needs to fake a component in order to test without
using a real one. This way if in the future any component
implement it's xAPI handler this test will continue working.

return: post_state the external class

Class: extends  - X-Ref

validate_component(string $component)   X-Ref
Method to override validate_component.

param: string $component  The component name in frankenstyle.

post_state_data(string $component, state $data, ?string $expected)   X-Ref
This function do all checks from a standard post_state request.

The reason for this function is because states crafting (special in error
scenarios) is complicated to do via data providers because every test need a specific
testing conditions. For this reason alls tests creates a scenario and then uses this
function to check the results.

param: string $component component name
param: state $data data to encode and send to post_state
param: string $expected expected results (if null an exception is expected)