protected function setUp() { $schema_sql = file_get_contents(TEST_SCHEMA_SQL); \Illuminate\Database\Capsule\Manager::connection()->getPdo()->exec($schema_sql); $createQuestion0 = new M_Question(); $createQuestion0->createQuestion('タイトル0', '問題文00', '選択肢01', '選択肢02', '選択肢03', '選択肢04', 4); $createQuestion00 = new M_Question(); $createQuestion00->createQuestion('タイトル00', '問題文00', '選択肢10', '選択肢20', '選択肢30', '選択肢40', 3); $createQuestion000 = new M_Question(); $createQuestion000->createQuestion('タイトル000', '問題文000', '選択肢100', '選択肢200', '選択肢300', '選択肢400', 3); $createQuestion0000 = new M_Question(); $createQuestion0000->createQuestion('タイトル0000', '問題文0000', '選択肢1000', '選択肢2000', '選択肢3000', '選択肢4000', 3); $createQuestion00000 = new M_Question(); $createQuestion00000->createQuestion('タイトル00000', '問題文00000', '選択肢10000', '選択肢20000', '選択肢30000', '選択肢40000', 3); $createQuestion000000 = new M_Question(); $createQuestion000000->createQuestion('タイトル000000', '問題文00000000', '選択肢10000000', '選択肢20000000', '選択肢30000000', '選択肢40000000', 3); $createQuestion0000000 = new M_Question(); $createQuestion0000000->createQuestion('タイトル0000000', '問題文0000000', '選択肢1000000', '選択肢2000000', '選択肢3000000', '選択肢4000000', 3); $createQuestion00000000 = new M_Question(); $createQuestion00000000->createQuestion('タイトル00000000', '問題文00000000', '選択肢10000000', '選択肢20000000', '選択肢30000000', '選択肢40000000', 3); $createQuestion000000000 = new M_Question(); $createQuestion000000000->createQuestion('タイトル000000000', '問題文000000000', '選択肢100000000', '選択肢200000000', '選択肢300000000', '選択肢400000000', 3); $createQuestion0000000000 = new M_Question(); $createQuestion0000000000->createQuestion('タイトル0000000000', '問題文0000000000', '選択肢1000000000', '選択肢2000000000', '選択肢3000000000', '選択肢4000000000', 3); $createQuestion999 = new M_Question(); $createQuestion999->createQuestion('タイトル999', '問題文999', '選択肢1999', '選択肢2999', '選択肢3999', '選択肢4999', 3); $quiz = new M_Quiz(); $title = 'クイズタイトルテスト0'; $quizlist = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); //クイズを作成 $quizId = $quiz->createQuiz($title, $quizlist); }
public function createQuestion() { $app = \Slim\Slim::getInstance(); $params = $app->request->params(); $error_list = V_Question::byArray($params); if (empty($error_list)) { $question = new M_Question(); $questionId = $question->createQuestion($params['title'], $params['content'], $params['choice1'], $params['choice2'], $params['choice3'], $params['choice4'], $params['correct_answer']); $app->redirect('/quiz/questions'); } else { $app->render('Question/create.twig', ['params' => $params, 'error_list' => $error_list]); } }
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']); }