/** * Execute the console command. * * @return mixed */ public function fire() { ini_set('max_execution_time', 0); $data = DB::select('select * from answer_type'); $insert = []; foreach ($data as $d) { $insert[] = ['id' => $d->id, 'type' => $d->type, 'description' => $d->description]; } QuestionType::insert($insert); }
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)); }
function testSurveyState() { $questionStub = $this->getMock('sarhan\\survey\\SurveyQuestion'); $surveyStub = $this->getMock("sarhan\\survey\\Survey"); $surveyStub->expects($this->any())->method('getQuestions')->will($this->returnValue(array($questionStub, $questionStub, $questionStub))); $questionStub->expects($this->any())->method("getType")->will($this->returnValue(QuestionType::YesNo())); $this->assertEquals(array($questionStub, $questionStub, $questionStub), $surveyStub->getQuestions()); $s = new SurveyState(); $s->setSurvey($surveyStub); $this->assertFalse($s->hasId()); $s->setId("foobar"); $this->assertTrue($s->hasId()); $s->setQuestionIndex(0); $q = $s->getQuestion(); $this->assertNotNull($q); $s->setQuestionIndex(3); $q = $s->getQuestion(); $this->assertNull($q); }
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()); }
<?php require_once 'QuestionList.php'; require_once 'QuestionType.php'; require_once 'QuestionLevel.php'; header('content-type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); $questionTypeId = isset($_GET['typeId']) ? $_GET['typeId'] : null; $levelIds = isset($_GET['levelIds']) ? $_GET['levelIds'] : array(); $question = new QuestionList(); $questionType = new QuestionType(); $questionLevel = new QuestionLevel(); $resp = array(); $resp['questionList'] = $question->getAllQuestions($questionTypeId, $levelIds); $resp['questionTypes'] = $questionType->getAllQuestionTypes(); $resp['questionLevels'] = $questionLevel->getAllquestionLevels(); $resp['questionTypeId'] = $questionTypeId; $resp = json_encode($resp); echo $_REQUEST['callback'] . '(' . $resp . ')';
public function testQuestionHint() { $qt = QuestionType::YesNo(); $this->assertEquals("(Y or N)", $qt->getQuestionHint()); }
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? }
public function getValidator(QuestionType $type) { return $this->validators[$type->getValue()]; }
/** * @param QuestionType $type */ public function setType(QuestionType $type) { $this->type = $type->getValue(); }