/** * @dataProvider calculateScoreForAnswersDataProvider * @param string $mode withComma or withoutComma * @param array $answers * @param integer $expected */ public function testCalculateScoreForAnswers($mode, $answers, $expected) { $exercise = new SpellingAndGrammarCommaExercise(); $data = array(array('questionWithComma' => 'q, w, e', 'questionWithoutComma' => 'q, w e'), array('questionWithComma' => 'qqq www, eee', 'questionWithoutComma' => 'qqq www eee'), array('questionWithComma' => 'rrr, ttt eee www', 'questionWithoutComma' => 'rrr ttt eee www')); $exercise->setQuestionsFromArray($data); $answers = array('answers' => $answers, 'mode' => $mode); $this->assertSame($expected, $exercise->calculateScoreForAnswers($answers)); }
/** * Register answer. * * @param \_OurBrand_\Quiz\Domain\Model\Exercises\SpellingAndGrammarCommaExercise $exercise * @return void */ public function registerAnswerAction($exercise) { $answers = $this->request->hasArgument('answers') ? $this->request->getArgument('answers') : array(); $mode = $this->request->hasArgument('mode') ? $this->request->getArgument('mode') : ''; $answer = array('answers' => $answers, 'mode' => $mode); $score = $exercise->calculateScoreForAnswers($answer); $status = $exercise->isCompleted($answer); // Save the score, for the given answers, on this exercise, during this quiz. $this->exerciseService->registerAnswer($score, $status, $answer, $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'); } }