Пример #1
0
 static function findById($search_id)
 {
     $found_question = null;
     $returned_questions = Question::getAll();
     foreach ($returned_questions as $question) {
         $id = $question->getId();
         if ($search_id == $id) {
             $found_question = $question;
         }
     }
     return $found_question;
 }
Пример #2
0
 public static function manage()
 {
     self::ensureAdmin();
     // Handle creation of vanilla questions.
     $createVanillaData = self::createVanilla();
     // Handle deletion of questions.
     self::delete();
     // Handle editing of questions.
     self::edit();
     // Load all questions.
     $questions = Question::getAll();
     $typeMap = mapDataArrayByField($questions, function (Question $each) {
         return $each->getVanilla();
     }, [true => 'vanilla', false => 'custom']);
     $viewData = ['vanilla' => [], 'custom' => []];
     foreach ($typeMap['vanilla'] as $vanilla) {
         $viewData['vanilla'][] = $vanilla->getData();
     }
     foreach ($typeMap['custom'] as $custom) {
         $viewData['custom'][] = $custom->getData();
     }
     self::render('admin/questions', array_merge($viewData, $createVanillaData));
 }
Пример #3
0
 function test_delete()
 {
     //Arrange
     $test_field = "What is their name?";
     $test_description = "What you want to call your character.";
     $test_question = new Question($test_field, $test_description);
     $test_question->save();
     $test_field2 = "What is their profession?";
     $test_description2 = "What you want your character to do.";
     $test_question2 = new Question($test_field2, $test_description2);
     $test_question2->save();
     //Act
     $test_question->delete();
     $result = Question::getAll();
     //Assert
     $this->assertEquals($test_question2, $result[0]);
 }
Пример #4
0
 function test_getQuestions()
 {
     $name = "mikes 5 top interview questions";
     $test_promptr = new Promptr($name);
     $test_promptr->save();
     $question = "What is your biggest weakness punk?";
     $description = "This question goes straight for the jugular";
     $test_question = new Question($question, $description);
     $test_question->save();
     $test_promptr->addQuestion($test_question);
     $question2 = "Who are you really?";
     $description2 = "I mean really really";
     $test_question2 = new Question($question2, $description2);
     $test_question2->save();
     $test_promptr->addQuestion($test_question2);
     $result = Question::getAll();
     $end_question = new Question($question, $description, $result[0]->getId());
     $end_question2 = new Question($question2, $description2, $result[1]->getId());
     $this->assertEquals([$end_question, $end_question2], $result);
 }