public function post()
 {
     if (!isset($this->get['survey_id'], $this->post['question'])) {
         $this->message = "Missing one or more required parameters";
         $this->status = 400;
         return;
     }
     $survey = new Survey($this->get['survey_id']);
     if (!$survey->exists()) {
         $this->message = "Survey does not exist";
         $this->status = 404;
         return;
     }
     if (($questionID = $survey->addQuestion($this->post['question'])) === false) {
         $this->message = 'Internal Server Error';
         $this->status = 500;
         return;
     }
     $surveyData = $survey->apiData();
     $this->response[$this->slug][] = $surveyData['questions'][$questionID];
     return;
 }
 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());
 }
 public function testDeleteQuestionFromSurvey()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $qtypes = QuestionType::toArray();
     $max = rand(4, 5);
     for ($i = 0; $i < $max; ++$i) {
         $q = new SurveyQuestion();
         $q->setType(new QuestionType(rand(1, count($qtypes))));
         $q->setQuestion("q" . $i);
         $survey->addQuestion($q);
     }
     $this->manager->createSurvey($survey);
     $toDelete = $survey->getQuestions()[rand(0, $max - 1)];
     $idToDelete = $toDelete->getId();
     $survey->deleteQuestion($idToDelete);
     $this->manager->updateSurvey($survey);
     $this->assertEquals($max - 1, count($survey->getQuestions()));
 }
 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?
 }