/**
  * @param string $from
  * @param SurveyQuestion $question
  * @param string $answerString
  */
 private function persistAnswer($from, SurveyQuestion $question, $answerString)
 {
     $answer = new SurveyAnswer();
     $answer->setAnswer($answerString);
     $answer->setAnsweredBy($from);
     //Persist the answer
     $this->surveyManager->addAnswer($question->getId(), $answer);
 }
 public function testTagCloud()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::Text());
     $q->setQuestion("Your Suggestions");
     $survey->addQuestion($q);
     $this->manager->createSurvey($survey);
     $max = rand(1, 20);
     for ($i = 0; $i < $max; ++$i) {
         $val = $this->getRandomString();
         $ans = new SurveyAnswer();
         $ans->setAnswer($val);
         $ans->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q->getId(), $ans);
     }
     $answers = $this->manager->getAnswers($survey->getId());
     $strArr = ReportChartFormatter::getChartData($answers->getAnswers($q->getId()), ChartFormats::TagCloud());
     $this->assertNotNull($strArr);
     //TODO: how the heck do i test this? I guess that it just works?
 }
示例#3
0
 public function testAnswerQuestion()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::StarRating());
     $q->setQuestion("A question");
     $survey->addQuestion($q);
     $this->manager->createSurvey($survey);
     $ss = $this->manager->getSurvey($survey->getId());
     $q = $ss->getQuestions()[0];
     $ans = new SurveyAnswer();
     $ans->setAnswer("awesome!");
     $ans->setAnsweredBy("+12064122496");
     $this->manager->addAnswer($q->getId(), $ans);
     //SurveyEntityManager::testClear();
     $answers = $this->manager->getAnswers($survey->getId());
     $this->assertNotNull($answers);
     $this->assertEquals(1, count($answers));
     $this->assertEquals($answers->getAnswers($q->getId())[0]->getAnswer(), "awesome!");
     $this->assertEquals($answers->getAnswers($q->getId())[0]->getSurveyQuestionId(), $q->getId());
     //add another question
     $q2 = new SurveyQuestion();
     $q2->setType(QuestionType::StarRating());
     $q2->setQuestion("Second question");
     $survey->addQuestion($q2);
     $this->manager->updateSurvey($survey);
     $this->assertNotNull($q2->getId(), "Asserting the second question was saved");
     //Create another survey and question to make sure we do not
     // have leaks.
     $survey2 = new Survey();
     $survey2->setSurveyName("hi2");
     $survey2->setDescription('stuff2');
     $q3 = new SurveyQuestion();
     $q3->setType(QuestionType::StarRating());
     $q3->setQuestion("A question3");
     $survey2->addQuestion($q3);
     $this->manager->createSurvey($survey2);
     //Now lets add a lot more answers!
     $max = rand(1, 10);
     for ($i = 0; $i < $max; ++$i) {
         $ans = new SurveyAnswer();
         $ans->setAnswer("awesome{$i}");
         $ans->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q->getId(), $ans);
         $ans2 = new SurveyAnswer();
         $ans2->setAnswer("2awesome{$i}");
         $ans2->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q2->getId(), $ans2);
         $ans3 = new SurveyAnswer();
         $ans3->setAnswer("don't return me");
         $ans3->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q3->getId(), $ans3);
     }
     $answers = $this->manager->getAnswers($survey->getId());
     $this->assertNotNull($answers);
     $this->assertEquals(1 + $max * 2, $answers->getTotalAnswers());
     $answers = $this->manager->getAnswers($survey2->getId());
     $this->assertNotNull($answers);
     $this->assertEquals($max, $answers->getTotalAnswers());
 }