This commit is contained in:
Shamim Rezaie
2021-10-29 00:10:24 +11:00
3 changed files with 19 additions and 2 deletions
+2 -1
View File
@@ -403,7 +403,8 @@ abstract class persistent {
* @return static
*/
final public function from_record(stdClass $record) {
$record = (array) $record;
$properties = static::properties_definition();
$record = array_intersect_key((array) $record, $properties);
foreach ($record as $property => $value) {
$this->raw_set($property, $value);
}
+16 -1
View File
@@ -207,11 +207,26 @@ class core_persistent_testcase extends advanced_testcase {
public function test_from_record_invalid_param() {
$p = new core_testable_persistent();
$data = (object) array(
'shortname' => 'ddd',
'idnumber' => 'abc',
'description' => 'xyz',
'descriptionformat' => FORMAT_PLAIN,
'parentid' => 999,
'path' => '/a/b/c',
'sortorder' => 12,
'id' => 1,
'timecreated' => 2,
'timemodified' => 3,
'usermodified' => 4,
'scaleid' => null,
'invalidparam' => 'abc'
);
$this->expectException(coding_exception::class);
$p->from_record($data);
// Previous call should succeed, assert we get back all data except invalid param.
unset($data->invalidparam);
$this->assertEquals($data, $p->to_record());
}
public function test_validate() {
+1
View File
@@ -104,6 +104,7 @@ completely removed from Moodle core too.
fixed units), to always include a non-breaking space between the number and unit, and to use
consistent rounding (always 1 decimal place by default).
* The persistent method get() now returns the correct type for each property defined in the persistent class.
* The persistent method from_record() now only attempts to load record properties defined in the persistent class.
* Require pass grade criteria is now part of core.
Refer to upgrade.php to see transitioning from similar plugin criteria to core
Refer to completion/upgrade.txt for additional information.