1 |
efrain |
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
namespace quiz_statistics;
|
|
|
18 |
|
|
|
19 |
use quiz_statistics_table;
|
|
|
20 |
|
|
|
21 |
defined('MOODLE_INTERNAL') || die();
|
|
|
22 |
|
|
|
23 |
global $CFG;
|
|
|
24 |
require_once($CFG->dirroot . '/mod/quiz/report/statistics/statistics_table.php');
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Class quiz_statistics_statistics_table_testcase
|
|
|
28 |
*
|
|
|
29 |
* @package quiz_statistics
|
|
|
30 |
* @category test
|
|
|
31 |
* @copyright 2018 Shamim Rezaie <shamim@moodle.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class statistics_table_test extends \advanced_testcase {
|
|
|
35 |
|
11 |
efrain |
36 |
public function test_format_percentage(): void {
|
1 |
efrain |
37 |
$table = new quiz_statistics_table();
|
|
|
38 |
|
|
|
39 |
// The format_percentage method is protected. Use Reflection to call the method.
|
|
|
40 |
$reflector = new \ReflectionClass('quiz_statistics_table');
|
|
|
41 |
$method = $reflector->getMethod('format_percentage');
|
|
|
42 |
|
|
|
43 |
$this->assertEquals(
|
|
|
44 |
'84.758%',
|
|
|
45 |
$method->invokeArgs($table, [0.847576, true, 3])
|
|
|
46 |
);
|
|
|
47 |
|
|
|
48 |
$this->assertEquals(
|
|
|
49 |
'84.758%',
|
|
|
50 |
$method->invokeArgs($table, [84.7576, false, 3])
|
|
|
51 |
);
|
|
|
52 |
}
|
|
|
53 |
|
11 |
efrain |
54 |
public function test_format_percentage_range(): void {
|
1 |
efrain |
55 |
$table = new quiz_statistics_table();
|
|
|
56 |
|
|
|
57 |
// The format_percentage_range method is protected. Use Reflection to call the method.
|
|
|
58 |
$reflector = new \ReflectionClass('quiz_statistics_table');
|
|
|
59 |
$method = $reflector->getMethod('format_percentage_range');
|
|
|
60 |
|
|
|
61 |
$this->assertEquals(
|
|
|
62 |
'54.400% − 84.758%',
|
|
|
63 |
$method->invokeArgs($table, [0.544, 0.847576, true, 3])
|
|
|
64 |
);
|
|
|
65 |
|
|
|
66 |
$this->assertEquals(
|
|
|
67 |
'54.400% − 84.758%',
|
|
|
68 |
$method->invokeArgs($table, [54.4, 84.7576, false, 3])
|
|
|
69 |
);
|
|
|
70 |
}
|
|
|
71 |
|
11 |
efrain |
72 |
public function test_format_range(): void {
|
1 |
efrain |
73 |
$table = new quiz_statistics_table();
|
|
|
74 |
|
|
|
75 |
// The format_range method is protected. Use Reflection to call the method.
|
|
|
76 |
$reflector = new \ReflectionClass('quiz_statistics_table');
|
|
|
77 |
$method = $reflector->getMethod('format_range');
|
|
|
78 |
|
|
|
79 |
$this->assertEquals(
|
|
|
80 |
'5 − 10',
|
|
|
81 |
$method->invokeArgs($table, [5, 10])
|
|
|
82 |
);
|
|
|
83 |
|
|
|
84 |
$this->assertEquals(
|
|
|
85 |
'Some Text − 10',
|
|
|
86 |
$method->invokeArgs($table, ['Some Text', 10])
|
|
|
87 |
);
|
|
|
88 |
}
|
|
|
89 |
}
|