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/>.
17 namespace core_analytics
;
19 defined('MOODLE_INTERNAL') ||
die();
21 require_once(__DIR__
. '/fixtures/test_indicator_max.php');
22 require_once(__DIR__
. '/fixtures/test_indicator_discrete.php');
23 require_once(__DIR__
. '/fixtures/test_indicator_min.php');
26 * Unit tests for the model.
28 * @package core_analytics
29 * @copyright 2017 David MonllaĆ³ {@link http://www.davidmonllao.com}
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class indicator_test
extends \advanced_testcase
{
35 * test_validate_calculated_value
37 * @param string $indicatorclass
38 * @param array $returnedvalue
39 * @dataProvider validate_calculated_value
42 public function test_validate_calculated_value($indicatorclass, $returnedvalue) {
43 $indicator = new $indicatorclass();
44 list($values, $unused) = $indicator->calculate([1], 'notrelevanthere');
45 $this->assertEquals($returnedvalue, $values[0]);
49 * Data provider for test_validate_calculated_value
53 public function validate_calculated_value() {
55 'max' => ['test_indicator_max', [1]],
56 'min' => ['test_indicator_min', [-1]],
57 'discrete' => ['test_indicator_discrete', [0, 0, 0, 0, 1]],
62 * test_validate_calculated_value_exceptions
64 * @param string $indicatorclass
65 * @param string $willreturn
66 * @dataProvider validate_calculated_value_exceptions
69 public function test_validate_calculated_value_exceptions($indicatorclass, $willreturn) {
71 $indicator = new $indicatorclass();
72 $indicatormock = $this->getMockBuilder(get_class($indicator))
73 ->onlyMethods(['calculate_sample'])
75 $indicatormock->method('calculate_sample')->willReturn($willreturn);
76 $this->expectException(\coding_exception
::class);
77 list($values, $unused) = $indicatormock->calculate([1], 'notrelevanthere');
82 * Data provider for test_validate_calculated_value_exceptions
86 public function validate_calculated_value_exceptions() {
88 'max' => ['test_indicator_max', 2],
89 'min' => ['test_indicator_min', -2],
90 'discrete' => ['test_indicator_discrete', 7],