public $modules_to_ignore = array('hotpot', 'lams', 'journal', 'scorm', 'exercise', 'dialogue');
public $modules_list = array('forum' => 'forum',
'assignment' => 'assignment',
+ 'data' => 'data',
'glossary' => 'glossary',
'quiz' => 'quiz',
'comments' => 'comments',
array('short'=>'pd', 'long' => 'posts_per_discussion',
'help' => 'The number of posts to generate for each forum discussion. Default=15',
'type'=>'NUMBER', 'default' => 15),
+ array('short'=>'fd', 'long' => 'fields_per_database',
+ 'help' => 'The number of fields to generate for each database. Default=4',
+ 'type'=>'NUMBER', 'default' => 4),
+ array('short'=>'drs', 'long' => 'database_records_per_student',
+ 'help' => 'The number of records to generate for each student/database tuple. Default=1',
+ 'type'=>'NUMBER', 'default' => 1),
);
foreach ($arguments as $args_array) {
$module->schedule = 1;
$module->chattime = 60 * 60 * 4;
break;
+ case 'data':
+ $module->intro = $description;
+ $module->name = 'test';
+ break;
case 'choice':
$module->text = $content;
$module->option = array('Good choice', 'Bad choice', 'No choice');
public function generate_module_content($course_users, $courses, $modules) {
global $USER, $DB, $CFG;
+ $result = null;
$entries_count = 0;
if ($this->get('entries_per_glossary') && !empty($modules['glossary'])) {
if ($entries_count > 0 && !$this->get('quiet')) {
echo "$entries_count glossary definitions have been generated.{$this->eolchar}";
}
- return true;
+ $result = true;
}
- return null;
+
+ $fields_count = 0;
+ if ($this->get('fields_per_database') && $this->get('database_records_per_student')) {
+ $database_field_types = array('checkbox',
+ 'date',
+ 'file',
+ 'latlong',
+ 'menu',
+ 'multimenu',
+ 'number',
+ 'picture',
+ 'radiobutton',
+ 'text',
+ '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 = $newfield(0, $data, true);
+ $fields[] = $newfield;
+ }
+
+ foreach ($modules['data'] as $data) {
+
+ // Generate fields for each database (same fields for all, no arguing)
+ for ($i = 0; $i < $this->get('fields_per_database'); $i++) {
+
+ }
+
+ // Generate database records for each student, if needed
+ for ($i = 0; $i < $this->get('database_records_per_student'); $i++) {
+
+ }
+ }
+ if ($fields_count > 0 && !$this->get('quiet')) {
+ $datacount = count($modules['data']);
+ echo "$fields_count database fields have been generated for each of the "
+ . "$datacount generated databases.{$this->eolchar}";
+ }
+ $result = true;
+ }
+
+ return $result;
}
/**
--- /dev/null
+<?php // $Id$
+require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
+require_once($CFG->dirroot.'/mod/data/lib.php');
+require_once($CFG->dirroot.'/admin/generator.php');
+
+Mock::generate('data_portfolio_caller', 'mock_caller');
+Mock::generate('portfolio_exporter', 'mock_exporter');
+
+class testDataPortfolioCallers extends portfoliolib_test {
+ public $module_type = 'data';
+ public $modules = array();
+ public $entries = array();
+ public $caller;
+
+ public function setUp() {
+ global $DB, $USER;
+
+ parent::setUp();
+
+ $settings = array('quiet' => 1,
+ 'database_prefix' => 'tst_',
+ 'pre_cleanup' => 0,
+ 'modules_list' => array($this->module_type),
+ 'number_of_students' => 5,
+ 'students_per_course' => 5,
+ 'number_of_sections' => 1,
+ 'number_of_modules' => 1,
+ 'questions_per_course' => 0);
+
+ generator_generate_data($settings);
+
+ $this->modules = $DB->get_records($this->module_type);
+ $first_module = reset($this->modules);
+ $cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
+
+ // Callback args required: id, record, delimiter_name, exporttype
+
+ $callbackargs = array('assignmentid' => $cm->id, 'userid' => $USER->id);
+ $this->caller = new assignment_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() {
+ parent::tearDown();
+ }
+
+ public function test_caller_sha1() {
+ $sha1 = $this->caller->get_sha1();
+ $this->caller->prepare_package();
+ $this->assertEqual($sha1, $this->caller->get_sha1());
+ }
+
+}
+?>
--- /dev/null
+<?php // $Id$
+require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
+require_once($CFG->dirroot.'/mod/forum/lib.php');
+require_once($CFG->dirroot.'/admin/generator.php');
+
+Mock::generate('forum_portfolio_caller', 'mock_caller');
+Mock::generate('portfolio_exporter', 'mock_exporter');
+
+class testForumPortfolioCallers extends portfoliolib_test {
+ public $module_type = 'forum';
+ public $modules = array();
+ public $entries = array();
+ public $caller;
+
+ public function setUp() {
+ global $DB, $USER;
+
+ parent::setUp();
+
+ $settings = array('quiet' => 1,
+ 'verbose' => 0,
+ 'database_prefix' => 'tst_',
+ 'pre_cleanup' => 0,
+ 'post_cleanup' => 0,
+ 'modules_list' => array($this->module_type),
+ 'discussions_per_forum' => 5,
+ 'posts_per_discussion' => 10,
+ 'number_of_students' => 5,
+ 'students_per_course' => 5,
+ 'number_of_sections' => 1,
+ 'number_of_modules' => 1,
+ 'questions_per_course' => 0);
+
+ generator_generate_data($settings);
+
+ $this->modules = $DB->get_records($this->module_type);
+ $first_module = reset($this->modules);
+ $cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
+
+ $discussions = $DB->get_records('forum_discussions', array('forum' => $first_module->id));
+ $first_discussion = reset($discussions);
+
+ $posts = $DB->get_records('forum_posts', array('discussion' => $first_discussion->id));
+ $first_post = reset($posts);
+
+ $callbackargs = array('postid' => $first_post->id, 'discussionid' => $first_discussion->id);
+ $this->caller = new forum_portfolio_caller($callbackargs);
+ $this->caller->set('exporter', new mock_exporter());
+ $user = $DB->get_record('user', array('id' => $first_post->userid));
+ $this->caller->set('user', $user);
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+ }
+
+ public function test_caller_sha1() {
+ $sha1 = $this->caller->get_sha1();
+ $this->caller->prepare_package();
+ $this->assertEqual($sha1, $this->caller->get_sha1());
+ }
+
+}
+?>