Permalink
Browse files

Merge branch 'MDL-30865-workshop-unittest_22_STABLE' of git://github.…

…com/mudrd8mz/moodle into MOODLE_22_STABLE
  • Loading branch information...
2 parents dbc7d20 + 7d8c4fb commit aed7f3278386078a39e7981502270a1806eeecd9 @stronk7 stronk7 committed Jan 4, 2012
Showing with 16 additions and 9 deletions.
  1. +8 −3 mod/workshop/locallib.php
  2. +8 −6 mod/workshop/simpletest/testlocallib.php
View
@@ -2018,9 +2018,10 @@ protected function aggregate_submission_grades_process(array $assessments) {
* was overridden by a teacher, the gradinggradeover value is returned and the rest of grades are ignored.
*
* @param array $assessments of stdclass(->reviewerid ->gradinggrade ->gradinggradeover ->aggregationid ->aggregatedgrade)
+ * @param null|int $timegraded explicit timestamp of the aggregation, defaults to the current time
* @return void
*/
- protected function aggregate_grading_grades_process(array $assessments) {
+ protected function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
global $DB;
$reviewerid = null; // the id of the reviewer being processed
@@ -2030,6 +2031,10 @@ protected function aggregate_grading_grades_process(array $assessments) {
$sumgrades = 0;
$count = 0;
+ if (is_null($timegraded)) {
+ $timegraded = time();
+ }
+
foreach ($assessments as $assessment) {
if (is_null($reviewerid)) {
// the id is the same in all records, fetch it during the first loop cycle
@@ -2066,13 +2071,13 @@ protected function aggregate_grading_grades_process(array $assessments) {
$record->workshopid = $this->id;
$record->userid = $reviewerid;
$record->gradinggrade = $finalgrade;
- $record->timegraded = time();
+ $record->timegraded = $timegraded;
$DB->insert_record('workshop_aggregations', $record);
} else {
$record = new stdclass();
$record->id = $agid;
$record->gradinggrade = $finalgrade;
- $record->timegraded = time();
+ $record->timegraded = $timegraded;
$DB->update_record('workshop_aggregations', $record);
}
}
@@ -47,8 +47,8 @@ public function aggregate_submission_grades_process(array $assessments) {
parent::aggregate_submission_grades_process($assessments);
}
- public function aggregate_grading_grades_process(array $assessments) {
- parent::aggregate_grading_grades_process($assessments);
+ public function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
+ parent::aggregate_grading_grades_process($assessments, $timegraded);
}
}
@@ -214,14 +214,15 @@ public function test_aggregate_grading_grades_process_single_grade_new() {
$batch = array();
$batch[] = (object)array('reviewerid'=>3, 'gradinggrade'=>82.87670, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null);
// expectation
+ $now = time();
$expected = new stdclass();
$expected->workshopid = $this->workshop->id;
$expected->userid = 3;
$expected->gradinggrade = 82.87670;
- $expected->timegraded = time(); // warning - this is a weak point as the time may actually change
+ $expected->timegraded = $now;
$DB->expectOnce('insert_record', array('workshop_aggregations', $expected));
// excersise SUT
- $this->workshop->aggregate_grading_grades_process($batch);
+ $this->workshop->aggregate_grading_grades_process($batch, $now);
}
public function test_aggregate_grading_grades_process_single_grade_update() {
@@ -265,14 +266,15 @@ public function test_aggregate_grading_grades_process_multiple_grades_new() {
$batch[] = (object)array('reviewerid'=>5, 'gradinggrade'=>87.34311, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null);
$batch[] = (object)array('reviewerid'=>5, 'gradinggrade'=>51.12000, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null);
// expectation
+ $now = time();
$expected = new stdclass();
$expected->workshopid = $this->workshop->id;
$expected->userid = 5;
$expected->gradinggrade = 79.3066;
- $expected->timegraded = time(); // warning - this is a weak point as the time may actually change
+ $expected->timegraded = $now;
$DB->expectOnce('insert_record', array('workshop_aggregations', $expected));
// excersise SUT
- $this->workshop->aggregate_grading_grades_process($batch);
+ $this->workshop->aggregate_grading_grades_process($batch, $now);
}
public function test_aggregate_grading_grades_process_multiple_grades_update() {

0 comments on commit aed7f32

Please sign in to comment.