You are here

public function QuizTrueFalseTestCase::testEditQuestionResponse in Quiz 8.6

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

Test that the question response can be edited.

File

question_types/quiz_truefalse/tests/src/Functional/QuizTrueFalseTestCase.php, line 113

Class

QuizTrueFalseTestCase
Test class for true false questions.

Namespace

Drupal\Tests\quiz_truefalse\Functional

Code

public function testEditQuestionResponse() {

  // Create & link a question.
  $question = $this
    ->testCreateQuizQuestion();
  $quiz = $this
    ->linkQuestionToQuiz($question);
  $quiz
    ->set('backwards_navigation', 1);
  $quiz
    ->set('allow_change', 1);
  $quiz
    ->save();
  $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]" => 0,
  ), t('Next'));
  $this
    ->drupalGet("quiz/{$quiz->id()}/take/1");
  $this
    ->drupalPostForm(NULL, array(
    "question[{$question->id()}][answer]" => 1,
  ), t('Next'));
}