MDL-68525 behat: chrome/switches caps not allowed in Chrome > 81
[moodle.git] / lib / tests / statslib_test.php
blob7af80e024f8f36ea31f9e286c9b8d68fae2f00d6
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Tests for ../statslib.php
20 * @package core_stats
21 * @category phpunit
22 * @copyright 2012 Tyler Bannister
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 global $CFG;
29 require_once($CFG->libdir . '/adminlib.php');
30 require_once($CFG->libdir . '/statslib.php');
31 require_once($CFG->libdir . '/cronlib.php');
32 require_once(__DIR__ . '/fixtures/stats_events.php');
34 /**
35 * Test functions that affect daily stats.
37 class core_statslib_testcase extends advanced_testcase {
38 /** The day to use for testing **/
39 const DAY = 1272672000;
41 /** The timezone to use for testing **/
42 const TIMEZONE = 0;
44 /** @var array The list of temporary tables created for the statistic calculations **/
45 protected $tables = array('temp_log1', 'temp_log2', 'temp_stats_daily', 'temp_stats_user_daily');
47 /** @var array The replacements to be used when loading XML files **/
48 protected $replacements = null;
51 /**
52 * Setup function
53 * - Allow changes to CFG->debug for testing purposes.
55 protected function setUp() {
56 global $CFG, $DB;
57 parent::setUp();
59 // Settings to force statistic to run during testing.
60 $this->setTimezone(self::TIMEZONE);
61 core_date::set_default_server_timezone();
62 $CFG->statsfirstrun = 'all';
63 $CFG->statslastdaily = 0;
65 // Figure out the broken day start so I can figure out when to the start time should be.
66 $time = time();
67 // This nonsense needs to be rewritten.
68 $date = new DateTime('now', core_date::get_server_timezone_object());
69 $offset = $date->getOffset();
70 $stime = $time + $offset;
71 $stime = intval($stime / (60*60*24)) * 60*60*24;
72 $stime -= $offset;
74 $shour = intval(($time - $stime) / (60*60));
76 if ($DB->record_exists('user', array('username' => 'user1'))) {
77 return;
80 // Set up the database.
81 $datagen = self::getDataGenerator();
83 $user1 = $datagen->create_user(array('username'=>'user1'));
84 $user2 = $datagen->create_user(array('username'=>'user2'));
86 $course1 = $datagen->create_course(array('shortname'=>'course1'));
87 $datagen->enrol_user($user1->id, $course1->id);
89 $this->generate_replacement_list();
91 // Reset between tests.
92 $this->resetAfterTest();
95 /**
96 * Function to setup database.
98 * @param array $dataset An array of tables including the log table.
99 * @param array $tables
101 protected function prepare_db($dataset, $tables) {
102 global $DB;
104 foreach ($tables as $tablename) {
105 $DB->delete_records($tablename);
107 foreach ($dataset as $name => $table) {
109 if ($tablename == $name) {
111 $rows = $table->getRowCount();
113 for ($i = 0; $i < $rows; $i++) {
114 $row = $table->getRow($i);
116 $DB->insert_record($tablename, $row, false, true);
124 * Load dataset from XML file.
126 protected function generate_replacement_list() {
127 global $CFG, $DB;
129 if ($this->replacements !== null) {
130 return;
133 $this->setTimezone(self::TIMEZONE);
135 $guest = $DB->get_record('user', array('id' => $CFG->siteguest));
136 $user1 = $DB->get_record('user', array('username' => 'user1'));
137 $user2 = $DB->get_record('user', array('username' => 'user2'));
139 if (($guest === false) || ($user1 === false) || ($user2 === false)) {
140 trigger_error('User setup incomplete', E_USER_ERROR);
143 $site = $DB->get_record('course', array('id' => SITEID));
144 $course1 = $DB->get_record('course', array('shortname' => 'course1'));
146 if (($site === false) || ($course1 === false)) {
147 trigger_error('Course setup incomplete', E_USER_ERROR);
150 $start = stats_get_base_daily(self::DAY + 3600);
151 $startnolog = stats_get_base_daily(stats_get_start_from('daily'));
152 $gr = get_guest_role();
153 $studentrole = $DB->get_record('role', array('shortname' => 'student'));
155 $this->replacements = array(
156 // Start and end times.
157 '[start_0]' => $start - 14410, // 4 hours before.
158 '[start_1]' => $start + 14410, // 4 hours after.
159 '[start_2]' => $start + 14420,
160 '[start_3]' => $start + 14430,
161 '[start_4]' => $start + 100800, // 28 hours after.
162 '[end]' => stats_get_next_day_start($start),
163 '[end_no_logs]' => stats_get_next_day_start($startnolog),
165 // User ids.
166 '[guest_id]' => $guest->id,
167 '[user1_id]' => $user1->id,
168 '[user2_id]' => $user2->id,
170 // Course ids.
171 '[course1_id]' => $course1->id,
172 '[site_id]' => SITEID,
174 // Role ids.
175 '[frontpage_roleid]' => (int) $CFG->defaultfrontpageroleid,
176 '[guest_roleid]' => $gr->id,
177 '[student_roleid]' => $studentrole->id,
182 * Load dataset from XML file.
184 * @param string $file The name of the file to load
185 * @return array
187 protected function load_xml_data_file($file) {
188 static $replacements = null;
190 $raw = $this->createXMLDataSet($file);
191 $clean = new PHPUnit\DbUnit\DataSet\ReplacementDataSet($raw);
193 foreach ($this->replacements as $placeholder => $value) {
194 $clean->addFullReplacement($placeholder, $value);
197 $logs = new PHPUnit\DbUnit\DataSet\Filter($clean);
198 $logs->addIncludeTables(array('log'));
200 $stats = new PHPUnit\DbUnit\DataSet\Filter($clean);
201 $stats->addIncludeTables(array('stats_daily', 'stats_user_daily'));
203 return array($logs, $stats);
207 * Provides the log data for test_statslib_cron_daily.
209 * @return array of fixture XML log file names.
211 public function daily_log_provider() {
212 $logfiles = array();
213 $fileno = array('00', '01', '02', '03', '04', '05', '06', '07', '08');
215 foreach ($fileno as $no) {
216 $logfiles[] = array("statslib-test{$no}.xml");
219 return $logfiles;
223 * Set of data for test_statlibs_get_base_weekly
225 * @return array Dates and timezones for which the first day of the week will be calculated
227 public function get_base_weekly_provider() {
228 return [
230 "startwday" => 0,
231 "timezone" => 'America/Chicago',
232 "timestart" => '18-03-2017 22:00',
233 "expected" => '12-03-2017 00:00:00'
236 "startwday" => 0,
237 "timezone" => 'America/Chicago',
238 "date" => '25-03-2017 22:00',
239 "expected" => '19-03-2017 00:00:00'
242 "startwday" => 1,
243 "timezone" => 'Atlantic/Canary',
244 "date" => '06-08-2018 22:00',
245 "expected" => '06-08-2018 00:00:00'
251 * Compare the expected stats to those in the database.
253 * @param array $expected
254 * @param string $output
256 protected function verify_stats($expected, $output = '') {
257 global $DB;
259 // Note: We can not use $this->assertDataSetEqual($expected, $actual) because there's no
260 // $this->getConnection() in advanced_testcase.
262 foreach ($expected as $type => $table) {
263 $records = $DB->get_records($type);
265 $rows = $table->getRowCount();
267 $message = 'Incorrect number of results returned for '. $type;
269 if ($output != '') {
270 $message .= "\nCron output:\n$output";
273 $this->assertCount($rows, $records, $message);
275 for ($i = 0; $i < $rows; $i++) {
276 $row = $table->getRow($i);
277 $found = 0;
279 foreach ($records as $key => $record) {
280 $record = (array) $record;
281 unset($record['id']);
282 $diff = array_merge(array_diff_assoc($row, $record),
283 array_diff_assoc($record, $row));
285 if (empty($diff)) {
286 $found = $key;
287 break;
291 $this->assertGreaterThan(0, $found, 'Expected log '. var_export($row, true)
292 ." was not found in $type ". var_export($records, true));
293 unset($records[$found]);
299 * Test progress output when debug is on.
301 public function test_statslib_progress_debug() {
302 set_debugging(DEBUG_ALL);
303 $this->expectOutputString('1:0 ');
304 stats_progress('init');
305 stats_progress('1');
306 $this->resetDebugging();
310 * Test progress output when debug is off.
312 public function test_statslib_progress_no_debug() {
313 set_debugging(DEBUG_NONE);
314 $this->expectOutputString('.');
315 stats_progress('init');
316 stats_progress('1');
317 $this->resetDebugging();
321 * Test the function that gets the start date from the config.
323 public function test_statslib_get_start_from() {
324 global $CFG, $DB;
326 $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test01.xml");
327 $DB->delete_records('log');
329 $date = new DateTime('now', core_date::get_server_timezone_object());
330 $day = self::DAY - $date->getOffset();
332 $CFG->statsfirstrun = 'all';
333 // Allow 1 second difference in case we cross a second boundary.
334 // Note: within 3 days of a DST change - -3 days != 3 * 24 hours (it may be more or less).
335 $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', time()), 'All start time');
337 $this->prepare_db($dataset[0], array('log'));
338 $records = $DB->get_records('log');
340 $this->assertEquals($day + 14410, stats_get_start_from('daily'), 'Log entry start');
342 $CFG->statsfirstrun = 'none';
343 $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - strtotime('-3 days', time()), 'None start time');
345 $CFG->statsfirstrun = 14515200;
346 $this->assertLessThanOrEqual(1, stats_get_start_from('daily') - (time() - (14515200)), 'Specified start time');
348 $this->prepare_db($dataset[1], array('stats_daily'));
349 $this->assertEquals($day + DAYSECS, stats_get_start_from('daily'), 'Daily stats start time');
351 // New log stores.
352 $this->preventResetByRollback();
354 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/log/store/standard/version.php");
355 set_config('enabled_stores', 'logstore_standard', 'tool_log');
356 set_config('buffersize', 0, 'logstore_standard');
357 set_config('logguests', 1, 'logstore_standard');
358 get_log_manager(true);
360 $this->assertEquals(0, $DB->count_records('logstore_standard_log'));
362 $DB->delete_records('stats_daily');
363 $CFG->statsfirstrun = 'all';
364 $firstoldtime = $DB->get_field_sql('SELECT MIN(time) FROM {log}');
366 $this->assertEquals($firstoldtime, stats_get_start_from('daily'));
368 $time = time() - 5;
369 \core_tests\event\create_executed::create(array('context' => context_system::instance()))->trigger();
370 $DB->set_field('logstore_standard_log', 'timecreated', $time++, [
371 'eventname' => '\\core_tests\\event\\create_executed',
374 \core_tests\event\read_executed::create(array('context' => context_system::instance()))->trigger();
375 $DB->set_field('logstore_standard_log', 'timecreated', $time++, [
376 'eventname' => '\\core_tests\\event\\read_executed',
379 \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger();
380 $DB->set_field('logstore_standard_log', 'timecreated', $time++, [
381 'eventname' => '\\core_tests\\event\\update_executed',
384 \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
385 $DB->set_field('logstore_standard_log', 'timecreated', $time++, [
386 'eventname' => '\\core_tests\\event\\delete_executed',
389 $DB->set_field('logstore_standard_log', 'origin', 'web', array());
390 $logs = $DB->get_records('logstore_standard_log', null, 'timecreated ASC');
391 $this->assertCount(4, $logs);
393 $firstnew = reset($logs);
394 $this->assertGreaterThan($firstoldtime, $firstnew->timecreated);
395 $DB->set_field('logstore_standard_log', 'timecreated', 10, array('id' => $firstnew->id));
396 $this->assertEquals(10, stats_get_start_from('daily'));
398 $DB->set_field('logstore_standard_log', 'timecreated', $firstnew->timecreated, array('id' => $firstnew->id));
399 $DB->delete_records('log');
400 $this->assertEquals($firstnew->timecreated, stats_get_start_from('daily'));
402 set_config('enabled_stores', '', 'tool_log');
403 get_log_manager(true);
407 * Test the function that calculates the start of the day.
409 * NOTE: I don't think this is the way this function should work.
410 * This test documents the current functionality.
412 public function test_statslib_get_base_daily() {
413 global $CFG;
415 for ($x = 0; $x < 13; $x += 1) {
416 $this->setTimezone($x);
418 $start = 1272672000 - ($x * 3600);
419 if ($x >= 20) {
420 $start += (24 * 3600);
423 $this->assertEquals($start, stats_get_base_daily(1272686410), "Timezone $x check");
428 * Test the function that gets the start of the next day.
430 public function test_statslib_get_next_day_start() {
431 $this->setTimezone(0);
432 $this->assertEquals(1272758400, stats_get_next_day_start(1272686410));
434 // Try setting timezone to some place in the US.
435 $this->setTimezone('America/New_York', 'America/New_York');
436 // Then set the time for midnight before daylight savings.
437 // 1425790800 is midnight in New York (2015-03-08) Daylight saving will occur in 2 hours time.
438 // 1425873600 is midnight the next day.
439 $this->assertEquals(1425873600, stats_get_next_day_start(1425790800));
440 $this->assertEquals(23, ((1425873600 - 1425790800) / 60 ) / 60);
441 // Then set the time for midnight before daylight savings ends.
442 // 1446350400 is midnight in New York (2015-11-01) Daylight saving will finish in 2 hours time.
443 // 1446440400 is midnight the next day.
444 $this->assertEquals(1446440400, stats_get_next_day_start(1446350400));
445 $this->assertEquals(25, ((1446440400 - 1446350400) / 60 ) / 60);
446 // The next day should be normal.
447 $this->assertEquals(1446526800, stats_get_next_day_start(1446440400));
448 $this->assertEquals(24, ((1446526800 - 1446440400) / 60 ) / 60);
452 * Test the function that calculates the start of the week.
454 * @dataProvider get_base_weekly_provider
455 * @param int $startwday Day in which the week starts (Sunday = 0)
456 * @param string $timezone Default timezone
457 * @param string $timestart Date and time for which the first day of the week will be obtained
458 * @param string $expected Expected date of the first day of the week
460 public function test_statslib_get_base_weekly($startwday, $timezone, $timestart, $expected) {
461 $this->setTimezone($timezone);
462 $time = strtotime($timestart);
463 $expected = strtotime($expected);
464 set_config('calendar_startwday', $startwday);
465 set_config('statslastweekly', $time);
467 $weekstarttime = stats_get_base_weekly($time);
469 $this->assertEquals($expected, $weekstarttime);
473 * Test the function that gets the action names.
475 * Note: The function results depend on installed modules. The hard coded lists are the
476 * defaults for a new Moodle 2.3 install.
478 public function test_statslib_get_action_names() {
479 $basepostactions = array (
480 0 => 'add',
481 1 => 'delete',
482 2 => 'edit',
483 3 => 'add mod',
484 4 => 'delete mod',
485 5 => 'edit sectionenrol',
486 6 => 'loginas',
487 7 => 'new',
488 8 => 'unenrol',
489 9 => 'update',
490 10 => 'update mod',
491 11 => 'upload',
492 12 => 'submit',
493 13 => 'submit for grading',
494 14 => 'talk',
495 15 => 'choose',
496 16 => 'choose again',
497 17 => 'record delete',
498 18 => 'add discussion',
499 19 => 'add post',
500 20 => 'delete discussion',
501 21 => 'delete post',
502 22 => 'move discussion',
503 23 => 'prune post',
504 24 => 'update post',
505 25 => 'add category',
506 26 => 'add entry',
507 27 => 'approve entry',
508 28 => 'delete category',
509 29 => 'delete entry',
510 30 => 'edit category',
511 31 => 'update entry',
512 32 => 'end',
513 33 => 'start',
514 34 => 'attempt',
515 35 => 'close attempt',
516 36 => 'preview',
517 37 => 'editquestions',
518 38 => 'delete attempt',
519 39 => 'manualgrade',
522 $baseviewactions = array (
523 0 => 'view',
524 1 => 'view all',
525 2 => 'history',
526 3 => 'view submission',
527 4 => 'view feedback',
528 5 => 'print',
529 6 => 'report',
530 7 => 'view discussion',
531 8 => 'search',
532 9 => 'forum',
533 10 => 'forums',
534 11 => 'subscribers',
535 12 => 'view forum',
536 13 => 'view entry',
537 14 => 'review',
538 15 => 'pre-view',
539 16 => 'download',
540 17 => 'view form',
541 18 => 'view graph',
542 19 => 'view report',
545 $postactions = stats_get_action_names('post');
547 foreach ($basepostactions as $action) {
548 $this->assertContains($action, $postactions);
551 $viewactions = stats_get_action_names('view');
553 foreach ($baseviewactions as $action) {
554 $this->assertContains($action, $viewactions);
559 * Test the temporary table creation and deletion.
561 public function test_statslib_temp_table_create_and_drop() {
562 global $DB;
564 foreach ($this->tables as $table) {
565 $this->assertFalse($DB->get_manager()->table_exists($table));
568 stats_temp_table_create();
570 foreach ($this->tables as $table) {
571 $this->assertTrue($DB->get_manager()->table_exists($table));
574 stats_temp_table_drop();
576 foreach ($this->tables as $table) {
577 $this->assertFalse($DB->get_manager()->table_exists($table));
582 * Test the temporary table creation and deletion.
584 * @depends test_statslib_temp_table_create_and_drop
586 public function test_statslib_temp_table_fill() {
587 global $CFG, $DB, $USER;
589 $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test09.xml");
591 $this->prepare_db($dataset[0], array('log'));
593 // This nonsense needs to be rewritten.
594 $date = new DateTime('now', core_date::get_server_timezone_object());
595 $start = self::DAY - $date->getOffset();
596 $end = $start + (24 * 3600);
598 stats_temp_table_create();
599 stats_temp_table_fill($start, $end);
601 $this->assertEquals(1, $DB->count_records('temp_log1'));
602 $this->assertEquals(1, $DB->count_records('temp_log2'));
604 stats_temp_table_drop();
606 // New log stores.
607 $this->preventResetByRollback();
608 stats_temp_table_create();
610 $course = $this->getDataGenerator()->create_course();
611 $context = context_course::instance($course->id);
612 $fcontext = context_course::instance(SITEID);
613 $user = $this->getDataGenerator()->create_user();
614 $this->setUser($user);
616 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/log/store/standard/version.php");
617 set_config('enabled_stores', 'logstore_standard', 'tool_log');
618 set_config('buffersize', 0, 'logstore_standard');
619 set_config('logguests', 1, 'logstore_standard');
620 get_log_manager(true);
622 $DB->delete_records('logstore_standard_log');
624 \core_tests\event\create_executed::create(array('context' => $fcontext, 'courseid' => SITEID))->trigger();
625 \core_tests\event\read_executed::create(array('context' => $context, 'courseid' => $course->id))->trigger();
626 \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger();
627 \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
629 \core\event\user_loggedin::create(
630 array(
631 'userid' => $USER->id,
632 'objectid' => $USER->id,
633 'other' => array('username' => $USER->username),
635 )->trigger();
637 $DB->set_field('logstore_standard_log', 'timecreated', 10);
639 $this->assertEquals(5, $DB->count_records('logstore_standard_log'));
641 \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
642 \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger();
644 // Fake the origin of events.
645 $DB->set_field('logstore_standard_log', 'origin', 'web', array());
647 $this->assertEquals(7, $DB->count_records('logstore_standard_log'));
649 stats_temp_table_fill(9, 11);
651 $logs1 = $DB->get_records('temp_log1');
652 $logs2 = $DB->get_records('temp_log2');
653 $this->assertCount(5, $logs1);
654 $this->assertCount(5, $logs2);
655 // The order of records in the temp tables is not guaranteed...
657 $viewcount = 0;
658 $updatecount = 0;
659 $logincount = 0;
660 foreach ($logs1 as $log) {
661 if ($log->course == $course->id) {
662 $this->assertEquals('view', $log->action);
663 $viewcount++;
664 } else {
665 $this->assertTrue(in_array($log->action, array('update', 'login')));
666 if ($log->action === 'update') {
667 $updatecount++;
668 } else {
669 $logincount++;
671 $this->assertEquals(SITEID, $log->course);
673 $this->assertEquals($user->id, $log->userid);
675 $this->assertEquals(1, $viewcount);
676 $this->assertEquals(3, $updatecount);
677 $this->assertEquals(1, $logincount);
679 set_config('enabled_stores', '', 'tool_log');
680 get_log_manager(true);
681 stats_temp_table_drop();
685 * Test the temporary table creation and deletion.
687 * @depends test_statslib_temp_table_create_and_drop
689 public function test_statslib_temp_table_setup() {
690 global $DB;
692 $logs = array();
693 $this->prepare_db($logs, array('log'));
695 stats_temp_table_create();
696 stats_temp_table_setup();
698 $this->assertEquals(1, $DB->count_records('temp_enroled'));
700 stats_temp_table_drop();
704 * Test the function that clean out the temporary tables.
706 * @depends test_statslib_temp_table_create_and_drop
708 public function test_statslib_temp_table_clean() {
709 global $DB;
711 $rows = array(
712 'temp_log1' => array('id' => 1, 'course' => 1),
713 'temp_log2' => array('id' => 1, 'course' => 1),
714 'temp_stats_daily' => array('id' => 1, 'courseid' => 1),
715 'temp_stats_user_daily' => array('id' => 1, 'courseid' => 1),
718 stats_temp_table_create();
720 foreach ($rows as $table => $row) {
721 $DB->insert_record_raw($table, $row);
722 $this->assertEquals(1, $DB->count_records($table));
725 stats_temp_table_clean();
727 foreach ($rows as $table => $row) {
728 $this->assertEquals(0, $DB->count_records($table));
731 $this->assertEquals(1, $DB->count_records('stats_daily'));
732 $this->assertEquals(1, $DB->count_records('stats_user_daily'));
734 stats_temp_table_drop();
738 * Test the daily stats function.
740 * @depends test_statslib_get_base_daily
741 * @depends test_statslib_get_next_day_start
742 * @depends test_statslib_get_start_from
743 * @depends test_statslib_temp_table_create_and_drop
744 * @depends test_statslib_temp_table_setup
745 * @depends test_statslib_temp_table_fill
746 * @dataProvider daily_log_provider
748 public function test_statslib_cron_daily($xmlfile) {
749 global $CFG, $DB;
751 $dataset = $this->load_xml_data_file(__DIR__."/fixtures/{$xmlfile}");
753 list($logs, $stats) = $dataset;
754 $this->prepare_db($logs, array('log'));
756 // Stats cron daily uses mtrace, turn on buffering to silence output.
757 ob_start();
758 stats_cron_daily(1);
759 $output = ob_get_contents();
760 ob_end_clean();
762 $this->verify_stats($stats, $output);
766 * Test the daily stats function.
768 * @depends test_statslib_get_base_daily
769 * @depends test_statslib_get_next_day_start
771 public function test_statslib_cron_daily_no_default_profile_id() {
772 global $CFG, $DB;
773 $CFG->defaultfrontpageroleid = 0;
775 $course1 = $DB->get_record('course', array('shortname' => 'course1'));
776 $guestid = $CFG->siteguest;
777 $start = stats_get_base_daily(1272758400);
778 $end = stats_get_next_day_start($start);
779 $fpid = (int) $CFG->defaultfrontpageroleid;
780 $gr = get_guest_role();
782 $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test10.xml");
784 $this->prepare_db($dataset[0], array('log'));
786 // Stats cron daily uses mtrace, turn on buffering to silence output.
787 ob_start();
788 stats_cron_daily($maxdays=1);
789 $output = ob_get_contents();
790 ob_end_clean();
792 $this->verify_stats($dataset[1], $output);