/** * Makes sure we can get one node only for when the counts will have changed due to a settings tweak. * */ public function test_get_count_for_single_node() { // Make all the test data and get a total count back. $this->make_module_submissions(); // Make sure the current user is a teacher in the course. $this->setUser(key($this->teachers)); $filters = array(); $filters['currentfilter'] = 'courseid'; $filters['filtervalue'] = $this->course->id; $node = block_ajax_marking_nodes_builder::get_count_for_single_node($filters); $message = "Wrong number of things returned as the count for a single node. Expected {$this->submissioncount} " . "but got {$node['itemcount']}"; $this->assertEquals($this->submissioncount, $node['itemcount'], $message); }
require_once dirname(__FILE__) . '/../../../config.php'; // For unit tests to work. global $CFG, $PAGE; require_once $CFG->dirroot . '/blocks/ajax_marking/lib.php'; require_once $CFG->dirroot . '/blocks/ajax_marking/classes/module_base.class.php'; require_once $CFG->dirroot . '/blocks/ajax_marking/classes/nodes_builder.class.php'; block_ajax_marking_login_error(); require_login(0, false); // TODO might be in a course. $PAGE->set_context(context_system::instance()); // Each ajax request will have different stuff that we want to pass to the callback function. Using // required_param() means hard-coding them. $params = array(); foreach ($_POST as $name => $value) { $params[$name] = clean_param($value, PARAM_ALPHANUMEXT); } if (!isset($params['currentfilter'])) { print_error('No filter specified for node count'); die; } if (!isset($params['filtervalue'])) { print_error('No filter value specified for node count'); die; } if (!isset($params['nodeindex'])) { print_error('No node index specified for the count'); die; } $nodecounts = block_ajax_marking_nodes_builder::get_count_for_single_node($params); $data = array('counts' => $nodecounts, 'nodeindex' => $params['nodeindex']); echo json_encode($data);