mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-58596 core_stats: unit test for stats_get_base_weekly
This commit is contained in:
parent
38a1b4f203
commit
5007d1cb04
1 changed files with 49 additions and 0 deletions
|
@ -219,6 +219,34 @@ class core_statslib_testcase extends advanced_testcase {
|
|||
return $logfiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of data for test_statlibs_get_base_weekly
|
||||
*
|
||||
* @return array Dates and timezones for which the first day of the week will be calculated
|
||||
*/
|
||||
public function get_base_weekly_provider() {
|
||||
return [
|
||||
[
|
||||
"startwday" => 0,
|
||||
"timezone" => 'America/Chicago',
|
||||
"timestart" => '18-03-2017 22:00',
|
||||
"expected" => '12-03-2017 00:00:00'
|
||||
],
|
||||
[
|
||||
"startwday" => 0,
|
||||
"timezone" => 'America/Chicago',
|
||||
"date" => '25-03-2017 22:00',
|
||||
"expected" => '19-03-2017 00:00:00'
|
||||
],
|
||||
[
|
||||
"startwday" => 1,
|
||||
"timezone" => 'Atlantic/Canary',
|
||||
"date" => '06-08-2018 22:00',
|
||||
"expected" => '06-08-2018 00:00:00'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the expected stats to those in the database.
|
||||
*
|
||||
|
@ -420,6 +448,27 @@ class core_statslib_testcase extends advanced_testcase {
|
|||
$this->assertEquals(24, ((1446526800 - 1446440400) / 60 ) / 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the function that calculates the start of the week.
|
||||
*
|
||||
* @dataProvider get_base_weekly_provider
|
||||
* @param int $startwday Day in which the week starts (Sunday = 0)
|
||||
* @param string $timezone Default timezone
|
||||
* @param string $timestart Date and time for which the first day of the week will be obtained
|
||||
* @param string $expected Expected date of the first day of the week
|
||||
*/
|
||||
public function test_statslib_get_base_weekly($startwday, $timezone, $timestart, $expected) {
|
||||
$this->setTimezone($timezone);
|
||||
$time = strtotime($timestart);
|
||||
$expected = strtotime($expected);
|
||||
set_config('calendar_startwday', $startwday);
|
||||
set_config('statslastweekly', $time);
|
||||
|
||||
$weekstarttime = stats_get_base_weekly($time);
|
||||
|
||||
$this->assertEquals($expected, $weekstarttime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the function that gets the action names.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue