Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-35001 added unit test for function convert_to_array()

  • Loading branch information...
commit 093825d81ede9260427c0938ec44c4338911da2a 1 parent 7116aca
Marina Glancy marinaglancy authored

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. +23 0 lib/tests/moodlelib_test.php
23 lib/tests/moodlelib_test.php
@@ -1970,4 +1970,27 @@ public function test_delete_user() {
1970 1970 $result = delete_user($admin);
1971 1971 $this->assertFalse($result);
1972 1972 }
  1973 +
  1974 + /**
  1975 + * Test function convert_to_array()
  1976 + */
  1977 + public function test_convert_to_array() {
  1978 + // check that normal classes are converted to arrays the same way as (array) would do
  1979 + $obj = new stdClass();
  1980 + $obj->prop1 = 'hello';
  1981 + $obj->prop2 = array('first', 'second', 13);
  1982 + $obj->prop3 = 15;
  1983 + $this->assertEquals(convert_to_array($obj), (array)$obj);
  1984 +
  1985 + // check that context object (with iterator) is converted to array properly
  1986 + $obj = get_system_context();
  1987 + $ar = array(
  1988 + 'id' => $obj->id,
  1989 + 'contextlevel' => $obj->contextlevel,
  1990 + 'instanceid' => $obj->instanceid,
  1991 + 'path' => $obj->path,
  1992 + 'depth' => $obj->depth
  1993 + );
  1994 + $this->assertEquals(convert_to_array($obj), $ar);
  1995 + }
1973 1996 }

0 comments on commit 093825d

Please sign in to comment.
Something went wrong with that request. Please try again.