/** * Test various methods of the menuofchoices filter. */ public function test_filter_menuofchoices() { global $DB; // Assert we get an exception if we don't specify an endpoint. try { $filter = new deepsight_filter_menuofchoices($DB, 'menu', 'Menu Of Choices', array()); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue(true); } $name = 'menu'; $label = 'Menu Of Choices'; $dataurl = 'test.php'; $filter = new deepsight_filter_menuofchoices($DB, $name, $label, array(), $dataurl); // Test setting/getting choices. $choices = array('A', 'B', 'C', 'D'); $filter->set_choices($choices); $this->assertEquals($choices, $filter->get_choices()); $jsopts = $filter->get_js_opts(); $this->assertInternalType('array', $jsopts); $this->assertArrayHasKey('name', $jsopts); $this->assertArrayHasKey('label', $jsopts); $this->assertArrayHasKey('dataurl', $jsopts); $this->assertArrayHasKey('initialchoices', $jsopts); $this->assertEquals($name, $jsopts['name']); $this->assertEquals($label, $jsopts['label']); $this->assertEquals($dataurl . '?m=filter', $jsopts['dataurl']); $expectedchoices = array(); for ($i = 0; $i < 4; $i++) { $expectedchoices[] = array('label' => $choices[$i], 'id' => $i); } $this->assertEquals($expectedchoices, $jsopts['initialchoices']); }