MDL-75301 question: Add behat generator for updating questions

This adds "core_question > updated question" as an entity for `the
following "X" exist` and calls the existing update_question() generator
which will create a new question version with the supplied data.
This commit is contained in:
Mark Johnson
2023-04-05 12:49:51 +02:00
committed by Sara Arjona
parent ddaf4b7a58
commit c55473ad2e
@@ -41,6 +41,12 @@ class behat_core_question_generator extends behat_generator_base {
'required' => ['question', 'tag'],
'switchids' => ['question' => 'questionid'],
],
'updated questions' => [
'singular' => 'question',
'datagenerator' => 'updated_question',
'required' => ['question', 'questioncategory'],
'switchids' => ['question' => 'id', 'questioncategory' => 'category'],
],
];
}
@@ -58,4 +64,22 @@ class behat_core_question_generator extends behat_generator_base {
}
return $id;
}
/**
* Update a question
*
* This will update a question matching the supplied name with the provided data, creating a new version in the process.
*
* @param array $data the row of data from the behat script.
* @return void
*/
protected function process_updated_question(array $data): void {
global $DB;
$question = $DB->get_record('question', ['id' => $data['id']], '*', MUST_EXIST);
foreach ($data as $key => $value) {
$question->{$key} = $value;
}
$this->datagenerator->get_plugin_generator('core_question')->update_question($question);
}
}