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
defined('MOODLE_INTERNAL') || die();
20
 
21
global $CFG;
22
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
23
 
24
/**
25
 * Test for question_definition base classes.
26
 *
27
 * @package   core_question
28
 * @copyright  2015 The Open University
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 30
 * @covers     \question_definition
1 efrain 31
 */
1441 ariadna 32
final class question_definition_test extends \advanced_testcase {
11 efrain 33
    public function test_make_html_inline(): void {
1 efrain 34
        // Base class is abstract, so we need to pick one qusetion type to test this method.
35
        $mc = \test_question_maker::make_a_multichoice_single_question();
36
        $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p>'));
37
        $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog<br /></p>'));
38
        $this->assertEquals('Frog<br />Toad', $mc->make_html_inline("<p>Frog</p>\n<p>Toad</p>"));
39
        $this->assertEquals('<img src="http://example.com/pic.png" alt="Graph" />',
40
                $mc->make_html_inline(
41
                    '<p><img src="http://example.com/pic.png" alt="Graph" /></p>'));
42
        $this->assertEquals("Frog<br />XXX <img src='http://example.com/pic.png' alt='Graph' />",
43
                $mc->make_html_inline(" <p> Frog </p> \n\r
44
                    <p> XXX <img src='http://example.com/pic.png' alt='Graph' /> </p> "));
45
        $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p><p></p>'));
46
        $this->assertEquals('Frog<br />†', $mc->make_html_inline('<p>Frog</p><p>†</p>'));
47
    }
1441 ariadna 48
 
49
    public function test_check_file_access_hints(): void {
50
        // Prepare a shortanswer question with a hint plus default display options.
51
        $question = \test_question_maker::make_question('shortanswer', 'frogtoad');
52
        $question->id = 42;
53
        $question->hints[] = new \question_hint_with_parts(12, 'foo', FORMAT_HTML, false, false);
54
        $options = new \question_display_options();
55
 
56
        // Prepare and start an interactive question attempt.
57
        $quba = new \question_usage_by_activity('qtype_shortanswer', \context_system::instance());
58
        $qa = new \question_attempt($question, $quba->get_id());
59
        $qa->start('interactive', 1);
60
 
61
        // No answer has been submitted, so we should not have access to files from the 'hint' area.
62
        $args = [$question->hints[0]->id, 'foo.jpg'];
63
        $checkresult = $question->check_file_access($qa, $options, 'question', 'hint', $args, false);
64
        $this->assertFalse($checkresult);
65
    }
1 efrain 66
}