/** * Test to ensure that the auto-generated class ID number values do not overflow the maximum length of the * local_elisprogram_cls.idnumber field when multiple copies of the same class are created which require an incrementing iterator * to be appended to the idnumber value are used. */ public function test_trackautocreatevalidation_doesnotoverflowidnumberfieldwithiterators() { global $DB; $this->load_csv_data(); // Need track and userset. $userset = new stdClass(); $userset->id = 1; $userset->name = 'test'; // Set values required for auto create. $track = new track(5); $track->load(); // Testing track auto create. $track->track_auto_create(); // Force duplicate classes to be created which should have a unique iterator added to the idnumber field and // still be within the allowable field size. $track->track_auto_create(); $track->track_auto_create(); // Get most recent class records created. $records = $DB->get_records('local_elisprogram_cls', array(), "id DESC", 'id, idnumber', 0, 3); // We want to test in the order they were created. $records = array_reverse($records); $expectedvalue = substr('test-' . $track->idnumber, 0, 95); $iterator = 0; foreach ($records as $record) { $this->assertEquals($expectedvalue . ($iterator > 0 ? '.' . $iterator : ''), $record->idnumber); $iterator++; } }
/** * Do autocreate classes action. */ public function do_autocreate() { // TBD: display_autocreate() for error messages? $id = required_param('id', PARAM_INT); $track = new track($id); $track->track_auto_create(); $tmppage = new trackassignmentpage(array('id' => $id)); redirect($tmppage->url, get_string('track_success_autocreate', 'local_elisprogram')); }
function action_autocreate() { $id = required_param('id', PARAM_INT); $track = new track($id); $track->track_auto_create(); $tmppage = new trackassignmentpage(array('id' => $id)); redirect($tmppage->get_url(), get_string('success_autocreate', 'block_curr_admin')); }