mirror of
https://github.com/moodle/moodle.git
synced 2025-02-15 21:36:58 +01:00
Merge branch 'MDL-25935-user_picture_fields' of git://github.com/mudrd8mz/moodle
This commit is contained in:
commit
c5ea8d0bcc
@ -237,11 +237,11 @@ class user_picture implements renderable {
|
||||
|
||||
foreach (self::$fields as $field) {
|
||||
if ($field === 'id') {
|
||||
if (isset($record->{$idalias})) {
|
||||
if (property_exists($record, $idalias)) {
|
||||
$return->id = $record->{$idalias};
|
||||
}
|
||||
} else {
|
||||
if (isset($record->{$fieldprefix.$field})) {
|
||||
if (property_exists($record, $fieldprefix.$field)) {
|
||||
$return->{$field} = $record->{$fieldprefix.$field};
|
||||
}
|
||||
}
|
||||
@ -249,7 +249,7 @@ class user_picture implements renderable {
|
||||
// add extra fields if not already there
|
||||
if ($extrafields) {
|
||||
foreach ($extrafields as $e) {
|
||||
if ($e === 'id' or isset($return->{$e})) {
|
||||
if ($e === 'id' or property_exists($return, $e)) {
|
||||
continue;
|
||||
}
|
||||
$return->{$e} = $record->{$fieldprefix.$e};
|
||||
|
@ -85,4 +85,30 @@ class user_picture_test extends UnitTestCase {
|
||||
}
|
||||
$this->assertEqual($returned->custom1, 'Value of custom1');
|
||||
}
|
||||
|
||||
public function test_user_picture_fields_unaliasing_null() {
|
||||
$fields = user_picture::fields();
|
||||
$fields = array_map('trim', explode(',', $fields));
|
||||
|
||||
$fakerecord = new stdClass();
|
||||
$fakerecord->aliasedid = 42;
|
||||
foreach ($fields as $field) {
|
||||
if ($field !== 'id') {
|
||||
$fakerecord->{'prefix'.$field} = "Value of $field";
|
||||
}
|
||||
}
|
||||
$fakerecord->prefixcustom1 = 'Value of custom1';
|
||||
$fakerecord->prefiximagealt = null;
|
||||
|
||||
$returned = user_picture::unalias($fakerecord, array('custom1'), 'aliasedid', 'prefix');
|
||||
|
||||
$this->assertEqual($returned->id, 42);
|
||||
$this->assertEqual($returned->imagealt, null);
|
||||
foreach ($fields as $field) {
|
||||
if ($field !== 'id' and $field !== 'imagealt') {
|
||||
$this->assertEqual($returned->{$field}, "Value of $field");
|
||||
}
|
||||
}
|
||||
$this->assertEqual($returned->custom1, 'Value of custom1');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user