You are here

public function MatchingTestCase::testTakeQuestion in Quiz 8.5

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

Test using a matching question inside a quiz.

File

question_types/quiz_matching/tests/src/Functional/MatchingTestCase.php, line 53

Class

MatchingTestCase
Test class for matching questions.

Namespace

Drupal\Tests\quiz_matching\Functional

Code

public function testTakeQuestion() {
  $quiz_node = $this
    ->createQuiz(array(
    'review_options' => array(
      'end' => array_combine([
        'answer_feedback',
        'score',
      ], [
        'answer_feedback',
        'score',
      ]),
    ),
  ));
  $question_node = $this
    ->testCreateQuizQuestion();

  // Link the question.
  $this
    ->linkQuestionToQuiz($question_node, $quiz_node);

  // Test that question appears in lists.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/questions");
  $this
    ->assertText('MA 1 title');

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

  // Take the quiz.
  $this
    ->drupalGet("quiz/{$quiz_node->id()}/take");
  $this
    ->assertNoText('MA 1 title');
  $this
    ->assertText('MA 1 body text');
  $this
    ->assertText('MAQ 1');
  $this
    ->assertText('MAQ 2');
  $this
    ->assertText('MAQ 3');
  $this
    ->assertText('MAA 1');
  $this
    ->assertText('MAA 2');
  $this
    ->assertText('MAA 3');

  // Test validation.
  $this
    ->drupalPostForm(NULL, array(), t('Finish'));
  $this
    ->assertText('You need to match at least one of the items.');

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

  // We may not have MCQ feedback, since it always displays. Question feedback can be used.

  //$this->assertText('MAF 1');

  //$this->assertText('MAF 2');

  //$this->assertText('MAF 3');
  $this
    ->assertText('You got 3 of 3 possible points.');

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

  // We may not have MCQ feedback, since it always displays. Question feedback can be used.

  //$this->assertText('MAF 1');

  //$this->assertText('MAF 2');

  // The behavior right now is that all the feedback shows.

  //$this->assertText('MAF 3');
  $this
    ->assertText('You got 2 of 3 possible points.');
}