You are here

public function QuizMultichoiceTestCase::testEditQuestionResponse in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testEditQuestionResponse()
  2. 6.x question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php \Drupal\Tests\quiz_multichoice\Functional\QuizMultichoiceTestCase::testEditQuestionResponse()

Test that the question response can be edited.

File

question_types/quiz_multichoice/tests/src/Functional/QuizMultichoiceTestCase.php, line 215

Class

QuizMultichoiceTestCase
Test multiple choice questions.

Namespace

Drupal\Tests\quiz_multichoice\Functional

Code

public function testEditQuestionResponse() {

  // Create & link a question.
  $question = $this
    ->testCreateQuizQuestion();
  $quiz = $this
    ->linkQuestionToQuiz($question);
  $question2 = $this
    ->testCreateQuizQuestion();
  $this
    ->linkQuestionToQuiz($question2, $quiz);

  // Login as non-admin.
  $this
    ->drupalLogin($this->user);

  // Take the quiz.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");

  // Test editing a question.
  $this
    ->drupalGet("quiz/{$quiz->id()}/take");
  $this
    ->drupalGet("quiz/{$quiz->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question->id()}][answer][user_answer]" => 1,
  ), t('Next'));
  $this
    ->drupalGet("quiz/{$quiz->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question->id()}][answer][user_answer]" => 2,
  ), t('Next'));
}