Merge branch 'MDL-76525-MOODLE_400_STABLE' of https://github.com/PhMemmel/moodle...
[moodle.git] / analytics / tests / indicator_test.php
blob82966cb04c936d6992684ae7d92180286cc622db
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 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');
25 /**
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 {
34 /**
35 * test_validate_calculated_value
37 * @param string $indicatorclass
38 * @param array $returnedvalue
39 * @dataProvider validate_calculated_value
40 * @return null
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]);
48 /**
49 * Data provider for test_validate_calculated_value
51 * @return array
53 public function validate_calculated_value() {
54 return [
55 'max' => ['test_indicator_max', [1]],
56 'min' => ['test_indicator_min', [-1]],
57 'discrete' => ['test_indicator_discrete', [0, 0, 0, 0, 1]],
61 /**
62 * test_validate_calculated_value_exceptions
64 * @param string $indicatorclass
65 * @param string $willreturn
66 * @dataProvider validate_calculated_value_exceptions
67 * @return null
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'])
74 ->getMock();
75 $indicatormock->method('calculate_sample')->willReturn($willreturn);
76 $this->expectException(\coding_exception::class);
77 list($values, $unused) = $indicatormock->calculate([1], 'notrelevanthere');
81 /**
82 * Data provider for test_validate_calculated_value_exceptions
84 * @return array
86 public function validate_calculated_value_exceptions() {
87 return [
88 'max' => ['test_indicator_max', 2],
89 'min' => ['test_indicator_min', -2],
90 'discrete' => ['test_indicator_discrete', 7],