mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-44725 Availability: Add utility API to make unit testing easier (7)
Previously there was no way in PHP to create the JSON values used for availability, except by manually hard-coding them (the main code to do this normally is in JavaScript). This makes unit tests hard to read, so I have implemented static functions tree::get_root_json and tree::get_nested_json which allow for easier-to-read unit tests.
This commit is contained in:
parent
9c85baa8c5
commit
f9103882dc
4 changed files with 243 additions and 102 deletions
|
@ -239,4 +239,23 @@ class condition extends \core_availability\condition {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON object which corresponds to a condition of this type.
|
||||
*
|
||||
* Intended for unit testing, as normally the JSON values are constructed
|
||||
* by JavaScript code.
|
||||
*
|
||||
* @param int $groupingid Required grouping id (0 = grouping linked to activity)
|
||||
* @return stdClass Object representing condition
|
||||
*/
|
||||
public static function get_json($groupingid = 0) {
|
||||
$result = (object)array('type' => 'grouping');
|
||||
if ($groupingid) {
|
||||
$result->id = (int)$groupingid;
|
||||
} else {
|
||||
$result->activity = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue