Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-35001 added unit test for function convert_to_array()

  • Loading branch information...
commit 093825d81ede9260427c0938ec44c4338911da2a 1 parent 7116aca
@marinaglancy marinaglancy authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/tests/moodlelib_test.php
View
23 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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.