Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

Unit Tests for sitepolicy manager

Copyright: 2018 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 384 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes


Class: sitepolicy_test  - X-Ref

Unit Tests for sitepolicy manager

test_get_handler_classname()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_handler_classname() behaviour.


test_is_defined()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::is_defined()


test_get_redirect_url()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url()


test_get_embed_url()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url()


test_accept()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url()


test_accept_guests()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url() for guests


get_mock_manager_with_handler()   X-Ref
Helper to spoof the results of the internal function get_all_handlers, allowing mock handler to be tested.

return: PHPUnit_Framework_MockObject_MockObject

test_is_defined_with_handler()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::is_defined() with a handler


test_get_redirect_url_with_handler()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url() with a handler


test_get_embed_url_with_handler()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url() with a handler


test_accept_with_handler()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url() with a handler


test_accept_guests_with_handler()   X-Ref
Tests for \core_privacy\local\sitepolicy\manager::get_redirect_url() for guests with a handler


Class: handler  - X-Ref

Mock handler for site policies

is_defined($forguests = false)   X-Ref
Checks if the site has site policy defined

param: bool $forguests
return: bool

get_redirect_url($forguests = false)   X-Ref
Returns URL to redirect user to when user needs to agree to site policy

This is a regular interactive page for web users. It should have normal Moodle header/footers, it should
allow user to view policies and accept them.

param: bool $forguests
return: moodle_url|null (returns null if site policy is not defined)

get_embed_url($forguests = false)   X-Ref
Returns URL of the site policy that needs to be displayed to the user (inside iframe or to use in WS such as mobile app)

This page should not have any header/footer, it does not also have any buttons/checkboxes. The caller needs to implement
the "Accept" button and call {@link self::accept()} on completion.

param: bool $forguests
return: moodle_url|null

accept()   X-Ref
Accept site policy for the current user

return: bool - false if sitepolicy not defined, user is not logged in or user has already agreed to site policy;