Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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  
  36      public function test_format_percentage() {
  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          $method->setAccessible(true);
  43  
  44          $this->assertEquals(
  45                  '84.758%',
  46                  $method->invokeArgs($table, [0.847576, true, 3])
  47          );
  48  
  49          $this->assertEquals(
  50                  '84.758%',
  51                  $method->invokeArgs($table, [84.7576, false, 3])
  52          );
  53      }
  54  
  55      public function test_format_percentage_range() {
  56          $table = new quiz_statistics_table();
  57  
  58          // The format_percentage_range method is protected. Use Reflection to call the method.
  59          $reflector = new \ReflectionClass('quiz_statistics_table');
  60          $method = $reflector->getMethod('format_percentage_range');
  61          $method->setAccessible(true);
  62  
  63          $this->assertEquals(
  64                  '54.400% − 84.758%',
  65                  $method->invokeArgs($table, [0.544, 0.847576, true, 3])
  66          );
  67  
  68          $this->assertEquals(
  69                  '54.400% − 84.758%',
  70                  $method->invokeArgs($table, [54.4, 84.7576, false, 3])
  71          );
  72      }
  73  
  74      public function test_format_range() {
  75          $table = new quiz_statistics_table();
  76  
  77          // The format_range method is protected. Use Reflection to call the method.
  78          $reflector = new \ReflectionClass('quiz_statistics_table');
  79          $method = $reflector->getMethod('format_range');
  80          $method->setAccessible(true);
  81  
  82          $this->assertEquals(
  83                  '5 − 10',
  84                  $method->invokeArgs($table, [5, 10])
  85          );
  86  
  87          $this->assertEquals(
  88                  'Some Text − 10',
  89                  $method->invokeArgs($table, ['Some Text', 10])
  90          );
  91      }
  92  }