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:
sam marshall 2014-08-26 18:07:16 +01:00
parent 9c85baa8c5
commit f9103882dc
4 changed files with 243 additions and 102 deletions

View file

@ -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;
}
}