Skip to content

Commit

Permalink
Merge branch 'MDL-25935-user_picture_fields' of git://github.com/mudr…
Browse files Browse the repository at this point in the history
…d8mz/moodle
  • Loading branch information
Sam Hemelryk committed Jan 17, 2011
2 parents 5a7f931 + 9ecbf80 commit c5ea8d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
26 changes: 26 additions & 0 deletions lib/simpletest/testoutputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 c5ea8d0

Please sign in to comment.