2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Unit tests for the indicator API.
20 * @package core_analytics
21 * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once(__DIR__
. '/fixtures/test_indicator_max.php');
28 require_once(__DIR__
. '/fixtures/test_indicator_discrete.php');
29 require_once(__DIR__
. '/fixtures/test_indicator_min.php');
32 * Unit tests for the model.
34 * @package core_analytics
35 * @copyright 2017 David MonllaĆ³ {@link http://www.davidmonllao.com}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class analytics_indicator_testcase
extends advanced_testcase
{
41 * test_validate_calculated_value
43 * @param string $indicatorclass
44 * @param array $returnedvalue
45 * @dataProvider validate_calculated_value
48 public function test_validate_calculated_value($indicatorclass, $returnedvalue) {
49 $indicator = new $indicatorclass();
50 list($values, $unused) = $indicator->calculate([1], 'notrelevanthere');
51 $this->assertEquals($returnedvalue, $values[0]);
55 * Data provider for test_validate_calculated_value
59 public function validate_calculated_value() {
61 'max' => ['test_indicator_max', [1]],
62 'min' => ['test_indicator_min', [-1]],
63 'discrete' => ['test_indicator_discrete', [0, 0, 0, 0, 1]],
68 * test_validate_calculated_value_exceptions
70 * @param string $indicatorclass
71 * @param string $willreturn
72 * @dataProvider validate_calculated_value_exceptions
75 public function test_validate_calculated_value_exceptions($indicatorclass, $willreturn) {
77 $indicator = new $indicatorclass();
78 $indicatormock = $this->getMockBuilder(get_class($indicator))
79 ->onlyMethods(['calculate_sample'])
81 $indicatormock->method('calculate_sample')->willReturn($willreturn);
82 $this->expectException(coding_exception
::class);
83 list($values, $unused) = $indicatormock->calculate([1], 'notrelevanthere');
88 * Data provider for test_validate_calculated_value_exceptions
92 public function validate_calculated_value_exceptions() {
94 'max' => ['test_indicator_max', 2],
95 'min' => ['test_indicator_min', -2],
96 'discrete' => ['test_indicator_discrete', 7],