MDL-15666 database module caller unit test working (get_sha1 only)
This commit is contained in:
+11
-8
@@ -925,7 +925,7 @@ class generator {
|
||||
}
|
||||
|
||||
$fields_count = 0;
|
||||
if ($this->get('fields_per_database') && $this->get('database_records_per_student')) {
|
||||
if (!empty($modules['data']) && $this->get('fields_per_database') && $this->get('database_records_per_student')) {
|
||||
$database_field_types = array('checkbox',
|
||||
'date',
|
||||
'file',
|
||||
@@ -939,17 +939,20 @@ class generator {
|
||||
'textarea',
|
||||
'url');
|
||||
|
||||
|
||||
$fields = array();
|
||||
for ($i = 0; $i < $this->get('fields_per_database'); $i++) {
|
||||
$type = $database_field_types[array_rand($database_field_types)];
|
||||
require_once($CFG->dirroot.'/mod/data/field/'.$type.'/field.class.php');
|
||||
$newfield = 'data_field_'.$type;
|
||||
$newfield = new $newfield(0, $data, true);
|
||||
$fields[] = $newfield;
|
||||
}
|
||||
|
||||
foreach ($modules['data'] as $data) {
|
||||
|
||||
for ($i = 0; $i < $this->get('fields_per_database'); $i++) {
|
||||
$type = $database_field_types[array_rand($database_field_types)];
|
||||
require_once($CFG->dirroot.'/mod/data/field/'.$type.'/field.class.php');
|
||||
$newfield = 'data_field_'.$type;
|
||||
$newfield = new $newfield(0, $data, true);
|
||||
$fields[$data->id][] = $newfield;
|
||||
$newfield->insert_field();
|
||||
}
|
||||
|
||||
// Generate fields for each database (same fields for all, no arguing)
|
||||
for ($i = 0; $i < $this->get('fields_per_database'); $i++) {
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ class testDataPortfolioCallers extends portfoliolib_test {
|
||||
public $module_type = 'data';
|
||||
public $modules = array();
|
||||
public $entries = array();
|
||||
public $caller_single;
|
||||
public $caller;
|
||||
|
||||
public function setUp() {
|
||||
@@ -33,13 +34,26 @@ class testDataPortfolioCallers extends portfoliolib_test {
|
||||
$first_module = reset($this->modules);
|
||||
$cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
|
||||
|
||||
$fields = $DB->get_records('data_fields', array('dataid' => $first_module->id));
|
||||
$recordid = data_add_record($first_module);
|
||||
foreach ($fields as $field) {
|
||||
$content->recordid = $recordid;
|
||||
$content->fieldid = $field->id;
|
||||
$content->content = 'test content';
|
||||
$content->content1 = 'test content 1';
|
||||
$content->content2 = 'test content 2';
|
||||
$DB->insert_record('data_content',$content);
|
||||
}
|
||||
|
||||
// Callback args required: id, record, delimiter_name, exporttype
|
||||
|
||||
$callbackargs = array('assignmentid' => $cm->id, 'userid' => $USER->id);
|
||||
$this->caller = new assignment_portfolio_caller($callbackargs);
|
||||
$callbackargs = array('id' => $cm->id, 'record' => $recordid);
|
||||
$this->caller_single = new data_portfolio_caller($callbackargs);
|
||||
$this->caller_single->set('exporter', new mock_exporter());
|
||||
|
||||
unset($callbackargs['record']);
|
||||
$this->caller = new data_portfolio_caller($callbackargs);
|
||||
$this->caller->set('exporter', new mock_exporter());
|
||||
$user = $DB->get_record('user', array('id' => $first_submission->userid));
|
||||
$this->caller->set('user', $user);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
@@ -50,6 +64,10 @@ class testDataPortfolioCallers extends portfoliolib_test {
|
||||
$sha1 = $this->caller->get_sha1();
|
||||
$this->caller->prepare_package();
|
||||
$this->assertEqual($sha1, $this->caller->get_sha1());
|
||||
|
||||
$sha1 = $this->caller_single->get_sha1();
|
||||
$this->caller_single->prepare_package();
|
||||
$this->assertEqual($sha1, $this->caller_single->get_sha1());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user