From f968a736cfae599562bd3e36f3e60ac1d03da136 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 9 Sep 2008 12:49:32 +0000 Subject: [PATCH] MDL-15666 database module caller unit test working (get_sha1 only) --- admin/generator.php | 19 ++++++++------ .../test_data_portfolio_callers.php | 26 ++++++++++++++++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/admin/generator.php b/admin/generator.php index d83980c6d1..a20453017b 100755 --- a/admin/generator.php +++ b/admin/generator.php @@ -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++) { diff --git a/mod/data/simpletest/test_data_portfolio_callers.php b/mod/data/simpletest/test_data_portfolio_callers.php index 5c8898a1ee..0080b57935 100644 --- a/mod/data/simpletest/test_data_portfolio_callers.php +++ b/mod/data/simpletest/test_data_portfolio_callers.php @@ -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()); } } -- 2.39.5