예제 #1
0
 /**
  * Test that the pm_migrate_tags() function works correctly
  */
 public function test_pmmigratetags()
 {
     global $DB;
     $this->load_csv_data();
     // ELIS-7599: create bogus tag instance data (ala 1.9).
     $tag = (object) array('name' => 'bogus_tag', 'description' => 'Bogus Tag Description', 'timecreated' => 1327958800, 'timemodified' => 1327958800);
     $tagid = $DB->insert_record('local_elisprogram_tag', $tag);
     $taginstance = (object) array('instancetype' => 'cur', 'instanceid' => 999999, 'tagid' => $tagid, 'data' => '', 'timecreated' => 1327958800, 'timemodified' => 132795880);
     $DB->insert_record('local_elisprogram_tag_inst', $taginstance);
     // Migrate the legacy tag data to new ELIS fields.
     pm_migrate_tags();
     $this->assertTrue(!$DB->get_records('local_elisprogram_tag_inst', array('tagid' => $tagid)));
     // Initialize the program object.
     $program = new curriculum(1);
     $program->reset_custom_field_list();
     $program->load();
     $program = $program->to_object();
     // Get the field data from the object.
     $this->assertObjectHasAttribute('field__19upgrade_curriculum_tags', $program);
     $this->assertEquals(1, count($program->field__19upgrade_curriculum_tags));
     $this->assertEquals('Testing data', $program->field__19upgrade_curriculum_tag_data_Test_tag);
     // Let's do some extra DB-level validation (though it's probably not necessary).
     $field = $DB->get_record(field::TABLE, array('shortname' => '_19upgrade_curriculum_tags'));
     $this->assertGreaterThan(0, $field->id);
     $context = \local_elisprogram\context\program::instance($program->id);
     $this->assertTrue($DB->record_exists(field_data_char::TABLE, array('contextid' => $context->id, 'fieldid' => $field->id)));
 }
 /**
  * Validate that the provided custom field type and value produce the
  * specified error message on program update
  *
  * @param string $uitype The input control / UI type
  * @param string $value The value to use for the custom field
  * @param string $message The expected error message
  * @param array $otherparams Other parameters to give to the field owner
  * @dataProvider type_error_provider
  */
 public function test_program_update_customfield_message($uitype, $value, $message, $otherparams)
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/elisprogram/accesslib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/curriculum.class.php';
     $this->create_custom_field(CONTEXT_ELIS_PROGRAM, $uitype, $otherparams);
     // Create mapping record.
     $this->create_mapping_record('course', 'testfieldshortname', 'customtestfieldshortname');
     $program = new curriculum(array('name' => 'testprogramname', 'idnumber' => 'testprogramidnumber'));
     $program->save();
     $temp = new curriculum();
     $temp->reset_custom_field_list();
     $data = array('action' => 'update', 'context' => 'curriculum', 'idnumber' => 'testprogramidnumber', 'customtestfieldshortname' => $value);
     $message = '[course.csv line 2] Program with idnumber "testprogramidnumber" could not be updated. ' . $message . "\n";
     $this->assert_data_produces_error($data, $message, 'course');
 }
 /**
  * Create and update program custom fields
  *
  * @dataProvider ui_type_provider
  * @param string $uitype The string value representing a UI type
  * @param string $data Value for create
  * @param mixed $expected Expected value after create as a string or int
  * @param string $updateddata Value for update
  * @param mixed $updateexpected Expected value after update as string or int
  * @param string $name The name of the control
  * @param string $datatype The datatype of the field
  * @param mixed $maxlength The maxiumum length of the field as int or null
  * @param mixed $inctime Include time along with the date as string or null
  * @param mixed $options The options of the field as array or null
  */
 public function test_elis_program_custom_field_import($control, $data, $expected, $updateddata, $updateexpected, $name, $datatype, $maxlength, $inctime, $options)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elis::lib('data/customfield.class.php');
     require_once elispm::lib('data/user.class.php');
     require_once elispm::lib('data/curriculum.class.php');
     if ($control === 'datetime' && is_array($expected)) {
         $expected = rlip_timestamp($expected[0], $expected[1], $expected[2], $expected[3], $expected[4], $expected[5]);
     }
     if ($control === 'datetime' && is_array($updateexpected)) {
         $updateexpected = rlip_timestamp($updateexpected[0], $updateexpected[1], $updateexpected[2], $updateexpected[3], $updateexpected[4], $updateexpected[5]);
     }
     $fieldid = $this->create_test_field($name, $datatype, $control, $inctime, $maxlength, $options, CONTEXT_ELIS_PROGRAM);
     $temp = new curriculum();
     // Prevent caching issues.
     $temp->reset_custom_field_list();
     $record = new stdClass();
     $record->action = 'create';
     $record->context = 'curriculum';
     $record->idnumber = 'testprogramid';
     $record->name = 'testprogram';
     $record->{$name} = $data;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->process_record('course', (object) $record, 'bogus');
     $programcontext = \local_elisprogram\context\program::instance($DB->get_field(curriculum::TABLE, 'id', array('idnumber' => 'testprogramid')));
     $this->assert_field_values($datatype, $control, $fieldid, $programcontext->id, $expected);
     // Update.
     $record = new stdClass();
     $record->action = 'update';
     $record->context = 'curriculum';
     $record->idnumber = 'testprogramid';
     $record->name = 'testprogram';
     $record->{$name} = $updateddata;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->process_record('course', (object) $record, 'bogus');
     $this->assert_field_values($datatype, $control, $fieldid, $programcontext->id, $updateexpected);
 }