Ejemplo n.º 1
0
 function testStringSurveyQuestion()
 {
     $v = new AnswerValidatorProvider();
     $q = $v->getValidator(QuestionType::Text());
     $this->assertFalse($q->isValid(NULL));
     $this->assertFalse($q->isValid(""));
     $this->assertFalse($q->isValid(" "));
     $this->assertTrue($q->isValid("anything else"));
     $this->assertFalse($q->isValid(null));
 }
Ejemplo n.º 2
0
 function testMultipleQuestions()
 {
     $manager = $this->newSurveyService();
     $thankYou = "Thank you for filling out the survey. Visit us at farooqmasjid.org";
     $max = 5;
     $qs[0] = "Rate us";
     $qt[0] = QuestionType::StarRating();
     $qs[1] = "What did you like?";
     $qt[1] = QuestionType::Text();
     $qs[2] = "Would you attend another event like this? (yes or no)";
     $qt[2] = QuestionType::YesNo();
     $s = new Survey();
     $s->setSurveyName("my name is john");
     $s->setDescription("a survey");
     $s->setThankYouMessage($thankYou);
     for ($i = 0; $i < count($qs); ++$i) {
         $sq = new SurveyQuestion();
         $sq->setQuestion($qs[$i]);
         $sq->setType($qt[$i]);
         $s->addQuestion($sq);
     }
     $this->surveyManager->createSurvey($s);
     SurveyEntityManager::testClear();
     $this->request[SurveyRequestService::BODY_KEY] = $s->getSurveyName();
     $serviced = $manager->service();
     $res = $manager->getResponse();
     $this->assertTrue($serviced);
     $this->assertNotNull($res);
     $this->assertTrue(count($res->getContent()) > 0);
     $this->assertContains($qs[0], $res->getContent(), "Checking first question returned");
     $this->request[SurveyRequestService::BODY_KEY] = 3;
     $serviced = $manager->service();
     $this->assertTrue($serviced);
     $res = $manager->getResponse();
     $this->assertContains($qs[1], $res->getContent(), "Checking second question returned");
     $this->request[SurveyRequestService::BODY_KEY] = "I loved and loved and .36879176^&*@#;;!2";
     $serviced = $manager->service();
     $this->assertTrue($serviced);
     $res = $manager->getResponse();
     $this->assertContains($qs[2], $res->getContent(), "Checking third question returned");
     $this->request[SurveyRequestService::BODY_KEY] = 'Yes';
     $serviced = $manager->service();
     $this->assertTrue($serviced);
     $res = $manager->getResponse();
     $this->assertTrue(strstr($res->getContent(), $thankYou) !== false);
 }
Ejemplo n.º 3
0
 public function testAddQuestions()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $num = rand(3, 10);
     for ($i = 0; $i < $num; ++$i) {
         $q = new SurveyQuestion();
         $q->setType(QuestionType::Text());
         $q->setQuestion("q{$i}");
         $survey->addQuestion($q);
     }
     $this->manager->createSurvey($survey);
     SurveyEntityManager::testClear();
     $ss = $this->manager->getSurvey($survey->getId());
     $this->assertEquals($ss->getId(), $survey->getId());
     $this->assertNotNull($ss->getQuestions());
     $this->assertEquals($num, count($ss->getQuestions()));
     $q = $ss->getQuestions()[$num - 1];
     $this->assertNotNull($q);
     $this->assertEquals("q" . ($num - 1), $q->getQuestion());
     $this->assertEquals(QuestionType::Text(), $q->getType());
 }
 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?
 }