Skip to content

Instantly share code, notes, and snippets.

@RyosukeKamei
Last active July 17, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyosukeKamei/9a395146356a2c186d2efbec0bf6b05c to your computer and use it in GitHub Desktop.
Save RyosukeKamei/9a395146356a2c186d2efbec0bf6b05c to your computer and use it in GitHub Desktop.
コーディング規則「優しいコードを書こう」 ref: http://qiita.com/RyosukeKamei/items/e6dbe03dd24dd1511f19
/**
* create_choices
* 選択肢(4つ)を生成
*
* @param int $question_last_id question.id
* @return boolean
*/
private function create_choices($question_last_id) {
/*
* IPA系の試験は選択肢は4つある
*/
for($choice_num = 1; $choice_num run())
{
/*
* 問題を追加するINSERT(もしくはUPDATE)を生成
*/
$choice = Model_Choice::forge(array(
'question_id' => $question_last_id, // 問題番号(固定)
'choice_num' => $choice_num, // 選択肢番号
'correct_flag' => $correct_flag, // 正解
'choice_body' => Input::post('choice_body_'.$choice_num), // 選択肢
));
if (!($choice and $choice->save()))
{
Session::set_flash('error', '選択肢を追加できませんでした。');
/*
* ●コーディング規則「優しいコードを書こう」
* 8. 早めにreturnし、関数から抜ける
*/
return false;
}
} else
{
Session::set_flash('error', $choice_validation->error());
/*
* ●コーディング規則「優しいコードを書こう」
* 8. 早めにreturnし、関数から抜ける
*/
return false;
}
}
return true;
}
public function test_removed_tag_and_contents() {
/*
* beforequestionから値を取得
*/
$questions = Controller_Question::get_before_question(2);
/*
* 選択肢を除去
*/
$conveted_question_body
/*
* ●コーディング規則「優しいコードを書こう」
* 3. 横幅は80文字以内とし、縦の線をまっすぐにする意識をすると、ソースの可読性が向上する
*/
= Controller_Question::removed_tag_and_contents(
$questions['question_body']
, 'ul'
);
/*
* 選択肢が除去されていれば、除去前と比較して異なる
*/
$this->assertNotEquals(
$conveted_question_body
, $questions['question_body']
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment