Example #1
0
 public function action_delete($id = null)
 {
     if ($form = Model_Form::find($id)) {
         $form->delete();
         Session::set_flash('success', e('Deleted form #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete form #' . $id));
     }
     Response::redirect('admin/form');
 }
Example #2
0
 public function test_新規データをテーブルに保存する()
 {
     $data = array('name' => '藤原義孝', 'email' => '*****@*****.**', 'comment' => '君がため 惜しからざりし 命さえ 長くもがなと 思ひけるかな', 'ip_address' => '10.11.12.13', 'user_agent' => 'Mozilla/2.02 (Macintosh; I; PPC)');
     $form = Model_Form::forge($data);
     // 新規データをデータベースに挿入
     $ret = $form->save();
     // 挿入されたデータをデータベースから検索
     $form = Model_Form::find($form->id);
     foreach ($data as $field => $value) {
         $this->assertEquals($value, $form[$field]);
     }
 }
Example #3
0
 public function action_send()
 {
     // CSRF対策
     if (!Security::check_token()) {
         throw new HttpInvalidInputException('ページ遷移が正しくありません');
     }
     $form = $this->forge_form();
     $val = $form->validation()->add_callable('MyValidationRules');
     if (!$val->run()) {
         $form->repopulate();
         $this->template->title = 'コンタクトフォーム: エラー';
         $this->template->content = View::forge('form/index');
         $this->template->content->set_safe('html_error', $val->show_errors());
         $this->template->content->set_safe('html_form', $form->build('form/confirm'));
         return;
     }
     $post = $val->validated();
     $post['ip_address'] = Input::ip();
     $post['user_agent'] = Input::user_agent();
     unset($post['submit']);
     // データベースへ保存
     $model_form = Model_Form::forge($post);
     $ret = $model_form->save();
     if (!$ret) {
         Log::error('データベース保存エラー', __METHOD__);
         $form->repopulate();
         $this->template->title = 'コンタクトフォーム: サーバエラー';
         $this->template->content = View::forge('form/index');
         $html_error = '<p>サーバでエラーが発生しました。</p>';
         $this->template->content->set_safe('html_error', $html_error);
         $this->template->content->set_safe('html_form', $form->build('form/confirm'));
         return;
     }
     // メールの送信
     try {
         $mail = new Model_Mail();
         $mail->send($post);
         $this->template->title = 'コンタクトフォーム: 送信完了';
         $this->template->content = View::forge('form/send');
         return;
     } catch (EmailValidationFailedException $e) {
         Log::error('メール検証エラー: ' . $e->getMessage(), __METHOD__);
         $html_error = '<p>メールアドレスに誤りがあります。</p>';
     } catch (EmailSendingFailedException $e) {
         Log::error('メール送信エラー: ' . $e->getMessage(), __METHOD__);
         $html_error = '<p>メールを送信できませんでした。</p>';
     }
     $form->repopulate();
     $this->template->title = 'コンタクトフォーム: 送信エラー';
     $this->template->content = View::forge('form/index');
     $this->template->content->set_safe('html_error', $html_error);
     $this->template->content->set_safe('html_form', $form->build('form/confirm'));
 }
Example #4
0
 public function testgetForm()
 {
     $modelArray = array('style' => '', 'id' => 1);
     $getAllResult = array(array('options' => '{"options":["hidden"]}', 'default_value' => 'TestingValue'));
     $model = new \Model_Form();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $dbMock->expects($this->atLeastOnce())->method('toArray')->will($this->returnValue($modelArray));
     $dbMock->expects($this->atLeastOnce())->method('getAll')->will($this->returnValue($getAllResult));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $formId = 1;
     $this->service->setDi($di);
     $result = $this->service->getForm($formId);
     $this->assertInternalType('array', $result);
 }
Example #5
0
 public function test_送信したデータの検証()
 {
     $form = Model_Form::find(4);
     foreach (static::$post as $field => $value) {
         $this->assertEquals($value, $form[$field]);
     }
 }