1 |
efrain |
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 core_question;
|
|
|
18 |
|
|
|
19 |
use core_question\local\bank\question_edit_contexts;
|
|
|
20 |
use core_question\local\bank\view;
|
|
|
21 |
use testable_core_question_column;
|
|
|
22 |
|
|
|
23 |
defined('MOODLE_INTERNAL') || die();
|
|
|
24 |
|
|
|
25 |
global $CFG;
|
|
|
26 |
require_once($CFG->dirroot . '/question/editlib.php');
|
|
|
27 |
require_once($CFG->dirroot . '/question/tests/fixtures/testable_core_question_column.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Unit tests for the question bank column class.
|
|
|
31 |
*
|
|
|
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
|
|
|
35 |
*/
|
|
|
36 |
class question_bank_column_test extends \advanced_testcase {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Test function display_header multiple sorts with no custom tooltips.
|
|
|
40 |
*
|
|
|
41 |
*/
|
|
|
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
|
|
|
49 |
);
|
|
|
50 |
$columnbase = new testable_core_question_column($questionbank);
|
|
|
51 |
|
|
|
52 |
$sortable = [
|
|
|
53 |
'apple' => [
|
|
|
54 |
'field' => 'apple',
|
|
|
55 |
'title' => 'Apple'
|
|
|
56 |
],
|
|
|
57 |
'banana' => [
|
|
|
58 |
'field' => 'banana',
|
|
|
59 |
'title' => 'Banana'
|
|
|
60 |
]
|
|
|
61 |
];
|
|
|
62 |
$columnbase->set_sortable($sortable);
|
|
|
63 |
|
|
|
64 |
ob_start();
|
|
|
65 |
$columnbase->display_header();
|
|
|
66 |
$output = ob_get_clean();
|
|
|
67 |
|
|
|
68 |
$this->assertStringContainsString(' title="Sort by Apple ascending">', $output);
|
|
|
69 |
$this->assertStringContainsString(' title="Sort by Banana ascending">', $output);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Test function display_header multiple sorts with custom tooltips.
|
|
|
74 |
*
|
|
|
75 |
*/
|
|
|
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
|
|
|
83 |
);
|
|
|
84 |
$columnbase = new testable_core_question_column($questionbank);
|
|
|
85 |
|
|
|
86 |
$sortable = [
|
|
|
87 |
'apple' => [
|
|
|
88 |
'field' => 'apple',
|
|
|
89 |
'title' => 'Apple',
|
|
|
90 |
'tip' => 'Apple Tooltips'
|
|
|
91 |
],
|
|
|
92 |
'banana' => [
|
|
|
93 |
'field' => 'banana',
|
|
|
94 |
'title' => 'Banana',
|
|
|
95 |
'tip' => 'Banana Tooltips'
|
|
|
96 |
]
|
|
|
97 |
];
|
|
|
98 |
$columnbase->set_sortable($sortable);
|
|
|
99 |
|
|
|
100 |
ob_start();
|
|
|
101 |
$columnbase->display_header();
|
|
|
102 |
$output = ob_get_clean();
|
|
|
103 |
|
|
|
104 |
$this->assertStringContainsString(' title="Sort by Apple Tooltips ascending">', $output);
|
|
|
105 |
$this->assertStringContainsString(' title="Sort by Banana Tooltips ascending">', $output);
|
|
|
106 |
}
|
|
|
107 |
}
|