public function QuizPageTestCase::testPageFeedback in Quiz 8.6
Same name in this branch
- 8.6 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.php \QuizPageTestCase::testPageFeedback()
- 8.6 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()
Same name and namespace in other branches
- 8.5 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.php \QuizPageTestCase::testPageFeedback()
- 8.5 question_types/quiz_page/tests/src/Functional/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()
- 7.5 question_types/quiz_page/QuizPageTestCase.test \QuizPageTestCase::testPageFeedback()
File
- question_types/
quiz_page/ tests/ src/ Functional/ QuizPageTestCase.test, line 169
Class
Code
public function testPageFeedback() {
$this
->drupalLogin($this->admin);
$quiz_node = $this
->createQuiz(array(
'review_options' => array(
'question' => array(
'question_feedback' => 'question_feedback',
),
),
));
// Create the questions.
$question_node1 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'TF 1 body text',
),
),
),
));
$this
->linkQuestionToQuiz($question_node1, $quiz_node);
// QNR ID 1
$question_node2 = $this
->drupalCreateNode(array(
'type' => 'truefalse',
'correct_answer' => 1,
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'TF 2 body text',
),
),
),
));
// Set feedback.
$entities = entity_load('quiz_question', FALSE, array(
'nid' => $question_node1->nid,
'vid' => $question_node1->vid,
));
$quiz_question = reset($entities);
$quiz_question->feedback = 'This is the feedback for question 1.';
$quiz_question->feedback_format = filter_default_format();
entity_save('quiz_question', $quiz_question);
$entities = entity_load('quiz_question', FALSE, array(
'nid' => $question_node2->nid,
'vid' => $question_node2->vid,
));
$quiz_question = reset($entities);
$quiz_question->feedback = 'This is the feedback for question 2.';
$quiz_question->feedback_format = filter_default_format();
entity_save('quiz_question', $quiz_question);
$this
->linkQuestionToQuiz($question_node2, $quiz_node);
// QNR ID 2
// Create the page.
$page_node1 = $this
->drupalCreateNode(array(
'type' => 'quiz_page',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'PG 1 body text',
),
),
),
));
$this
->linkQuestionToQuiz($page_node1, $quiz_node);
// QNR ID 3
// Go to the manage questions form.
$this
->drupalGet("quiz/{$quiz_node->nid}/quiz/questions");
$post = array(
// Make the questions have parents.
"qqr_pids[{$question_node1->nid}-{$question_node1->vid}]" => 3,
"qqr_pids[{$question_node2->nid}-{$question_node2->vid}]" => 3,
// Mirror what JS would have done by adjusting the weights.
"weights[{$page_node1->nid}-{$page_node1->vid}]" => 1,
"weights[{$question_node1->nid}-{$question_node1->vid}]" => 2,
"weights[{$question_node2->nid}-{$question_node2->vid}]" => 3,
);
$this
->drupalPostForm(NULL, $post, t('Submit'));
$this
->drupalLogin($this->user);
$this
->drupalGet("quiz/{$quiz_node->nid}/take");
$this
->drupalPostForm(NULL, array(
"question[{$question_node1->nid}][answer]" => 1,
"question[{$question_node2->nid}][answer]" => 1,
), t('Finish'));
$this
->assertText('This is the feedback for question 1');
$this
->assertText('This is the feedback for question 2');
}