]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15666 database module caller unit test working (get_sha1 only)
authornicolasconnault <nicolasconnault>
Tue, 9 Sep 2008 12:49:32 +0000 (12:49 +0000)
committernicolasconnault <nicolasconnault>
Tue, 9 Sep 2008 12:49:32 +0000 (12:49 +0000)
admin/generator.php
mod/data/simpletest/test_data_portfolio_callers.php

index d83980c6d18e163f22ae5a3e90933b406a3055c0..a20453017b4d1a749d96b815d6d43a49651681ee 100755 (executable)
@@ -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++) {
 
index 5c8898a1ee2e696a63a18c8df95db7f77702fe11..0080b57935acc3d2f193350723b49b3b6157d7c3 100644 (file)
@@ -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());
     }
 
 }