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