Permalink
Browse files

MDL-25935 user_picture::unalias() now handles null values correctly

  • Loading branch information...
1 parent 5c0d03e commit 9ecbf8018fd96750dcdee83d22996c090be44519 @mudrd8mz mudrd8mz committed Jan 10, 2011
Showing with 29 additions and 3 deletions.
  1. +3 −3 lib/outputcomponents.php
  2. +26 −0 lib/simpletest/testoutputcomponents.php
View
@@ -237,19 +237,19 @@ public static function unalias(stdClass $record, array $extrafields=null, $idali
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};
}
}
}
// 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 @@ public function test_user_picture_fields_unaliasing() {
}
$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');
+ }
}

0 comments on commit 9ecbf80

Please sign in to comment.