MDL-57254 mod_choice: Add not open case in choice_can_view_results

If the choice is not available (not open yet), the function must return
false even is CHOICE_SHOWRESULTS_ALWAYS is set to true.
This was failing only in Web Services, in Web that function is not
reached (execution stops when the time open check is done).
This commit is contained in:
Juan Leyva 2017-03-14 13:34:27 +01:00
parent 1034421264
commit fa19c73350
2 changed files with 13 additions and 0 deletions

View File

@ -1027,6 +1027,12 @@ function choice_can_view_results($choice, $current = null, $choiceopen = null) {
if (is_null($choiceopen)) {
$timenow = time();
if ($choice->timeopen != 0 && $timenow < $choice->timeopen) {
// If the choice is not available, we can't see the results.
return false;
}
if ($choice->timeclose != 0 && $timenow > $choice->timeclose) {
$choiceopen = false;
} else {

View File

@ -102,7 +102,14 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
$canview = choice_can_view_results($choice);
$this->assertTrue($canview);
// Add a time restriction (choice not open yet).
$choice->timeopen = time() + YEARSECS;
$DB->update_record('choice', $choice);
$canview = choice_can_view_results($choice);
$this->assertFalse($canview);
// Show results after closing.
$choice->timeopen = 0;
$choice->showresults = CHOICE_SHOWRESULTS_AFTER_CLOSE;
$DB->update_record('choice', $choice);
$canview = choice_can_view_results($choice);