public function createShow() { $app = \Slim\Slim::getInstance(); $question = new M_Question(); $questionList = $question->getAllQuestions(); $app->render('Quiz/create.twig', ['question_list' => $questionList]); }
public function show() { $app = \Slim\Slim::getInstance(); $questions = new M_Question(); $questionList = $questions->getAllQuestions(); $app->render('Question/show.twig', ['question_list' => $questionList]); }
public function testCreateQuestion() { //問題のモデルを作成して追加1 $createQuestion1 = new M_Question(); $id1 = $createQuestion1->createQuestion('タイトル1', '問題文1', '選択肢1', '選択肢2', '選択肢3', '選択肢4', '1'); //問題のモデルを作成して追加2 $createQuestion2 = new M_Question(); $id2 = $createQuestion2->createQuestion('タイトル2', '問題文2', '選択肢21', '選択肢22', '選択肢23', '選択肢24', '2'); //問題の全件参照 $showQuestion = new M_Question(); $actual = $showQuestion->getAllQuestions(); //問題を作成した結果、4(初期11件、追加2件)件であることを確認 $this->assertEquals(13, count($actual)); //今回作成した問題の期待結果を作成 $expected1 = array('title' => 'タイトル1', 'content' => '問題文1', 'choice1' => '選択肢1', 'choice2' => '選択肢2', 'choice3' => '選択肢3', 'choice4' => '選択肢4', 'correct_answer' => 1); $expected2 = array('title' => 'タイトル2', 'content' => '問題文2', 'choice1' => '選択肢21', 'choice2' => '選択肢22', 'choice3' => '選択肢23', 'choice4' => '選択肢24', 'correct_answer' => 2); //今回追加した1番目のレコードを参照 $actual1 = M_Question::find($id1); $this->assertEquals($expected1['title'], $actual1['original']['title']); $this->assertEquals($expected1['content'], $actual1['original']['content']); $this->assertEquals($expected1['choice1'], $actual1['original']['choice1']); $this->assertEquals($expected1['choice2'], $actual1['original']['choice2']); $this->assertEquals($expected1['choice3'], $actual1['original']['choice3']); $this->assertEquals($expected1['choice4'], $actual1['original']['choice4']); $this->assertEquals($expected1['correct_answer'], $actual1['original']['correct_answer']); //今回追加した2番目のレコードを参照 $actual2 = M_Question::find($id2); //問題2の内容確認 $this->assertEquals($expected2['title'], $actual2['original']['title']); $this->assertEquals($expected2['content'], $actual2['original']['content']); $this->assertEquals($expected2['choice1'], $actual2['original']['choice1']); $this->assertEquals($expected2['choice2'], $actual2['original']['choice2']); $this->assertEquals($expected2['choice3'], $actual2['original']['choice3']); $this->assertEquals($expected2['choice4'], $actual2['original']['choice4']); $this->assertEquals($expected2['correct_answer'], $actual2['original']['correct_answer']); }