MDL-73975 course: Remove course_search_form template
[moodle.git] / question / tests / question_bank_column_test.php
blobea8bfce844561abda8691fdd5e164a53dbc64912
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 namespace core_question;
19 use core_question\local\bank\question_edit_contexts;
20 use core_question\local\bank\view;
21 use testable_core_question_column;
23 defined('MOODLE_INTERNAL') || die();
25 global $CFG;
26 require_once($CFG->dirroot . '/question/editlib.php');
27 require_once($CFG->dirroot . '/question/tests/fixtures/testable_core_question_column.php');
29 /**
30 * Unit tests for the question bank column class.
32 * @package core_question
33 * @copyright 2018 Huong Nguyen <huongnv13@gmail.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class question_bank_column_test extends \advanced_testcase {
38 /**
39 * Test function display_header multiple sorts with no custom tooltips.
42 public function test_column_header_multi_sort_no_tooltips() {
43 $this->resetAfterTest();
44 $course = $this->getDataGenerator()->create_course();
45 $questionbank = new view(
46 new question_edit_contexts(\context_course::instance($course->id)),
47 new \moodle_url('/'),
48 $course
50 $columnbase = new testable_core_question_column($questionbank);
52 $sortable = [
53 'apple' => [
54 'field' => 'apple',
55 'title' => 'Apple'
57 'banana' => [
58 'field' => 'banana',
59 'title' => 'Banana'
62 $columnbase->set_sortable($sortable);
64 ob_start();
65 $columnbase->display_header();
66 $output = ob_get_clean();
68 $this->assertStringContainsString(' title="Sort by Apple ascending">', $output);
69 $this->assertStringContainsString(' title="Sort by Banana ascending">', $output);
72 /**
73 * Test function display_header multiple sorts with custom tooltips.
76 public function test_column_header_multi_sort_with_tooltips() {
77 $this->resetAfterTest();
78 $course = $this->getDataGenerator()->create_course();
79 $questionbank = new view(
80 new question_edit_contexts(\context_course::instance($course->id)),
81 new \moodle_url('/'),
82 $course
84 $columnbase = new testable_core_question_column($questionbank);
86 $sortable = [
87 'apple' => [
88 'field' => 'apple',
89 'title' => 'Apple',
90 'tip' => 'Apple Tooltips'
92 'banana' => [
93 'field' => 'banana',
94 'title' => 'Banana',
95 'tip' => 'Banana Tooltips'
98 $columnbase->set_sortable($sortable);
100 ob_start();
101 $columnbase->display_header();
102 $output = ob_get_clean();
104 $this->assertStringContainsString(' title="Sort by Apple Tooltips ascending">', $output);
105 $this->assertStringContainsString(' title="Sort by Banana Tooltips ascending">', $output);