Changeset 5635
- Timestamp:
- 10/23/07 09:08:10 (1 year ago)
- Files:
-
- trunk/lib/validator/sfValidator.class.php (modified) (4 diffs)
- trunk/test/unit/validator/sfValidatorTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/validator/sfValidator.class.php
r5581 r5635 52 52 53 53 /** 54 * Returns an array of current error messages. 55 * 56 * @return array An array of messages 57 */ 58 public function getMessages() 59 { 60 return $this->messages; 54 * Returns an error message given an error code. 55 * 56 * @param string The error code 57 * 58 * @return string The error message, or the empty string if the error code does not exist 59 */ 60 public function getMessage($name) 61 { 62 return isset($this->messages[$name]) ? $this->messages[$name] : ''; 61 63 } 62 64 … … 73 75 74 76 /** 75 * Returns an error message given an error code. 76 * 77 * @param string The error code 78 * 79 * @return string The error message, or the empty string if the error code does not exist 80 */ 81 public function getMessage($name) 82 { 83 return isset($this->messages[$name]) ? $this->messages[$name] : ''; 77 * Returns an array of current error messages. 78 * 79 * @return array An array of messages 80 */ 81 public function getMessages() 82 { 83 return $this->messages; 84 } 85 86 /** 87 * Changes all error messages. 88 * 89 * @param array An array of error messages 90 */ 91 public function setMessages($values) 92 { 93 $this->messages = $values; 94 } 95 96 /** 97 * Gets an option value. 98 * 99 * @param string The option name 100 * 101 * @return mixed The option value 102 */ 103 public function getOption($name) 104 { 105 return isset($this->options[$name]) ? $this->options[$name] : null; 84 106 } 85 107 … … 96 118 97 119 /** 98 * Gets an option value.99 *100 * @param string The option name101 *102 * @return mixed The option value103 */104 public function getOption($name)105 {106 return isset($this->options[$name]) ? $this->options[$name] : null;107 }108 109 /**110 120 * Returns true if the option exists. 111 121 * … … 117 127 { 118 128 return isset($this->options[$name]); 129 } 130 131 /** 132 * Returns all options. 133 * 134 * @return array An array if options 135 */ 136 public function getOptions() 137 { 138 return $this->options; 139 } 140 141 /** 142 * Changes all options. 143 * 144 * @param array An array if options 145 */ 146 public function setOptions($values) 147 { 148 $this->options = $values; 119 149 } 120 150 trunk/test/unit/validator/sfValidatorTest.php
r5581 r5635 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 1, new lime_output_color());13 $t = new lime_test(23, new lime_output_color()); 14 14 15 15 class ValidatorIdentity extends sfValidator … … 80 80 $t->is($v->getOption('nonexistant'), null, '->getOption() returns null if the option does not exist'); 81 81 82 // ->getOptions() ->setOptions() 83 $t->diag('->getOptions() ->setOptions()'); 84 $v->setOptions(array('required' => true, 'trim' => false)); 85 $t->is($v->getOptions(), array('required' => true, 'trim' => false), '->setOptions() changes all options'); 86 82 87 // ->getMessages() 83 88 $t->diag('->getMessages()'); … … 102 107 } 103 108 109 // ->setMessages() 110 $t->diag('->setMessages()'); 111 $v->setMessages(array('required' => 'This is required.')); 112 $t->is($v->getMessages(), array('required' => 'This is required.'), '->setMessages() changes all error messages'); 113 104 114 // ->getErrorCodes() 105 115 $t->diag('->getErrorCodes()');