MDL-58439 admin: Ignore guest logins for all admin pages
[moodle.git] / question / tests / question_bank_column_test.php
bloba263a6fd1fe2b1c63a32d6c561a68ae56e8a9f7b
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 /**
18 * This file contains tests for the question bank column class.
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
25 defined('MOODLE_INTERNAL') || die();
27 global $CFG;
28 require_once($CFG->dirroot . '/question/editlib.php');
29 require_once($CFG->dirroot . '/question/tests/fixtures/testable_core_question_column.php');
31 /**
32 * Unit tests for the question bank column class.
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
38 class question_bank_column_testcase extends advanced_testcase {
40 /**
41 * Test function display_header multiple sorts with no custom tooltips.
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
52 $columnbase = new testable_core_question_column($questionbank);
54 $sortable = [
55 'apple' => [
56 'field' => 'apple',
57 'title' => 'Apple'
59 'banana' => [
60 'field' => 'banana',
61 'title' => 'Banana'
64 $columnbase->set_sortable($sortable);
66 ob_start();
67 $columnbase->display_header();
68 $output = ob_get_clean();
70 $this->assertContains(' title="Sort by Apple ascending">Apple</a>', $output);
71 $this->assertContains(' title="Sort by Banana ascending">Banana</a>', $output);
74 /**
75 * Test function display_header multiple sorts with custom tooltips.
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
86 $columnbase = new testable_core_question_column($questionbank);
88 $sortable = [
89 'apple' => [
90 'field' => 'apple',
91 'title' => 'Apple',
92 'tip' => 'Apple Tooltips'
94 'banana' => [
95 'field' => 'banana',
96 'title' => 'Banana',
97 'tip' => 'Banana Tooltips'
100 $columnbase->set_sortable($sortable);
102 ob_start();
103 $columnbase->display_header();
104 $output = ob_get_clean();
106 $this->assertContains(' title="Sort by Apple Tooltips ascending">Apple</a>', $output);
107 $this->assertContains(' title="Sort by Banana Tooltips ascending">Banana</a>', $output);