public function testBarChart()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::StarRating());
     $q->setQuestion("how would you rate the event?");
     $survey->addQuestion($q);
     $this->manager->createSurvey($survey);
     $max = rand(100, 200);
     $ratings = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0);
     for ($i = 0; $i < $max; ++$i) {
         $ans = new SurveyAnswer();
         $rand = rand(1, 5);
         $ratings[$rand]++;
         $ans->setAnswer($rand);
         $ans->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q->getId(), $ans);
     }
     $answers = $this->manager->getAnswers($survey->getId());
     $str = ReportChartFormatter::getChartData($answers->getAnswers($q->getId()), ChartFormats::Bar());
     $this->assertNotNull($str);
     foreach ($ratings as $key => $rating) {
         $this->assertContains('{"key":' . $key . ',"val":' . $rating . '}', $str);
     }
 }
Esempio n. 2
0
 function testStarSurveyQuestion()
 {
     $max = 5;
     $v = new AnswerValidatorProvider();
     $q = $v->getValidator(QuestionType::StarRating());
     $this->assertFalse($q->isValid("what"));
     $this->assertFalse($q->isValid(0));
     $i = 1;
     for (; $i <= $max; ++$i) {
         $this->assertTrue($q->isValid($i));
     }
     $this->assertFalse($q->isValid($i), "Making sure that {$i} is not a valid star rating with max {$max}");
     $this->assertFalse($q->isValid(null));
 }
Esempio n. 3
0
 public function testSurveyName()
 {
     $survey = new Survey();
     $survey->setSurveyName("yesno");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::YesNo());
     $q->setQuestion("A question");
     $survey->addQuestion($q);
     //add another question
     $q2 = new SurveyQuestion();
     $q2->setType(QuestionType::StarRating());
     $secondQuestion = "Second question";
     $q2->setQuestion($secondQuestion);
     $survey->addQuestion($q2);
     $this->surveyManager->createSurvey($survey);
     SurveyEntityManager::testClear();
     $service = $this->newSurveyService();
     $this->request['Body'] = "yesno";
     $this->request['From'] = "1234";
     $serviced = $service->service();
     $this->assertTrue($serviced);
     $this->request['Body'] = "no";
     $this->request['From'] = "1234";
     $serviced = $service->service();
     $this->assertTrue($serviced);
     $this->assertContains($secondQuestion, $service->getResponse()->getContent());
 }
Esempio n. 4
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());
 }