Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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   * This file contains tests for the question bank column class.
  19   *
  20   * @package core_question
  21   * @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/question/editlib.php');
  29  require_once($CFG->dirroot . '/question/tests/fixtures/testable_core_question_column.php');
  30  
  31  /**
  32   * Unit tests for the question bank column class.
  33   *
  34   * @package core_question
  35   * @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
  36   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class question_bank_column_testcase extends advanced_testcase {
  39  
  40      /**
  41       * Test function display_header multiple sorts with no custom tooltips.
  42       *
  43       */
  44      public function test_column_header_multi_sort_no_tooltips() {
  45          $this->resetAfterTest();
  46          $course = $this->getDataGenerator()->create_course();
  47          $questionbank = new core_question\bank\view(
  48                  new question_edit_contexts(context_course::instance($course->id)),
  49                  new moodle_url('/'),
  50                  $course
  51          );
  52          $columnbase = new testable_core_question_column($questionbank);
  53  
  54          $sortable = [
  55                  'apple' => [
  56                          'field' => 'apple',
  57                          'title' => 'Apple'
  58                  ],
  59                  'banana' => [
  60                          'field' => 'banana',
  61                          'title' => 'Banana'
  62                  ]
  63          ];
  64          $columnbase->set_sortable($sortable);
  65  
  66          ob_start();
  67          $columnbase->display_header();
  68          $output = ob_get_clean();
  69  
  70          $this->assertStringContainsString(' title="Sort by Apple ascending">Apple</a>', $output);
  71          $this->assertStringContainsString(' title="Sort by Banana ascending">Banana</a>', $output);
  72      }
  73  
  74      /**
  75       * Test function display_header multiple sorts with custom tooltips.
  76       *
  77       */
  78      public function test_column_header_multi_sort_with_tooltips() {
  79          $this->resetAfterTest();
  80          $course = $this->getDataGenerator()->create_course();
  81          $questionbank = new core_question\bank\view(
  82                  new question_edit_contexts(context_course::instance($course->id)),
  83                  new moodle_url('/'),
  84                  $course
  85          );
  86          $columnbase = new testable_core_question_column($questionbank);
  87  
  88          $sortable = [
  89                  'apple' => [
  90                          'field' => 'apple',
  91                          'title' => 'Apple',
  92                          'tip' => 'Apple Tooltips'
  93                  ],
  94                  'banana' => [
  95                          'field' => 'banana',
  96                          'title' => 'Banana',
  97                          'tip' => 'Banana Tooltips'
  98                  ]
  99          ];
 100          $columnbase->set_sortable($sortable);
 101  
 102          ob_start();
 103          $columnbase->display_header();
 104          $output = ob_get_clean();
 105  
 106          $this->assertStringContainsString(' title="Sort by Apple Tooltips ascending">Apple</a>', $output);
 107          $this->assertStringContainsString(' title="Sort by Banana Tooltips ascending">Banana</a>', $output);
 108      }
 109  }