Merge branch 'MDL-65324-master' of git://github.com/peterRd/moodle

This commit is contained in:
Jun Pataleta 2019-04-23 11:48:50 +08:00 committed by Eloy Lafuente (stronk7)
commit 72f7e3f198
2 changed files with 66 additions and 4 deletions

View File

@ -239,7 +239,7 @@ class discussion {
}
/**
* Check if the discussion has started yet.
* Check if the discussion has started yet. DEFAULTS: true if not set
*
* @return bool
*/
@ -249,13 +249,13 @@ class discussion {
}
/**
* Check if the discussion has ended.
* Check if the discussion has ended. DEFAULTS: false if not set
*
* @return bool
*/
public function has_ended() : bool {
$endtime = $this->get_time_end();
return !empty($endtime) && $endtime >= time();
return !empty($endtime) && $endtime < time();
}
/**

View File

@ -113,4 +113,66 @@ class mod_forum_entities_discussion_testcase extends advanced_testcase {
$this->assertEquals(true, $discussion->has_started());
$this->assertEquals(true, $discussion->has_group());
}
}
/**
* Test the display period settings for discussions.
* This covers each individual date function as well as the combination of the 2.
*
* @dataProvider test_diplay_period_options_provider
* @param string $testdescription A basic description of the base assertions.
* @param int $basetime
* @param int $timestart
* @param int $timeend
* @param bool $timestartresult Expected result from the has_started function
* @param bool $timeendresult Expected result from the has_ended function
* @param bool $isvisible Expected result from the is_timed_discussion_visible function
*/
public function test_display_period_settings($testdescription, $basetime, $timestart, $timeend,
$timestartresult, $timeendresult, $isvisible) {
global $CFG;
$this->resetAfterTest();
$discussion = new discussion_entity(
1,
2,
3,
'test discussion',
4,
5,
6,
false,
$basetime,
$basetime,
$timestart,
$timeend,
false
);
$originaltimedposts = $CFG->forum_enabletimedposts;
$CFG->forum_enabletimedposts = true;
$this->assertEquals($timestartresult, $discussion->has_started(), $testdescription);
$this->assertEquals($timeendresult, $discussion->has_ended(), $testdescription);
$this->assertEquals($isvisible, $discussion->is_timed_discussion_visible(), $testdescription);
$CFG->forum_enabletimedposts = $originaltimedposts;
}
/**
* Data provider for test_display_period_settings().
*
* @return array base,start, endtimes and the expected results.
*/
public function test_diplay_period_options_provider() {
$base = time() + 10;
return array(
["No dates set set", $base, 0, 0, true, false, true],
["Only started date in the future", $base, $base + 100, 0, false, false, false],
["Only started date in the past", $base, $base - 100, 0, true, false, true],
["Only end date in the future", $base, 0, $base + 100, true, false, true],
["Only end date in the past", $base, 0, $base - 100, true, true, false],
["Start date in the past, end date in the future", $base, $base - 100, $base + 100, true, false, true],
["Both dates in the past", $base, $base - 100, $base - 50, true, true, false],
["Both dates in the future", $base, $base + 100, $base + 150, false, false, false],
);
}
}