Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 */
1441 ariadna 36
final class question_bank_column_test extends \advanced_testcase {
1 efrain 37
 
38
    /**
39
     * Test function display_header multiple sorts with no custom tooltips.
40
     *
41
     */
11 efrain 42
    public function test_column_header_multi_sort_no_tooltips(): void {
1 efrain 43
        $this->resetAfterTest();
44
        $course = $this->getDataGenerator()->create_course();
1441 ariadna 45
        $qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
46
        $cm = get_coursemodule_from_id('qbank', $qbank->cmid);
1 efrain 47
        $questionbank = new view(
1441 ariadna 48
                new question_edit_contexts(\context_module::instance($cm->id)),
1 efrain 49
                new \moodle_url('/'),
1441 ariadna 50
                $course,
51
                $cm
1 efrain 52
        );
53
        $columnbase = new testable_core_question_column($questionbank);
54
 
55
        $sortable = [
56
                'apple' => [
57
                        'field' => 'apple',
58
                        'title' => 'Apple'
59
                ],
60
                'banana' => [
61
                        'field' => 'banana',
62
                        'title' => 'Banana'
63
                ]
64
        ];
65
        $columnbase->set_sortable($sortable);
66
 
67
        ob_start();
68
        $columnbase->display_header();
69
        $output = ob_get_clean();
70
 
71
        $this->assertStringContainsString(' title="Sort by Apple ascending">', $output);
72
        $this->assertStringContainsString(' title="Sort by Banana ascending">', $output);
73
    }
74
 
75
    /**
76
     * Test function display_header multiple sorts with custom tooltips.
77
     *
78
     */
11 efrain 79
    public function test_column_header_multi_sort_with_tooltips(): void {
1 efrain 80
        $this->resetAfterTest();
81
        $course = $this->getDataGenerator()->create_course();
1441 ariadna 82
        $qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
83
        $cm = get_coursemodule_from_id('qbank', $qbank->cmid);
1 efrain 84
        $questionbank = new view(
1441 ariadna 85
                new question_edit_contexts(\context_module::instance($cm->id)),
1 efrain 86
                new \moodle_url('/'),
1441 ariadna 87
                $course,
88
                $cm
1 efrain 89
        );
90
        $columnbase = new testable_core_question_column($questionbank);
91
 
92
        $sortable = [
93
                'apple' => [
94
                        'field' => 'apple',
95
                        'title' => 'Apple',
96
                        'tip' => 'Apple Tooltips'
97
                ],
98
                'banana' => [
99
                        'field' => 'banana',
100
                        'title' => 'Banana',
101
                        'tip' => 'Banana Tooltips'
102
                ]
103
        ];
104
        $columnbase->set_sortable($sortable);
105
 
106
        ob_start();
107
        $columnbase->display_header();
108
        $output = ob_get_clean();
109
 
110
        $this->assertStringContainsString(' title="Sort by Apple Tooltips ascending">', $output);
111
        $this->assertStringContainsString(' title="Sort by Banana Tooltips ascending">', $output);
112
    }
113
}