mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-65348_master' of git://github.com/dmonllao/moodle
- Loading branch information
Showing
10 changed files
with
302 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Unit tests for the analysis class. | ||
* | ||
* @package core_analytics | ||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Unit tests for the analysis class. | ||
* | ||
* @package core_analytics | ||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class analytics_analysis_testcase extends advanced_testcase { | ||
|
||
/** | ||
* Test fill_firstanalyses_cache. | ||
* @return null | ||
*/ | ||
public function test_fill_firstanalyses_cache() { | ||
$this->resetAfterTest(); | ||
|
||
$this->insert_used(1, 1, 'training', 123); | ||
$this->insert_used(1, 2, 'training', 124); | ||
$this->insert_used(1, 1, 'prediction', 125); | ||
|
||
$firstanalyses = \core_analytics\analysis::fill_firstanalyses_cache(1); | ||
$this->assertCount(2, $firstanalyses); | ||
$this->assertEquals(123, $firstanalyses['1_1']); | ||
$this->assertEquals(124, $firstanalyses['1_2']); | ||
|
||
// The cached elements gets refreshed. | ||
$this->insert_used(1, 1, 'prediction', 122); | ||
$firstanalyses = \core_analytics\analysis::fill_firstanalyses_cache(1, 1); | ||
$this->assertCount(1, $firstanalyses); | ||
$this->assertEquals(122, $firstanalyses['1_1']); | ||
} | ||
|
||
private function insert_used($modelid, $analysableid, $action, $timestamp) { | ||
global $DB; | ||
|
||
$obj = new \stdClass(); | ||
$obj->modelid = $modelid; | ||
$obj->action = $action; | ||
$obj->analysableid = $analysableid; | ||
$obj->firstanalysis = $timestamp; | ||
$obj->timeanalysed = $timestamp; | ||
$obj->id = $DB->insert_record('analytics_used_analysables', $obj); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
analytics/tests/fixtures/test_timesplitting_upcoming_seconds.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Test time splitting. | ||
* | ||
* @package core_analytics | ||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Test time splitting. | ||
* | ||
* @package core_analytics | ||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class test_timesplitting_upcoming_seconds extends \core_analytics\local\time_splitting\upcoming_periodic { | ||
|
||
/** | ||
* Every second. | ||
* @return \DateInterval | ||
*/ | ||
public function periodicity() { | ||
return new \DateInterval('PT1S'); | ||
} | ||
|
||
/** | ||
* Just to comply with the interface. | ||
* | ||
* @return \lang_string | ||
*/ | ||
public static function get_name() : \lang_string { | ||
return new \lang_string('error'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.