Browse Source

replace Exception on GeneralException

master
Vyacheslav Agafonov 13 years ago
parent
commit
7d215c9af4
  1. 2
      form/Form.php
  2. 6
      form/FormField.php
  3. 4
      form/FormViewHelper.php
  4. 7
      tests/form/FormFieldTest.php
  5. 3
      tests/form/FormTest.php
  6. 8
      tests/form/FormViewHelperTest.php

2
form/Form.php

@ -39,7 +39,7 @@ abstract class Form
public function isValid($data) public function isValid($data)
{ {
if (!is_array($data)) { if (!is_array($data)) {
throw new Exception(__CLASS__ . '::' . __METHOD__ . ' expects an array');
throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array');
} }
foreach ($this->fields as $field_name => $field) { foreach ($this->fields as $field_name => $field) {

6
form/FormField.php

@ -72,7 +72,7 @@ class FormField
$name = $validator . 'Validator'; $name = $validator . 'Validator';
$validator = new $name(); $validator = new $name();
} else { } else {
throw new Exception('Invalid validator provided to addValidator; must be string or iValidator');
throw new InitializationException('Invalid validator provided to addValidator; must be string or iValidator');
} }
$this->validators[$name] = $validator; $this->validators[$name] = $validator;
return $this; return $this;
@ -94,7 +94,7 @@ class FormField
$name = $filter . 'Filter'; $name = $filter . 'Filter';
$filter = new $name(); $filter = new $name();
} else { } else {
throw new Exception('Invalid filter provided to addFilter; must be string or iFilter');
throw new InitializationException('Invalid filter provided to addFilter; must be string or iFilter');
} }
$this->filters[$name] = $filter; $this->filters[$name] = $filter;
return $this; return $this;
@ -147,7 +147,7 @@ class FormField
if (!$validator->isValid($val, $context)) { if (!$validator->isValid($val, $context)) {
$valid = false; $valid = false;
if (!$this->default_message) { if (!$this->default_message) {
throw new Exception('Define default message for array fields');
throw new InitializationException('Define default message for array fields');
} }
$this->message = $this->default_message; $this->message = $this->default_message;
} }

4
form/FormViewHelper.php

@ -18,7 +18,7 @@ class FormViewHelper extends ViewHelper
{ {
if ($this->data === null) { if ($this->data === null) {
if ($form == null) { if ($form == null) {
throw new Exception('Form name required for helper init');
throw new InitializationException('Form name required for helper init');
} }
$this->data = Session::get($form, array()); $this->data = Session::get($form, array());
Session::del($form); Session::del($form);
@ -34,7 +34,7 @@ class FormViewHelper extends ViewHelper
return $this->view->escape($default); return $this->view->escape($default);
} }
public function message($field)
public function message($fgrepield)
{ {
if (isset($this->data['messages'][$field])) { if (isset($this->data['messages'][$field])) {
return '<span class="error">' . $this->view->escape($this->data['messages'][$field]) . '</span>'; return '<span class="error">' . $this->view->escape($this->data['messages'][$field]) . '</span>';

7
tests/form/FormFieldTest.php

@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php';
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php'; require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
require_once dirname(__FILE__) . '/../../form/FormField.php'; require_once dirname(__FILE__) . '/../../form/FormField.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormFieldTest extends PHPUnit_Framework_TestCase class FormFieldTest extends PHPUnit_Framework_TestCase
{ {
@ -100,7 +101,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$validator = true; $validator = true;
$tmp_form_field = new FormField(); $tmp_form_field = new FormField();
// @TODO Fix exception type // @TODO Fix exception type
$this->setExpectedException('Exception', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception
$this->setExpectedException('InitializationException', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception
$tmp_form_field->addValidator($validator); $tmp_form_field->addValidator($validator);
} }
@ -144,7 +145,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$filter = new NotEmptyValidator(); $filter = new NotEmptyValidator();
$form_field = new FormField(); $form_field = new FormField();
// @TODO Fix exception type // @TODO Fix exception type
$this->setExpectedException('Exception', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception
$this->setExpectedException('InitializationException', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception
$form_field->addFilter($filter); $form_field->addFilter($filter);
} }
@ -217,7 +218,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
); );
$form_field = new FormField(); $form_field = new FormField();
$form_field->addValidator('NotEmpty'); $form_field->addValidator('NotEmpty');
$this->setExpectedException('Exception', 'Define default message for array fields');
$this->setExpectedException('InitializationException', 'Define default message for array fields');
$form_field->isValid($test_array); $form_field->isValid($test_array);
} }

3
tests/form/FormTest.php

@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../validator/Validator.php';
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php'; require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php'; require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php';
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormTest extends PHPUnit_Framework_TestCase class FormTest extends PHPUnit_Framework_TestCase
{ {
@ -51,7 +52,7 @@ class FormTest extends PHPUnit_Framework_TestCase
{ {
$form = new NotEmptyForm(); $form = new NotEmptyForm();
// @TODO Fix exception type // @TODO Fix exception type
$this->setExpectedException('Exception', 'Form::Form::isValid expects an array');
$this->setExpectedException('InitializationException', 'Form::Form::isValid expects an array');
$form->isValid(''); $form->isValid('');
} }

8
tests/form/FormViewHelperTest.php

@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../view/PHPView.php';
require_once dirname(__FILE__) . '/../../view/helpers/ViewHelper.php'; require_once dirname(__FILE__) . '/../../view/helpers/ViewHelper.php';
require_once dirname(__FILE__) . '/../../form/FormViewHelper.php'; require_once dirname(__FILE__) . '/../../form/FormViewHelper.php';
require_once dirname(__FILE__) . '/../../session/Session.php'; require_once dirname(__FILE__) . '/../../session/Session.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormViewHelperTest extends PHPUnit_Framework_TestCase class FormViewHelperTest extends PHPUnit_Framework_TestCase
{ {
@ -35,7 +36,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
public function testFormUnsetFormName() public function testFormUnsetFormName()
{ {
$helper = new FormViewHelper($this->view); $helper = new FormViewHelper($this->view);
$this->setExpectedException('Exception', 'Form name required for helper init');
$this->setExpectedException('InitializationException', 'Form name required for helper init');
// @TODO Refactor for form name is required param? // @TODO Refactor for form name is required param?
$helper->form(); $helper->form();
} }
@ -43,7 +44,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
public function testFormEmptyFormName() public function testFormEmptyFormName()
{ {
$helper = new FormViewHelper($this->view); $helper = new FormViewHelper($this->view);
$this->setExpectedException('Exception', 'Form name required for helper init');
$this->setExpectedException('InitializationException', 'Form name required for helper init');
$helper->form(''); $helper->form('');
} }
@ -80,14 +81,11 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
{ {
$helper = new FormViewHelper($this->view); $helper = new FormViewHelper($this->view);
$helper->form($this->formname); $helper->form($this->formname);
$value = $helper->message('field1'); $value = $helper->message('field1');
$this->assertSame('<span class="error">' . $this->view->escape('Can\'t serialize "value"') . '</span>', $value); $this->assertSame('<span class="error">' . $this->view->escape('Can\'t serialize "value"') . '</span>', $value);
} }
public function testMessageNotSet() public function testMessageNotSet()
{ {
$helper = new FormViewHelper($this->view); $helper = new FormViewHelper($this->view);
$helper->form($this->formname); $helper->form($this->formname);

Loading…
Cancel
Save