Skip to content
Permalink
Browse files

MDL-35001 added unit test for function convert_to_array()

  • Loading branch information...
marinaglancy committed Sep 19, 2012
1 parent 7116aca commit 093825d81ede9260427c0938ec44c4338911da2a
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/tests/moodlelib_test.php
@@ -1970,4 +1970,27 @@ public function test_delete_user() {
$result = delete_user($admin);
$this->assertFalse($result);
}
/**
* Test function convert_to_array()
*/
public function test_convert_to_array() {
// check that normal classes are converted to arrays the same way as (array) would do
$obj = new stdClass();
$obj->prop1 = 'hello';
$obj->prop2 = array('first', 'second', 13);
$obj->prop3 = 15;
$this->assertEquals(convert_to_array($obj), (array)$obj);
// check that context object (with iterator) is converted to array properly
$obj = get_system_context();
$ar = array(
'id' => $obj->id,
'contextlevel' => $obj->contextlevel,
'instanceid' => $obj->instanceid,
'path' => $obj->path,
'depth' => $obj->depth
);
$this->assertEquals(convert_to_array($obj), $ar);
}
}

0 comments on commit 093825d

Please sign in to comment.
You can’t perform that action at this time.