MDL-31936 workshop: Improve unit tests for the course reset support
authorDavid Mudrák <david@moodle.com>
Thu, 18 Sep 2014 11:52:47 +0000 (13:52 +0200)
committerDavid Mudrák <david@moodle.com>
Mon, 6 Oct 2014 21:32:32 +0000 (23:32 +0200)
mod/workshop/tests/fixtures/testable.php
mod/workshop/tests/locallib_test.php

index 50a0906..e7e1cd3 100644 (file)
@@ -38,19 +38,4 @@ class testable_workshop extends workshop {
         parent::aggregate_grading_grades_process($assessments, $timegraded);
     }
 
-    public function reset_submissions() {
-        parent::reset_submissions();
-    }
-
-    public function reset_allocators() {
-        parent::reset_allocators();
-    }
-
-    public function reset_strategies() {
-        parent::reset_strategies();
-    }
-
-    public function reset_evaluators() {
-        parent::reset_evaulators();
-    }
 }
index 88f8b83..70900ec 100644 (file)
@@ -528,45 +528,98 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
         $this->assertEquals(array($student1->id, $student2->id), $userids);
         $users = $workshoprestricted->get_potential_authors(false, $group2->id);
         $this->assertEquals(array($student2->id), array_keys($users));
-    
-    public function test_reset_userdata() {
+    }
+
+    /**
+     * Test the workshop reset feature.
+     */
+    public function test_reset_phase() {
         $this->resetAfterTest(true);
-        // $this->workshop is the instance we can use to test.
-        $this->workshop->switch_phase(workshop::PHASE_CLOSED);    // Ensure workshop is a state that indicates work done 
+
+        $this->workshop->switch_phase(workshop::PHASE_CLOSED);
         $this->assertEquals(workshop::PHASE_CLOSED, $this->workshop->phase);
-        $originaleventcount = $DB->count_records('event', array('modulename' => 'workshop', 'instance' => $this->workshop->id));
-
-        // Setup some data
-        /*
-         * Need to :
-         * 1. Setup (already done)
-         * 2. Move to submission phase
-         * 3. Submit
-         * 4. Move to assessmetn phase.
-         * 5. Record Assess
-         * 6. Move to Evaulation phase
-         * 7. Evaluate
-         */
-        
-        // Setup reset data
-        $data = new stdClass();
-        $data->reset_workshop_all = 1;
-        $data->reset_gradebook_grades = 1;
-        $data->courseid = $this->course->id;
-        $data->timeshift = 24 * 60 * 60;
-        $this->setUser($this->editingteachers[0]);
-
-        // Get various counts.
-        $status = $this->workshop->reset_userdata($data);
-        $posteventcount = $DB->count_records('event', array('modulename' => 'workshop', 'instance' => $this->workshop->id));
-        $countaggregations = $DB->count_records('workshop_aggregations', array('workshopid' => $this->workshop->id));
-        $fs = get_file_storage();\r
-        $files = $fs->get_area_files($this->context, 'mod_workshop', 'submission_attachment', false);\r
-
-        // Check results 
-        $this->assertEquals(0, $countaggregations, 'Aggregations should be empty');
-        $this->assertEquals(workshop::PHASE_SETUP, $this->workshop->phase, 'Phase should have changed to SETUP');
-        $this->assertEquals(0, $posteventcount, 'Calendar event count should equal 0.');
-        $this->assertEqual(0, count($files), 'Number of files should be 0.');
+
+        $settings = (object)array(
+            'reset_workshop_phase' => 0,
+        );
+        $status = $this->workshop->reset_userdata($settings);
+        $this->assertEquals(workshop::PHASE_CLOSED, $this->workshop->phase);
+
+        $settings = (object)array(
+            'reset_workshop_phase' => 1,
+        );
+        $status = $this->workshop->reset_userdata($settings);
+        $this->assertEquals(workshop::PHASE_SETUP, $this->workshop->phase);
+        foreach ($status as $result) {
+            $this->assertFalse($result['error']);
+        }
+    }
+
+    /**
+     * Test deleting assessments related data on workshop reset.
+     */
+    public function test_reset_userdata_assessments() {
+        global $DB;
+        $this->resetAfterTest(true);
+
+        $student1 = $this->getDataGenerator()->create_user();
+        $student2 = $this->getDataGenerator()->create_user();
+
+        $this->getDataGenerator()->enrol_user($student1->id, $this->workshop->course->id);
+        $this->getDataGenerator()->enrol_user($student2->id, $this->workshop->course->id);
+
+        $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
+
+        $subid1 = $workshopgenerator->create_submission($this->workshop->id, $student1->id);
+        $subid2 = $workshopgenerator->create_submission($this->workshop->id, $student2->id);
+
+        $asid1 = $workshopgenerator->create_assessment($subid1, $student2->id);
+        $asid2 = $workshopgenerator->create_assessment($subid2, $student1->id);
+
+        $settings = (object)array(
+            'reset_workshop_assessments' => 1,
+        );
+        $status = $this->workshop->reset_userdata($settings);
+
+        foreach ($status as $result) {
+            $this->assertFalse($result['error']);
+        }
+
+        $this->assertEquals(2, $DB->count_records('workshop_submissions', array('workshopid' => $this->workshop->id)));
+        $this->assertEquals(0, $DB->count_records('workshop_assessments'));
+    }
+
+    /**
+     * Test deleting submissions related data on workshop reset.
+     */
+    public function test_reset_userdata_submissions() {
+        global $DB;
+        $this->resetAfterTest(true);
+
+        $student1 = $this->getDataGenerator()->create_user();
+        $student2 = $this->getDataGenerator()->create_user();
+
+        $this->getDataGenerator()->enrol_user($student1->id, $this->workshop->course->id);
+        $this->getDataGenerator()->enrol_user($student2->id, $this->workshop->course->id);
+
+        $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
+
+        $subid1 = $workshopgenerator->create_submission($this->workshop->id, $student1->id);
+        $subid2 = $workshopgenerator->create_submission($this->workshop->id, $student2->id);
+
+        $asid1 = $workshopgenerator->create_assessment($subid1, $student2->id);
+        $asid2 = $workshopgenerator->create_assessment($subid2, $student1->id);
+
+        $settings = (object)array(
+            'reset_workshop_submissions' => 1,
+        );
+        $status = $this->workshop->reset_userdata($settings);
+
+        foreach ($status as $result) {
+            $this->assertFalse($result['error']);
+        }
+
+        $this->assertEquals(0, $DB->count_records('workshop_submissions', array('workshopid' => $this->workshop->id)));
+        $this->assertEquals(0, $DB->count_records('workshop_assessments'));
     }
 }