public function QuizPageTestCase::testPageFeedback in Quiz 6.x
File
- question_types/
quiz_page/ tests/ src/ Functional/ QuizPageTestCase.php, line 176
Class
- QuizPageTestCase
- Test quiz page behavior.
Namespace
Drupal\Tests\quiz_page\FunctionalCode
public function testPageFeedback() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz([
'review_options' => [
'question' => [
'question_feedback' => 'question_feedback',
],
],
]);
// Create the questions.
$question_node1 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 1 body text',
'feedback' => 'This is the feedback for question 1.',
]);
$this
->linkQuestionToQuiz($question_node1, $quiz_node);
// QNR ID 1
$question_node2 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 2 body text',
'feedback' => 'This is the feedback for question 2.',
]);
$this
->linkQuestionToQuiz($question_node2, $quiz_node);
// QNR ID 2
$question_node3 = $this
->createQuestion([
'type' => 'truefalse',
'truefalse_correct' => 1,
'body' => 'TF 3 body text',
'feedback' => 'This is the feedback for question 3.',
]);
$this
->linkQuestionToQuiz($question_node3, $quiz_node);
// QNR ID 3
//
// Create the page.
$page_node1 = $this
->createQuestion([
'type' => 'page',
'body' => 'PG 1 body text',
]);
$this
->linkQuestionToQuiz($page_node1, $quiz_node);
// QNR ID 4
// Go to the manage questions form.
$this
->drupalGet("quiz/{$quiz_node->id()}/questions");
$post = [
// Make the questions have parents.
"question_list[{$question_node1->getRevisionId()}][qqr_pid]" => 4,
"question_list[{$question_node2->getRevisionId()}][qqr_pid]" => 4,
// Mirror what JS would have done by adjusting the weights.
"question_list[{$page_node1->getRevisionId()}][weight]" => 1,
"question_list[{$question_node1->getRevisionId()}][weight]" => 2,
"question_list[{$question_node2->getRevisionId()}][weight]" => 3,
"question_list[{$question_node3->getRevisionId()}][weight]" => 4,
];
$this
->drupalPostForm(NULL, $post, t('Submit'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->id()}/take");
$this
->drupalPostForm(NULL, [
"question[{$question_node1->id()}][answer]" => 1,
"question[{$question_node2->id()}][answer]" => 1,
], t('Next'));
$this
->assertText('This is the feedback for question 1.');
$this
->assertText('This is the feedback for question 2.');
$this
->assertNoText('This is the feedback for question 3.');
}