MDL-87018 qtype_essay: Add unit tests for un_summarise_response().
This commit is contained in:
@@ -31,6 +31,7 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
* @package qtype_essay
|
||||
* @copyright 2009 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \qtype_essay_question
|
||||
*/
|
||||
final class question_test extends \advanced_testcase {
|
||||
public function test_get_question_summary(): void {
|
||||
@@ -100,6 +101,58 @@ final class question_test extends \advanced_testcase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test un_summarise_response().
|
||||
*
|
||||
* @dataProvider un_summarise_response_provider
|
||||
* @param string $responseformat
|
||||
* @param string $summary
|
||||
* @param array $expected
|
||||
*/
|
||||
public function test_un_summarise_response(string $responseformat, string $summary, array $expected): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$essay = \test_question_maker::make_an_essay_question();
|
||||
$essay->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$essay->responseformat = $responseformat;
|
||||
|
||||
$this->assertEquals($expected, $essay->un_summarise_response($summary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_un_summarise_response().
|
||||
*
|
||||
* Covers multiple response formats, empty responses,
|
||||
* case sensitivity, unicode text, and HTML content.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function un_summarise_response_provider(): array {
|
||||
return [
|
||||
'empty summary returns empty array' => [
|
||||
'plain',
|
||||
'',
|
||||
[],
|
||||
],
|
||||
'plain format returns plain text' => [
|
||||
'plain',
|
||||
'Hello Moodle',
|
||||
['answer' => 'Hello Moodle', 'answerformat' => FORMAT_PLAIN],
|
||||
],
|
||||
'editor format converts to HTML' => [
|
||||
'editor',
|
||||
'Hello Moodle',
|
||||
['answer' => text_to_html('Hello Moodle'), 'answerformat' => FORMAT_HTML],
|
||||
],
|
||||
'plain format preserves HTML tags literally' => [
|
||||
'plain',
|
||||
'<b>bold</b>',
|
||||
['answer' => '<b>bold</b>', 'answerformat' => FORMAT_PLAIN],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_is_same_response(): void {
|
||||
$essay = \test_question_maker::make_an_essay_question();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user