/** * Persist given answer(s) for the exercise by current StudentQuizSession. * Each correct answer gives a point. Certain questions can give multiple points. * * @param \_OurBrand_\Quiz\Domain\Model\Exercises\MultipleChoiceSameAnswerExercise $exercise */ public function registerAnswerAction($exercise) { $answers = $this->request->hasArgument('question') ? $this->request->getArgument('question') : array(); $score = $exercise->calculateScoreForAnswers($answers); $status = $exercise->isCompleted($answers); // Save the score, for the given answers, on this exercise, during this quiz. $this->exerciseService->registerAnswer($score, $status, $answers, $exercise, $this->studentQuizSession); $this->studentQuizSessionService->updateProgress($this->studentQuizSession); $this->view->assign('value', array('timeRemaining' => $this->studentQuizSession->getTimeRemaining())); if (!$this->isJson) { $this->redirect('studentnavigate', 'quiz', $this->request->hasArgument('goto') ? $this->request->getArgument('goto') : 'next'); } }
/** * @test * @dataProvider isCompletedDataProvider * @param array $maxScore * @param array $answers * @param int $expected */ public function isCompletedWorks($maxScore, $answers, $expected) { $exercise = new MultipleChoiceSameAnswerExercise(); $exercise->setMaxscore($maxScore); $this->assertSame($expected, $exercise->isCompleted($answers)); }