Commit c43cee24 authored by Amisha Patel's avatar Amisha Patel Committed by Devin Zuczek
Browse files

Issue #3282760 by djdevin, a-patel: Quizzes with pages or directions are not marked as evaluated

parent fc5ff3d4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ class QuizDirectionsResponse extends QuizResultAnswer {
   * {@inheritdoc}
   */
  public function score(array $values): ?int {
    // We have scored the question.
    $this->setEvaluated();
    return 0;
  }

+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ class QuizPageResponse extends QuizResultAnswer {
   * {@inheritdoc}
   */
  public function score(array $values): ?int {
    // We have scored the question.
    $this->setEvaluated();
    return NULL;
  }

+9 −0
Original line number Diff line number Diff line
@@ -657,4 +657,13 @@ class QuizResult extends ContentEntityBase implements EntityOwnerInterface, Enti
      ($request_time > ($time_start + $time_limit + $time_limit_buffer)));
  }

  /**
   * Check if this result has been evaluated (graded).
   *
   * @return bool
   */
  function isEvaluated() {
    return (bool) $this->get('is_evaluated')->getString();
  }

}
+50 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\quiz\Functional;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\quiz\Entity\QuizResult;

/**
 * Test quiz evaluation.
 *
 * @group Quiz
 */
class QuizEvaluationTest extends QuizTestBase {

  use StringTranslationTrait;

  protected static $modules = ['quiz_page', 'quiz_directions'];

  /**
   * Test that a quiz result is marked as evaluated.
   */
  public function testQuizEvaluation() {
    $this->drupalLogin($this->admin);

    $quiz_node = $this->createQuiz();

    $question_node1 = $this->createQuestion([
      'type' => 'directions',
      'body' => 'These are the quiz directions.',
    ]);
    $this->linkQuestionToQuiz($question_node1, $quiz_node); // QNR ID 1

    $page_node1 = $this->createQuestion(['type' => 'page']);
    $this->linkQuestionToQuiz($page_node1, $quiz_node); // QNR ID 2

    $this->drupalGet("quiz/{$quiz_node->id()}/questions");
    $post = [
      "question_list[{$question_node1->getRevisionId()}][qqr_pid]" => 2,
    ];
    $this->submitForm($post, $this->t('Submit'));

    $this->drupalLogin($this->user);
    $this->drupalGet("quiz/{$quiz_node->id()}/take");
    $this->submitForm([
    ], $this->t('Finish'));

    $quiz_result = QuizResult::load(1);
    $this->assertEquals(true, $quiz_result->isEvaluated());
  }
}