Changeset 144 for trunk/tests
- Timestamp:
- Jun 4, 2006 8:34:32 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/FormValidatorTest.php
r42 r144 33 33 function test_geterrorlist() 34 34 { 35 $this->FormValidator->geterrorlist(); 35 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 36 $err_list = $this->FormValidator->geterrorlist(); 37 $this->assertTrue($err_list[0]['message'] === _("This is an error.")); 36 38 } 37 39 38 40 function test_adderror() 39 41 { 40 $this->FormValidator->addError('name', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 42 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 43 $this->assertTrue($this->FormValidator->errors[0]['message'] === _("This is an error.")); 41 44 } 42 45 … … 45 48 $result = $this->FormValidator->anyerrors(); 46 49 $this->assertFalse($result); 50 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 51 $result = $this->FormValidator->anyerrors(); 52 $this->assertTrue($result); 47 53 } 48 54 49 55 function test_reseterrorlist() 50 56 { 51 $this->FormValidator->addError(' name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);57 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 52 58 $this->FormValidator->reseterrorlist(); 53 59 $this->assertFalse($this->FormValidator->anyerrors()); … … 56 62 function test_printerrormessages() 57 63 { 58 $this->FormValidator->addError(' name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);64 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 59 65 ob_start(); 60 66 $this->FormValidator->printerrormessages(); … … 65 71 function test_err() 66 72 { 67 $this->FormValidator->addError(' name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);73 $this->FormValidator->addError('some_field', _("This is an error."), MSG_ERR, __FILE__, __LINE__); 68 74 ob_start(); 69 $this->FormValidator->err(' name', 'printthis');75 $this->FormValidator->err('some_field', 'printthis'); 70 76 $result = ob_get_clean(); 71 77 $this->assertContains('printthis', $result); … … 74 80 function test_notempty() 75 81 { 76 $this->FormValidator->isEmpty('name', _("Error message")); 82 // This should not generate any error. 83 $_POST['some_field'] = 'a non empty string'; 84 $this->FormValidator->isempty('some_field', _("Error message")); 85 $this->assertFalse($this->FormValidator->anyerrors()); 86 87 // This one is an error! 88 $_POST['some_field'] = ''; 89 $this->FormValidator->isempty('some_field', _("Error message")); 90 $this->assertTrue($this->FormValidator->anyerrors()); 77 91 } 78 92 79 93 function test_isempty() 80 94 { 81 $result = $this->FormValidator->isempty('name', _("Error message")); 95 // This should not generate any error. 96 $_POST['some_field'] = 'a non empty string'; 97 $this->FormValidator->isempty('some_field', _("Error message")); 98 $this->assertFalse($this->FormValidator->anyerrors()); 99 100 // This one is an error! 101 $_POST['some_field'] = ''; 102 $this->FormValidator->isempty('some_field', _("Error message")); 103 $this->assertTrue($this->FormValidator->anyerrors()); 82 104 } 83 105 84 106 function test_isstring() 85 107 { 86 $result = $this->FormValidator->isstring('name', _("Error message")); 108 // This should not generate any error. 109 $_POST['some_field'] = 'this is a string'; 110 $this->FormValidator->isstring('some_field', _("Error message")); 111 $this->assertFalse($this->FormValidator->anyerrors()); 112 113 // This one is an error! 114 $_POST['some_field'] = 12.3248; // not a string. 115 $this->FormValidator->isstring('some_field', _("Error message")); 116 $this->assertTrue($this->FormValidator->anyerrors()); 87 117 } 88 118 89 119 function test_isnumber() 90 120 { 91 $result = $this->FormValidator->isnumber('name', _("Error message")); 121 // This should not generate any error. 122 $_POST['some_field'] = '1234.453'; 123 $this->FormValidator->isnumber('some_field', _("Error message")); 124 $this->assertFalse($this->FormValidator->anyerrors()); 125 126 // This one is an error! 127 $_POST['some_field'] = 'not a number'; 128 $this->FormValidator->isnumber('some_field', _("Error message")); 129 $this->assertTrue($this->FormValidator->anyerrors()); 92 130 } 93 131 94 132 function test_isinteger() 95 133 { 96 $result = $this->FormValidator->isinteger('name', _("Error message")); 134 // This should not generate any error. 135 $_POST['some_field'] = '1234'; 136 $this->FormValidator->isinteger('some_field', _("Error message")); 137 $this->assertFalse($this->FormValidator->anyerrors()); 138 139 // This one is an error! 140 $_POST['some_field'] = '1234.1'; 141 $this->FormValidator->isinteger('some_field', _("Error message")); 142 $this->assertTrue($this->FormValidator->anyerrors()); 97 143 } 98 144 99 145 function test_isfloat() 100 146 { 101 $result = $this->FormValidator->isfloat('name', _("Error message")); 147 // This should not generate any error. 148 $_POST['some_field'] = '123.1234'; 149 $this->FormValidator->isfloat('some_field', _("Error message")); 150 $this->assertFalse($this->FormValidator->anyerrors()); 151 152 // This one is an error! 153 $_POST['some_field'] = 'some falsity'; 154 $this->FormValidator->isfloat('some_field', _("Error message")); 155 $this->assertTrue($this->FormValidator->anyerrors()); 102 156 } 103 157 104 158 function test_isarray() 105 159 { 106 $result = $this->FormValidator->isarray('name', _("Error message")); 160 // This should not generate any error. 161 $_POST['some_field'] = array('asdf', 123); 162 $this->FormValidator->isarray('some_field', _("Error message")); 163 $this->assertFalse($this->FormValidator->anyerrors()); 164 165 // This one is an error! 166 $_POST['some_field'] = 'some falsity'; 167 $this->FormValidator->isarray('some_field', _("Error message")); 168 $this->assertTrue($this->FormValidator->anyerrors()); 107 169 } 108 170 109 171 function test_checkregex() 110 172 { 111 $result = $this->FormValidator->checkregex('name', '/\w/', true, _("Error message")); 173 // This should not generate any error. 174 $_POST['some_field'] = '1234abcd'; 175 $this->FormValidator->checkregex('some_field', '/\d{4}[a-d]{4}/', true, _("Error message")); 176 $this->assertFalse($this->FormValidator->anyerrors()); 177 178 // This should not generate any error. 179 $_POST['some_field'] = 'no digits here'; 180 $this->FormValidator->checkregex('some_field', '/\d/', false, _("Error message")); 181 $this->assertFalse($this->FormValidator->anyerrors()); 182 183 // This one is an error! 184 $_POST['some_field'] = 'oops, a d1git'; 185 $this->FormValidator->checkregex('some_field', '/\d/', false, _("Error message")); 186 $this->assertTrue($this->FormValidator->anyerrors()); 112 187 } 113 188 114 189 function test_stringlength() 115 190 { 116 $this->FormValidator->stringLength('name', 0, 255, _("Error message")); 191 // This should not generate any error. 192 $_POST['some_field'] = 'some truth'; 193 $this->FormValidator->stringLength('some_field', 0, 255, _("Error message")); 194 $this->assertFalse($this->FormValidator->anyerrors()); 195 196 // This one is an error! 197 $_POST['some_field'] = 'some falsity'; 198 $this->FormValidator->stringLength('some_field', 0, 4, _("Error message")); 199 $this->assertTrue($this->FormValidator->anyerrors()); 117 200 } 118 201 119 202 function test_numericrange() 120 203 { 121 $this->FormValidator->numericrange('name', 0, 255, _("Error message")); 204 // This should not generate any error. 205 $_POST['some_field'] = '12'; 206 $this->FormValidator->numericrange('some_field', 3, 22, _("Error message")); 207 $this->assertFalse($this->FormValidator->anyerrors()); 208 209 // This one is an error! 210 $_POST['some_field'] = '12'; 211 $this->FormValidator->numericrange('some_field', 300, 2200, _("Error message")); 212 $this->assertTrue($this->FormValidator->anyerrors()); 122 213 } 123 214 124 215 function test_validateemail() 125 216 { 126 $this->FormValidator->validateemail('name'); 217 // This should not generate any error. 218 $_POST['some_field'] = 'Quinn the Kook <quinn@strangecode.com>'; 219 $this->FormValidator->validateemail('some_field', _("Error message")); 220 $this->assertFalse($this->FormValidator->anyerrors()); 221 222 // This one is an error! 223 $_POST['some_field'] = 'quinn@kook.com.'; 224 $this->FormValidator->validateemail('some_field', _("Error message")); 225 $this->assertTrue($this->FormValidator->anyerrors()); 127 226 } 128 227 129 228 function test_validatephone() 130 229 { 131 $this->FormValidator->validatephone('name'); 230 // This should not generate any error. 231 $_POST['some_field'] = '+1 (530) 555-1212'; 232 $this->FormValidator->validatephone('some_field', _("Error message")); 233 $this->assertFalse($this->FormValidator->anyerrors()); 234 235 // This one is an error! 236 $_POST['some_field'] = 'd321/654*9875 '; 237 $this->FormValidator->validatephone('some_field', _("Error message")); 238 $this->assertTrue($this->FormValidator->anyerrors()); 132 239 } 133 240 134 241 function test_validatestrdate() 135 242 { 136 $this->FormValidator->validatestrdate('name'); 243 // This should not generate any error. 244 $_POST['some_field'] = 'next tuesday'; 245 $this->FormValidator->validatestrdate('some_field', _("Error message")); 246 $this->assertFalse($this->FormValidator->anyerrors()); 247 248 // This one is an error! 249 $_POST['some_field'] = 'in a galaxy far far away'; 250 $this->FormValidator->validatestrdate('some_field', _("Error message")); 251 $this->assertTrue($this->FormValidator->anyerrors()); 137 252 } 138 253 139 254 function test_validateccnumber() 140 255 { 141 $this->FormValidator->validateccnumber('name'); 142 } 143 144 function test_validatefile() 145 { 146 $this->FormValidator->validatefile('name'); 256 // This should not generate any error. 257 $_POST['some_field'] = '2323-2005-7766-3554'; 258 $this->FormValidator->validateccnumber('some_field', null); 259 $this->assertFalse($this->FormValidator->anyerrors()); 260 261 // This one is an error! 262 $_POST['some_field'] = '1234 1234 1234 1234'; 263 $this->FormValidator->validateccnumber('some_field', null); 264 $this->assertTrue($this->FormValidator->anyerrors()); 265 } 266 267 function test_fileuploaded() 268 { 269 // This one is an error! 270 $this->FormValidator->fileUploaded('some_field', _("Error message")); 271 $this->assertTrue($this->FormValidator->anyerrors()); 147 272 } 148 273
Note: See TracChangeset
for help on using the changeset viewer.