Línea 30... |
Línea 30... |
30 |
*
|
30 |
*
|
31 |
* @package qtype_essay
|
31 |
* @package qtype_essay
|
32 |
* @copyright 2009 The Open University
|
32 |
* @copyright 2009 The Open University
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
34 |
*/
|
34 |
*/
|
35 |
class question_test extends \advanced_testcase {
|
35 |
final class question_test extends \advanced_testcase {
|
36 |
public function test_get_question_summary(): void {
|
36 |
public function test_get_question_summary(): void {
|
37 |
$essay = \test_question_maker::make_an_essay_question();
|
37 |
$essay = \test_question_maker::make_an_essay_question();
|
38 |
$essay->questiontext = 'Hello <img src="http://example.com/globe.png" alt="world" />';
|
38 |
$essay->questiontext = 'Hello <img src="http://example.com/globe.png" alt="world" />';
|
39 |
$this->assertEquals('Hello [world]', $essay->get_question_summary());
|
39 |
$this->assertEquals('Hello [world]', $essay->get_question_summary());
|
40 |
}
|
40 |
}
|
Línea 78... |
Línea 78... |
78 |
/**
|
78 |
/**
|
79 |
* Data provider for summarise_response() test cases.
|
79 |
* Data provider for summarise_response() test cases.
|
80 |
*
|
80 |
*
|
81 |
* @return array List of data sets (test cases)
|
81 |
* @return array List of data sets (test cases)
|
82 |
*/
|
82 |
*/
|
83 |
public function summarise_response_provider(): array {
|
83 |
public static function summarise_response_provider(): array {
|
84 |
return [
|
84 |
return [
|
85 |
'text input required, not attachments required' =>
|
85 |
'text input required, not attachments required' =>
|
86 |
[1, 0, 'This is the text input for this essay.', 0, 'This is the text input for this essay.'],
|
86 |
[1, 0, 'This is the text input for this essay.', 0, 'This is the text input for this essay.'],
|
87 |
'Text input required, one attachments required, one uploaded' =>
|
87 |
'Text input required, one attachments required, one uploaded' =>
|
88 |
[1, 1, 'This is the text input for this essay.', 1, 'This is the text input for this essay.Attachments: 0 (1 bytes)'],
|
88 |
[1, 1, 'This is the text input for this essay.', 1, 'This is the text input for this essay.Attachments: 0 (1 bytes)'],
|
Línea 329... |
Línea 329... |
329 |
/**
|
329 |
/**
|
330 |
* Test get_validation_error when users submit their input text.
|
330 |
* Test get_validation_error when users submit their input text.
|
331 |
*
|
331 |
*
|
332 |
* (The tests are done with a fixed 14-word response.)
|
332 |
* (The tests are done with a fixed 14-word response.)
|
333 |
*
|
333 |
*
|
334 |
* @dataProvider get_min_max_wordlimit_test_cases()
|
334 |
* @dataProvider get_min_max_wordlimit_test_cases
|
335 |
* @param int $responserequired whether response required (yes = 1, no = 0)
|
335 |
* @param int $responserequired whether response required (yes = 1, no = 0)
|
336 |
* @param int $minwordlimit minimum word limit
|
336 |
* @param int $minwordlimit minimum word limit
|
337 |
* @param int $maxwordlimit maximum word limit
|
337 |
* @param int $maxwordlimit maximum word limit
|
338 |
* @param string $expected error message | null
|
338 |
* @param string $expected error message | null
|
339 |
*/
|
339 |
*/
|
Línea 351... |
Línea 351... |
351 |
/**
|
351 |
/**
|
352 |
* Data provider for get_validation_error test.
|
352 |
* Data provider for get_validation_error test.
|
353 |
*
|
353 |
*
|
354 |
* @return array the test cases.
|
354 |
* @return array the test cases.
|
355 |
*/
|
355 |
*/
|
356 |
public function get_min_max_wordlimit_test_cases(): array {
|
356 |
public static function get_min_max_wordlimit_test_cases(): array {
|
357 |
return [
|
357 |
return [
|
358 |
'text input required, min/max word limit not set' => [1, 0, 0, ''],
|
358 |
'text input required, min/max word limit not set' => [1, 0, 0, ''],
|
359 |
'text input required, min/max word limit valid (within the boundaries)' => [1, 10, 25, ''],
|
359 |
'text input required, min/max word limit valid (within the boundaries)' => [1, 10, 25, ''],
|
360 |
'text input required, min word limit not reached' => [1, 15, 25,
|
360 |
'text input required, min word limit not reached' => [1, 15, 25,
|
361 |
get_string('minwordlimitboundary', 'qtype_essay', ['count' => 14, 'limit' => 15])],
|
361 |
get_string('minwordlimitboundary', 'qtype_essay', ['count' => 14, 'limit' => 15])],
|
Línea 368... |
Línea 368... |
368 |
/**
|
368 |
/**
|
369 |
* Test get_word_count_message_for_review when users submit their input text.
|
369 |
* Test get_word_count_message_for_review when users submit their input text.
|
370 |
*
|
370 |
*
|
371 |
* (The tests are done with a fixed 14-word response.)
|
371 |
* (The tests are done with a fixed 14-word response.)
|
372 |
*
|
372 |
*
|
373 |
* @dataProvider get_word_count_message_for_review_test_cases()
|
373 |
* @dataProvider get_word_count_message_for_review_test_cases
|
374 |
* @param int|null $minwordlimit minimum word limit
|
374 |
* @param int|null $minwordlimit minimum word limit
|
375 |
* @param int|null $maxwordlimit maximum word limit
|
375 |
* @param int|null $maxwordlimit maximum word limit
|
376 |
* @param string $expected error message | null
|
376 |
* @param string $expected error message | null
|
377 |
*/
|
377 |
*/
|
378 |
public function test_get_word_count_message_for_review(?int $minwordlimit, ?int $maxwordlimit, string $expected): void {
|
378 |
public function test_get_word_count_message_for_review(?int $minwordlimit, ?int $maxwordlimit, string $expected): void {
|
Línea 387... |
Línea 387... |
387 |
/**
|
387 |
/**
|
388 |
* Data provider for test_get_word_count_message_for_review.
|
388 |
* Data provider for test_get_word_count_message_for_review.
|
389 |
*
|
389 |
*
|
390 |
* @return array the test cases.
|
390 |
* @return array the test cases.
|
391 |
*/
|
391 |
*/
|
392 |
public function get_word_count_message_for_review_test_cases() {
|
392 |
public static function get_word_count_message_for_review_test_cases(): array {
|
393 |
return [
|
393 |
return [
|
394 |
'No limit' =>
|
394 |
'No limit' =>
|
395 |
[null, null, ''],
|
395 |
[null, null, ''],
|
396 |
'min and max, answer within range' =>
|
396 |
'min and max, answer within range' =>
|
397 |
[10, 25, get_string('wordcount', 'qtype_essay', 14)],
|
397 |
[10, 25, get_string('wordcount', 'qtype_essay', 14)],
|