/**
  * For each module, we need to see if we can actually get any data back using the query from
  * the module's query factory. Possible problem with third (fourth?) party module access code,
  * so check first to see if the generator can handle making one to test with.
  */
 public function test_module_query_factories()
 {
     global $DB;
     // Assignment module is disabled in the PHPUnit DB, so we need to re-enable it.
     $DB->set_field('modules', 'visible', 1, array('name' => 'assignment'));
     $classes = block_ajax_marking_get_module_classes();
     foreach ($classes as $modclass) {
         $modname = $modclass->get_module_name();
         // We need some submissions, but these are different for every module.
         // Without a standardised way of doing this, we will use methods in this class to do
         // the job until a better way emerges.
         $createdatamethod = 'create_' . $modname . '_submission_data';
         if (method_exists($this, $createdatamethod)) {
             // Let the modules decide what number of things should be expected. Some are more
             // complex than others.
             $expectedcount = $this->{$createdatamethod}();
             if (empty($expectedcount)) {
                 continue;
             }
         } else {
             // No point carrying on without some data to check.
             continue;
         }
         // Make query.
         $query = $modclass->query_factory();
         // We will get an error if we leave it like this as the userids in the first
         // column are not unique.
         $wrapper = new block_ajax_marking_query_base();
         $wrapper->add_select(array('function' => 'COUNT', 'column' => '*', 'alias' => 'count'));
         $wrapper->add_from(array('table' => $query, 'alias' => 'modulequery'));
         // Run query. Get one stdClass with a count property.
         $unmarkedstuff = $wrapper->execute();
         // Make sure we get the right number of things back.
         $this->assertEquals($expectedcount, reset($unmarkedstuff)->count);
         // Now make sure we have the right columns for the SQL UNION ALL.
         // We will get duplicate user ids causing problems in the first column if we
         // use standard DB functions.
         $records = $query->execute(true);
         $firstrow = $records->current();
     }
 }