| Línea 37... |
Línea 37... |
| 37 |
* Unit tests for (some of) mod/quiz/locallib.php.
|
37 |
* Unit tests for (some of) mod/quiz/locallib.php.
|
| 38 |
*
|
38 |
*
|
| 39 |
* @copyright 2008 Tim Hunt
|
39 |
* @copyright 2008 Tim Hunt
|
| 40 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
40 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 41 |
*/
|
41 |
*/
|
| 42 |
class locallib_test extends \advanced_testcase {
|
42 |
final class locallib_test extends \advanced_testcase {
|
| Línea 43... |
Línea 43... |
| 43 |
|
43 |
|
| Línea 44... |
Línea 44... |
| 44 |
use \quiz_question_helper_test_trait;
|
44 |
use \quiz_question_helper_test_trait;
|
| 45 |
|
45 |
|
| Línea 58... |
Línea 58... |
| 58 |
$this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, true), format_float(0.25, 2));
|
58 |
$this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, true), format_float(0.25, 2));
|
| 59 |
$this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, 'question'),
|
59 |
$this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, 'question'),
|
| 60 |
format_float(0.247, 3));
|
60 |
format_float(0.247, 3));
|
| 61 |
}
|
61 |
}
|
| Línea 62... |
Línea 62... |
| 62 |
|
62 |
|
| 63 |
public function quiz_attempt_state_data_provider() {
|
63 |
public static function quiz_attempt_state_data_provider(): array {
|
| 64 |
return [
|
64 |
return [
|
| 65 |
[quiz_attempt::IN_PROGRESS, null, null, display_options::DURING],
|
65 |
[quiz_attempt::IN_PROGRESS, null, null, display_options::DURING],
|
| 66 |
[quiz_attempt::FINISHED, -90, null, display_options::IMMEDIATELY_AFTER],
|
66 |
[quiz_attempt::FINISHED, -90, null, display_options::IMMEDIATELY_AFTER],
|
| 67 |
[quiz_attempt::FINISHED, -7200, null, display_options::LATER_WHILE_OPEN],
|
67 |
[quiz_attempt::FINISHED, -7200, null, display_options::LATER_WHILE_OPEN],
|
| Línea 120... |
Línea 120... |
| 120 |
$this->assertEquals('<span class="questionname">The question name</span> ' .
|
120 |
$this->assertEquals('<span class="questionname">The question name</span> ' .
|
| 121 |
'<span class="questiontext">What sort of INEQUALITY is x < y[?]' . "\n" . '</span>', $summary);
|
121 |
'<span class="questiontext">What sort of INEQUALITY is x < y[?]' . "\n" . '</span>', $summary);
|
| 122 |
}
|
122 |
}
|
| Línea 123... |
Línea 123... |
| 123 |
|
123 |
|
| - |
|
124 |
/**
|
| - |
|
125 |
* Test the method quiz_question_to_string with the tag display.
|
| - |
|
126 |
*
|
| - |
|
127 |
* @covers ::quiz_question_tostring
|
| - |
|
128 |
*/
|
| - |
|
129 |
public function test_quiz_question_tostring_with_tags(): void {
|
| - |
|
130 |
$this->resetAfterTest();
|
| - |
|
131 |
$context = \context_coursecat::instance($this->getDataGenerator()->create_category()->id);
|
| - |
|
132 |
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
| - |
|
133 |
$questioncat = $questiongenerator->create_question_category(['contextid' => $context->id]);
|
| - |
|
134 |
// Create a question.
|
| - |
|
135 |
$question = $questiongenerator->create_question('shortanswer', null, ['category' => $questioncat->id]);
|
| - |
|
136 |
// Add tag to question.
|
| - |
|
137 |
\core_tag_tag::set_item_tags('core_question', 'question', $question->id,
|
| - |
|
138 |
$context, ['Banana']);
|
| - |
|
139 |
|
| - |
|
140 |
// Retrieve the question text to display, including the tag, with the tag displayed as a link.
|
| - |
|
141 |
$summary = quiz_question_tostring(question: $question, showtags: true);
|
| - |
|
142 |
// Ensure the tag is enclosed within a link.
|
| - |
|
143 |
$this->assertMatchesRegularExpression('/<a[^>]*>\s*Banana\s*<\/a>/', $summary);
|
| - |
|
144 |
|
| - |
|
145 |
// Retrieve the question text to display, including the tag, but ensure the tag is not displayed as a link.
|
| - |
|
146 |
$summary = quiz_question_tostring(question: $question, showtags: true, displaytaglink: false);
|
| - |
|
147 |
$this->assertMatchesRegularExpression('/<span[^>]*>\s*Banana\s*<\/span>/', $summary);
|
| - |
|
148 |
}
|
| - |
|
149 |
|
| 124 |
/**
|
150 |
/**
|
| 125 |
* @covers ::quiz_question_tostring
|
151 |
* @covers ::quiz_question_tostring
|
| 126 |
*/
|
152 |
*/
|
| 127 |
public function test_quiz_question_tostring_does_not_filter(): void {
|
153 |
public function test_quiz_question_tostring_does_not_filter(): void {
|
| 128 |
$question = new \stdClass();
|
154 |
$question = new \stdClass();
|