pictcode / lib / Cake / Test / Case / Utility / ValidationTest.php @ 635eef61
履歴 | 表示 | アノテート | ダウンロード (107.447 KB)
1 | 635eef61 | spyder1211 | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * ValidationTest file
|
||
4 | *
|
||
5 | * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||
6 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
7 | *
|
||
8 | * Licensed under The MIT License
|
||
9 | * For full copyright and license information, please see the LICENSE.txt
|
||
10 | * Redistributions of files must retain the above copyright notice.
|
||
11 | *
|
||
12 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
13 | * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||
14 | * @package Cake.Test.Case.Utility
|
||
15 | * @since CakePHP(tm) v 1.2.0.4206
|
||
16 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
17 | */
|
||
18 | |||
19 | App::uses('Validation', 'Utility'); |
||
20 | |||
21 | /**
|
||
22 | * CustomValidator class
|
||
23 | *
|
||
24 | * @package Cake.Test.Case.Utility
|
||
25 | */
|
||
26 | class CustomValidator { |
||
27 | |||
28 | /**
|
||
29 | * Makes sure that a given $email address is valid and unique
|
||
30 | *
|
||
31 | * @param string $check Email to check.
|
||
32 | * @return bool
|
||
33 | */
|
||
34 | public static function customValidate($check) { |
||
35 | return (bool)preg_match('/^[0-9]{3}$/', $check); |
||
36 | } |
||
37 | |||
38 | } |
||
39 | |||
40 | /**
|
||
41 | * TestNlValidation class
|
||
42 | *
|
||
43 | * Used to test pass through of Validation
|
||
44 | *
|
||
45 | * @package Cake.Test.Case.Utility
|
||
46 | */
|
||
47 | class TestNlValidation { |
||
48 | |||
49 | /**
|
||
50 | * postal function, for testing postal pass through.
|
||
51 | *
|
||
52 | * @param string $check
|
||
53 | * @return void
|
||
54 | */
|
||
55 | public static function postal($check) { |
||
56 | return true; |
||
57 | } |
||
58 | |||
59 | /**
|
||
60 | * ssn function for testing ssn pass through
|
||
61 | *
|
||
62 | * @return void
|
||
63 | */
|
||
64 | public static function ssn($check) { |
||
65 | return true; |
||
66 | } |
||
67 | |||
68 | } |
||
69 | |||
70 | /**
|
||
71 | * TestDeValidation class
|
||
72 | *
|
||
73 | * Used to test pass through of Validation
|
||
74 | *
|
||
75 | * @package Cake.Test.Case.Utility
|
||
76 | */
|
||
77 | class TestDeValidation { |
||
78 | |||
79 | /**
|
||
80 | * phone function, for testing phone pass through.
|
||
81 | *
|
||
82 | * @param string $check
|
||
83 | * @return void
|
||
84 | */
|
||
85 | public static function phone($check) { |
||
86 | return true; |
||
87 | } |
||
88 | |||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * Test Case for Validation Class
|
||
93 | *
|
||
94 | * @package Cake.Test.Case.Utility
|
||
95 | */
|
||
96 | class ValidationTest extends CakeTestCase { |
||
97 | |||
98 | /**
|
||
99 | * setUp method
|
||
100 | *
|
||
101 | * @return void
|
||
102 | */
|
||
103 | public function setUp() { |
||
104 | parent::setUp();
|
||
105 | $this->_appEncoding = Configure::read('App.encoding'); |
||
106 | $this->_appLocale = array(); |
||
107 | foreach (array(LC_MONETARY, LC_NUMERIC, LC_TIME) as $category) { |
||
108 | $this->_appLocale[$category] = setlocale($category, 0); |
||
109 | setlocale($category, 'en_US'); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * tearDown method
|
||
115 | *
|
||
116 | * @return void
|
||
117 | */
|
||
118 | public function tearDown() { |
||
119 | parent::tearDown();
|
||
120 | Configure::write('App.encoding', $this->_appEncoding); |
||
121 | foreach ($this->_appLocale as $category => $locale) { |
||
122 | setlocale($category, $locale); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * Test notBlank method
|
||
128 | *
|
||
129 | * @return void
|
||
130 | */
|
||
131 | public function testNotBlank() { |
||
132 | $this->assertTrue(Validation::notBlank('abcdefg')); |
||
133 | $this->assertTrue(Validation::notBlank('fasdf ')); |
||
134 | $this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla')); |
||
135 | $this->assertTrue(Validation::notBlank('abçďĕʑʘπй')); |
||
136 | $this->assertTrue(Validation::notBlank('José')); |
||
137 | $this->assertTrue(Validation::notBlank('é')); |
||
138 | $this->assertTrue(Validation::notBlank('π')); |
||
139 | $this->assertFalse(Validation::notBlank("\t ")); |
||
140 | $this->assertFalse(Validation::notBlank("")); |
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * Test notBlank method with ISO88591 encoding
|
||
145 | *
|
||
146 | * @return void
|
||
147 | */
|
||
148 | public function testNotBlankISO88591AppEncoding() { |
||
149 | Configure::write('App.encoding', 'ISO-8859-1'); |
||
150 | $this->assertTrue(Validation::notBlank('abcdefg')); |
||
151 | $this->assertTrue(Validation::notBlank('fasdf ')); |
||
152 | $this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla')); |
||
153 | $this->assertTrue(Validation::notBlank('abçďĕʑʘπй')); |
||
154 | $this->assertTrue(Validation::notBlank('José')); |
||
155 | $this->assertTrue(Validation::notBlank(utf8_decode('José'))); |
||
156 | $this->assertFalse(Validation::notBlank("\t ")); |
||
157 | $this->assertFalse(Validation::notBlank("")); |
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * testAlphaNumeric method
|
||
162 | *
|
||
163 | * @return void
|
||
164 | */
|
||
165 | public function testAlphaNumeric() { |
||
166 | $this->assertTrue(Validation::alphaNumeric('frferrf')); |
||
167 | $this->assertTrue(Validation::alphaNumeric('12234')); |
||
168 | $this->assertTrue(Validation::alphaNumeric('1w2e2r3t4y')); |
||
169 | $this->assertTrue(Validation::alphaNumeric('0')); |
||
170 | $this->assertTrue(Validation::alphaNumeric('abçďĕʑʘπй')); |
||
171 | $this->assertTrue(Validation::alphaNumeric('ˇˆๆゞ')); |
||
172 | $this->assertTrue(Validation::alphaNumeric('אกあアꀀ豈')); |
||
173 | $this->assertTrue(Validation::alphaNumeric('Džᾈᾨ')); |
||
174 | $this->assertTrue(Validation::alphaNumeric('ÆΔΩЖÇ')); |
||
175 | |||
176 | $this->assertFalse(Validation::alphaNumeric('12 234')); |
||
177 | $this->assertFalse(Validation::alphaNumeric('dfd 234')); |
||
178 | $this->assertFalse(Validation::alphaNumeric("0\n")); |
||
179 | $this->assertFalse(Validation::alphaNumeric("\n")); |
||
180 | $this->assertFalse(Validation::alphaNumeric("\t")); |
||
181 | $this->assertFalse(Validation::alphaNumeric("\r")); |
||
182 | $this->assertFalse(Validation::alphaNumeric(' ')); |
||
183 | $this->assertFalse(Validation::alphaNumeric('')); |
||
184 | } |
||
185 | |||
186 | /**
|
||
187 | * testLengthBetween method
|
||
188 | *
|
||
189 | * @return void
|
||
190 | */
|
||
191 | public function testLengthBetween() { |
||
192 | $this->assertTrue(Validation::lengthBetween('abcdefg', 1, 7)); |
||
193 | $this->assertTrue(Validation::lengthBetween('', 0, 7)); |
||
194 | $this->assertTrue(Validation::lengthBetween('אกあアꀀ豈', 1, 7)); |
||
195 | |||
196 | $this->assertFalse(Validation::lengthBetween('abcdefg', 1, 6)); |
||
197 | $this->assertFalse(Validation::lengthBetween('ÆΔΩЖÇ', 1, 3)); |
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * testBlank method
|
||
202 | *
|
||
203 | * @return void
|
||
204 | */
|
||
205 | public function testBlank() { |
||
206 | $this->assertTrue(Validation::blank('')); |
||
207 | $this->assertTrue(Validation::blank(' ')); |
||
208 | $this->assertTrue(Validation::blank("\n")); |
||
209 | $this->assertTrue(Validation::blank("\t")); |
||
210 | $this->assertTrue(Validation::blank("\r")); |
||
211 | $this->assertFalse(Validation::blank(' Blank')); |
||
212 | $this->assertFalse(Validation::blank('Blank')); |
||
213 | } |
||
214 | |||
215 | /**
|
||
216 | * testcc method
|
||
217 | *
|
||
218 | * @return void
|
||
219 | */
|
||
220 | public function testCc() { |
||
221 | //American Express
|
||
222 | $this->assertTrue(Validation::cc('370482756063980', array('amex'))); |
||
223 | $this->assertTrue(Validation::cc('349106433773483', array('amex'))); |
||
224 | $this->assertTrue(Validation::cc('344671486204764', array('amex'))); |
||
225 | $this->assertTrue(Validation::cc('344042544509943', array('amex'))); |
||
226 | $this->assertTrue(Validation::cc('377147515754475', array('amex'))); |
||
227 | $this->assertTrue(Validation::cc('375239372816422', array('amex'))); |
||
228 | $this->assertTrue(Validation::cc('376294341957707', array('amex'))); |
||
229 | $this->assertTrue(Validation::cc('341779292230411', array('amex'))); |
||
230 | $this->assertTrue(Validation::cc('341646919853372', array('amex'))); |
||
231 | $this->assertTrue(Validation::cc('348498616319346', array('amex'))); |
||
232 | //BankCard
|
||
233 | $this->assertTrue(Validation::cc('5610745867413420', array('bankcard'))); |
||
234 | $this->assertTrue(Validation::cc('5610376649499352', array('bankcard'))); |
||
235 | $this->assertTrue(Validation::cc('5610091936000694', array('bankcard'))); |
||
236 | $this->assertTrue(Validation::cc('5602248780118788', array('bankcard'))); |
||
237 | $this->assertTrue(Validation::cc('5610631567676765', array('bankcard'))); |
||
238 | $this->assertTrue(Validation::cc('5602238211270795', array('bankcard'))); |
||
239 | $this->assertTrue(Validation::cc('5610173951215470', array('bankcard'))); |
||
240 | $this->assertTrue(Validation::cc('5610139705753702', array('bankcard'))); |
||
241 | $this->assertTrue(Validation::cc('5602226032150551', array('bankcard'))); |
||
242 | $this->assertTrue(Validation::cc('5602223993735777', array('bankcard'))); |
||
243 | //Diners Club 14
|
||
244 | $this->assertTrue(Validation::cc('30155483651028', array('diners'))); |
||
245 | $this->assertTrue(Validation::cc('36371312803821', array('diners'))); |
||
246 | $this->assertTrue(Validation::cc('38801277489875', array('diners'))); |
||
247 | $this->assertTrue(Validation::cc('30348560464296', array('diners'))); |
||
248 | $this->assertTrue(Validation::cc('30349040317708', array('diners'))); |
||
249 | $this->assertTrue(Validation::cc('36567413559978', array('diners'))); |
||
250 | $this->assertTrue(Validation::cc('36051554732702', array('diners'))); |
||
251 | $this->assertTrue(Validation::cc('30391842198191', array('diners'))); |
||
252 | $this->assertTrue(Validation::cc('30172682197745', array('diners'))); |
||
253 | $this->assertTrue(Validation::cc('30162056566641', array('diners'))); |
||
254 | $this->assertTrue(Validation::cc('30085066927745', array('diners'))); |
||
255 | $this->assertTrue(Validation::cc('36519025221976', array('diners'))); |
||
256 | $this->assertTrue(Validation::cc('30372679371044', array('diners'))); |
||
257 | $this->assertTrue(Validation::cc('38913939150124', array('diners'))); |
||
258 | $this->assertTrue(Validation::cc('36852899094637', array('diners'))); |
||
259 | $this->assertTrue(Validation::cc('30138041971120', array('diners'))); |
||
260 | $this->assertTrue(Validation::cc('36184047836838', array('diners'))); |
||
261 | $this->assertTrue(Validation::cc('30057460264462', array('diners'))); |
||
262 | $this->assertTrue(Validation::cc('38980165212050', array('diners'))); |
||
263 | $this->assertTrue(Validation::cc('30356516881240', array('diners'))); |
||
264 | $this->assertTrue(Validation::cc('38744810033182', array('diners'))); |
||
265 | $this->assertTrue(Validation::cc('30173638706621', array('diners'))); |
||
266 | $this->assertTrue(Validation::cc('30158334709185', array('diners'))); |
||
267 | $this->assertTrue(Validation::cc('30195413721186', array('diners'))); |
||
268 | $this->assertTrue(Validation::cc('38863347694793', array('diners'))); |
||
269 | $this->assertTrue(Validation::cc('30275627009113', array('diners'))); |
||
270 | $this->assertTrue(Validation::cc('30242860404971', array('diners'))); |
||
271 | $this->assertTrue(Validation::cc('30081877595151', array('diners'))); |
||
272 | $this->assertTrue(Validation::cc('38053196067461', array('diners'))); |
||
273 | $this->assertTrue(Validation::cc('36520379984870', array('diners'))); |
||
274 | //2004 MasterCard/Diners Club Alliance International 14
|
||
275 | $this->assertTrue(Validation::cc('36747701998969', array('diners'))); |
||
276 | $this->assertTrue(Validation::cc('36427861123159', array('diners'))); |
||
277 | $this->assertTrue(Validation::cc('36150537602386', array('diners'))); |
||
278 | $this->assertTrue(Validation::cc('36582388820610', array('diners'))); |
||
279 | $this->assertTrue(Validation::cc('36729045250216', array('diners'))); |
||
280 | //2004 MasterCard/Diners Club Alliance US & Canada 16
|
||
281 | $this->assertTrue(Validation::cc('5597511346169950', array('diners'))); |
||
282 | $this->assertTrue(Validation::cc('5526443162217562', array('diners'))); |
||
283 | $this->assertTrue(Validation::cc('5577265786122391', array('diners'))); |
||
284 | $this->assertTrue(Validation::cc('5534061404676989', array('diners'))); |
||
285 | $this->assertTrue(Validation::cc('5545313588374502', array('diners'))); |
||
286 | //Discover
|
||
287 | $this->assertTrue(Validation::cc('6011802876467237', array('disc'))); |
||
288 | $this->assertTrue(Validation::cc('6506432777720955', array('disc'))); |
||
289 | $this->assertTrue(Validation::cc('6011126265283942', array('disc'))); |
||
290 | $this->assertTrue(Validation::cc('6502187151579252', array('disc'))); |
||
291 | $this->assertTrue(Validation::cc('6506600836002298', array('disc'))); |
||
292 | $this->assertTrue(Validation::cc('6504376463615189', array('disc'))); |
||
293 | $this->assertTrue(Validation::cc('6011440907005377', array('disc'))); |
||
294 | $this->assertTrue(Validation::cc('6509735979634270', array('disc'))); |
||
295 | $this->assertTrue(Validation::cc('6011422366775856', array('disc'))); |
||
296 | $this->assertTrue(Validation::cc('6500976374623323', array('disc'))); |
||
297 | //enRoute
|
||
298 | $this->assertTrue(Validation::cc('201496944158937', array('enroute'))); |
||
299 | $this->assertTrue(Validation::cc('214945833739665', array('enroute'))); |
||
300 | $this->assertTrue(Validation::cc('214982692491187', array('enroute'))); |
||
301 | $this->assertTrue(Validation::cc('214901395949424', array('enroute'))); |
||
302 | $this->assertTrue(Validation::cc('201480676269187', array('enroute'))); |
||
303 | $this->assertTrue(Validation::cc('214911922887807', array('enroute'))); |
||
304 | $this->assertTrue(Validation::cc('201485025457250', array('enroute'))); |
||
305 | $this->assertTrue(Validation::cc('201402662758866', array('enroute'))); |
||
306 | $this->assertTrue(Validation::cc('214981579370225', array('enroute'))); |
||
307 | $this->assertTrue(Validation::cc('201447595859877', array('enroute'))); |
||
308 | //JCB 15 digit
|
||
309 | $this->assertTrue(Validation::cc('210034762247893', array('jcb'))); |
||
310 | $this->assertTrue(Validation::cc('180078671678892', array('jcb'))); |
||
311 | $this->assertTrue(Validation::cc('180010559353736', array('jcb'))); |
||
312 | $this->assertTrue(Validation::cc('210095474464258', array('jcb'))); |
||
313 | $this->assertTrue(Validation::cc('210006675562188', array('jcb'))); |
||
314 | $this->assertTrue(Validation::cc('210063299662662', array('jcb'))); |
||
315 | $this->assertTrue(Validation::cc('180032506857825', array('jcb'))); |
||
316 | $this->assertTrue(Validation::cc('210057919192738', array('jcb'))); |
||
317 | $this->assertTrue(Validation::cc('180031358949367', array('jcb'))); |
||
318 | $this->assertTrue(Validation::cc('180033802147846', array('jcb'))); |
||
319 | //JCB 16 digit
|
||
320 | $this->assertTrue(Validation::cc('3096806857839939', array('jcb'))); |
||
321 | $this->assertTrue(Validation::cc('3158699503187091', array('jcb'))); |
||
322 | $this->assertTrue(Validation::cc('3112549607186579', array('jcb'))); |
||
323 | $this->assertTrue(Validation::cc('3112332922425604', array('jcb'))); |
||
324 | $this->assertTrue(Validation::cc('3112001541159239', array('jcb'))); |
||
325 | $this->assertTrue(Validation::cc('3112162495317841', array('jcb'))); |
||
326 | $this->assertTrue(Validation::cc('3337562627732768', array('jcb'))); |
||
327 | $this->assertTrue(Validation::cc('3337107161330775', array('jcb'))); |
||
328 | $this->assertTrue(Validation::cc('3528053736003621', array('jcb'))); |
||
329 | $this->assertTrue(Validation::cc('3528915255020360', array('jcb'))); |
||
330 | $this->assertTrue(Validation::cc('3096786059660921', array('jcb'))); |
||
331 | $this->assertTrue(Validation::cc('3528264799292320', array('jcb'))); |
||
332 | $this->assertTrue(Validation::cc('3096469164130136', array('jcb'))); |
||
333 | $this->assertTrue(Validation::cc('3112127443822853', array('jcb'))); |
||
334 | $this->assertTrue(Validation::cc('3096849995802328', array('jcb'))); |
||
335 | $this->assertTrue(Validation::cc('3528090735127407', array('jcb'))); |
||
336 | $this->assertTrue(Validation::cc('3112101006819234', array('jcb'))); |
||
337 | $this->assertTrue(Validation::cc('3337444428040784', array('jcb'))); |
||
338 | $this->assertTrue(Validation::cc('3088043154151061', array('jcb'))); |
||
339 | $this->assertTrue(Validation::cc('3088295969414866', array('jcb'))); |
||
340 | $this->assertTrue(Validation::cc('3158748843158575', array('jcb'))); |
||
341 | $this->assertTrue(Validation::cc('3158709206148538', array('jcb'))); |
||
342 | $this->assertTrue(Validation::cc('3158365159575324', array('jcb'))); |
||
343 | $this->assertTrue(Validation::cc('3158671691305165', array('jcb'))); |
||
344 | $this->assertTrue(Validation::cc('3528523028771093', array('jcb'))); |
||
345 | $this->assertTrue(Validation::cc('3096057126267870', array('jcb'))); |
||
346 | $this->assertTrue(Validation::cc('3158514047166834', array('jcb'))); |
||
347 | $this->assertTrue(Validation::cc('3528274546125962', array('jcb'))); |
||
348 | $this->assertTrue(Validation::cc('3528890967705733', array('jcb'))); |
||
349 | $this->assertTrue(Validation::cc('3337198811307545', array('jcb'))); |
||
350 | //Maestro (debit card)
|
||
351 | $this->assertTrue(Validation::cc('5020147409985219', array('maestro'))); |
||
352 | $this->assertTrue(Validation::cc('5020931809905616', array('maestro'))); |
||
353 | $this->assertTrue(Validation::cc('5020412965470224', array('maestro'))); |
||
354 | $this->assertTrue(Validation::cc('5020129740944022', array('maestro'))); |
||
355 | $this->assertTrue(Validation::cc('5020024696747943', array('maestro'))); |
||
356 | $this->assertTrue(Validation::cc('5020581514636509', array('maestro'))); |
||
357 | $this->assertTrue(Validation::cc('5020695008411987', array('maestro'))); |
||
358 | $this->assertTrue(Validation::cc('5020565359718977', array('maestro'))); |
||
359 | $this->assertTrue(Validation::cc('6339931536544062', array('maestro'))); |
||
360 | $this->assertTrue(Validation::cc('6465028615704406', array('maestro'))); |
||
361 | //Mastercard
|
||
362 | $this->assertTrue(Validation::cc('5580424361774366', array('mc'))); |
||
363 | $this->assertTrue(Validation::cc('5589563059318282', array('mc'))); |
||
364 | $this->assertTrue(Validation::cc('5387558333690047', array('mc'))); |
||
365 | $this->assertTrue(Validation::cc('5163919215247175', array('mc'))); |
||
366 | $this->assertTrue(Validation::cc('5386742685055055', array('mc'))); |
||
367 | $this->assertTrue(Validation::cc('5102303335960674', array('mc'))); |
||
368 | $this->assertTrue(Validation::cc('5526543403964565', array('mc'))); |
||
369 | $this->assertTrue(Validation::cc('5538725892618432', array('mc'))); |
||
370 | $this->assertTrue(Validation::cc('5119543573129778', array('mc'))); |
||
371 | $this->assertTrue(Validation::cc('5391174753915767', array('mc'))); |
||
372 | $this->assertTrue(Validation::cc('5510994113980714', array('mc'))); |
||
373 | $this->assertTrue(Validation::cc('5183720260418091', array('mc'))); |
||
374 | $this->assertTrue(Validation::cc('5488082196086704', array('mc'))); |
||
375 | $this->assertTrue(Validation::cc('5484645164161834', array('mc'))); |
||
376 | $this->assertTrue(Validation::cc('5171254350337031', array('mc'))); |
||
377 | $this->assertTrue(Validation::cc('5526987528136452', array('mc'))); |
||
378 | $this->assertTrue(Validation::cc('5504148941409358', array('mc'))); |
||
379 | $this->assertTrue(Validation::cc('5240793507243615', array('mc'))); |
||
380 | $this->assertTrue(Validation::cc('5162114693017107', array('mc'))); |
||
381 | $this->assertTrue(Validation::cc('5163104807404753', array('mc'))); |
||
382 | $this->assertTrue(Validation::cc('5590136167248365', array('mc'))); |
||
383 | $this->assertTrue(Validation::cc('5565816281038948', array('mc'))); |
||
384 | $this->assertTrue(Validation::cc('5467639122779531', array('mc'))); |
||
385 | $this->assertTrue(Validation::cc('5297350261550024', array('mc'))); |
||
386 | $this->assertTrue(Validation::cc('5162739131368058', array('mc'))); |
||
387 | //Solo 16
|
||
388 | $this->assertTrue(Validation::cc('6767432107064987', array('solo'))); |
||
389 | $this->assertTrue(Validation::cc('6334667758225411', array('solo'))); |
||
390 | $this->assertTrue(Validation::cc('6767037421954068', array('solo'))); |
||
391 | $this->assertTrue(Validation::cc('6767823306394854', array('solo'))); |
||
392 | $this->assertTrue(Validation::cc('6334768185398134', array('solo'))); |
||
393 | $this->assertTrue(Validation::cc('6767286729498589', array('solo'))); |
||
394 | $this->assertTrue(Validation::cc('6334972104431261', array('solo'))); |
||
395 | $this->assertTrue(Validation::cc('6334843427400616', array('solo'))); |
||
396 | $this->assertTrue(Validation::cc('6767493947881311', array('solo'))); |
||
397 | $this->assertTrue(Validation::cc('6767194235798817', array('solo'))); |
||
398 | //Solo 18
|
||
399 | $this->assertTrue(Validation::cc('676714834398858593', array('solo'))); |
||
400 | $this->assertTrue(Validation::cc('676751666435130857', array('solo'))); |
||
401 | $this->assertTrue(Validation::cc('676781908573924236', array('solo'))); |
||
402 | $this->assertTrue(Validation::cc('633488724644003240', array('solo'))); |
||
403 | $this->assertTrue(Validation::cc('676732252338067316', array('solo'))); |
||
404 | $this->assertTrue(Validation::cc('676747520084495821', array('solo'))); |
||
405 | $this->assertTrue(Validation::cc('633465488901381957', array('solo'))); |
||
406 | $this->assertTrue(Validation::cc('633487484858610484', array('solo'))); |
||
407 | $this->assertTrue(Validation::cc('633453764680740694', array('solo'))); |
||
408 | $this->assertTrue(Validation::cc('676768613295414451', array('solo'))); |
||
409 | //Solo 19
|
||
410 | $this->assertTrue(Validation::cc('6767838565218340113', array('solo'))); |
||
411 | $this->assertTrue(Validation::cc('6767760119829705181', array('solo'))); |
||
412 | $this->assertTrue(Validation::cc('6767265917091593668', array('solo'))); |
||
413 | $this->assertTrue(Validation::cc('6767938856947440111', array('solo'))); |
||
414 | $this->assertTrue(Validation::cc('6767501945697390076', array('solo'))); |
||
415 | $this->assertTrue(Validation::cc('6334902868716257379', array('solo'))); |
||
416 | $this->assertTrue(Validation::cc('6334922127686425532', array('solo'))); |
||
417 | $this->assertTrue(Validation::cc('6334933119080706440', array('solo'))); |
||
418 | $this->assertTrue(Validation::cc('6334647959628261714', array('solo'))); |
||
419 | $this->assertTrue(Validation::cc('6334527312384101382', array('solo'))); |
||
420 | //Switch 16
|
||
421 | $this->assertTrue(Validation::cc('5641829171515733', array('switch'))); |
||
422 | $this->assertTrue(Validation::cc('5641824852820809', array('switch'))); |
||
423 | $this->assertTrue(Validation::cc('6759129648956909', array('switch'))); |
||
424 | $this->assertTrue(Validation::cc('6759626072268156', array('switch'))); |
||
425 | $this->assertTrue(Validation::cc('5641822698388957', array('switch'))); |
||
426 | $this->assertTrue(Validation::cc('5641827123105470', array('switch'))); |
||
427 | $this->assertTrue(Validation::cc('5641823755819553', array('switch'))); |
||
428 | $this->assertTrue(Validation::cc('5641821939587682', array('switch'))); |
||
429 | $this->assertTrue(Validation::cc('4936097148079186', array('switch'))); |
||
430 | $this->assertTrue(Validation::cc('5641829739125009', array('switch'))); |
||
431 | $this->assertTrue(Validation::cc('5641822860725507', array('switch'))); |
||
432 | $this->assertTrue(Validation::cc('4936717688865831', array('switch'))); |
||
433 | $this->assertTrue(Validation::cc('6759487613615441', array('switch'))); |
||
434 | $this->assertTrue(Validation::cc('5641821346840617', array('switch'))); |
||
435 | $this->assertTrue(Validation::cc('5641825793417126', array('switch'))); |
||
436 | $this->assertTrue(Validation::cc('5641821302759595', array('switch'))); |
||
437 | $this->assertTrue(Validation::cc('6759784969918837', array('switch'))); |
||
438 | $this->assertTrue(Validation::cc('5641824910667036', array('switch'))); |
||
439 | $this->assertTrue(Validation::cc('6759139909636173', array('switch'))); |
||
440 | $this->assertTrue(Validation::cc('6333425070638022', array('switch'))); |
||
441 | $this->assertTrue(Validation::cc('5641823910382067', array('switch'))); |
||
442 | $this->assertTrue(Validation::cc('4936295218139423', array('switch'))); |
||
443 | $this->assertTrue(Validation::cc('6333031811316199', array('switch'))); |
||
444 | $this->assertTrue(Validation::cc('4936912044763198', array('switch'))); |
||
445 | $this->assertTrue(Validation::cc('4936387053303824', array('switch'))); |
||
446 | $this->assertTrue(Validation::cc('6759535838760523', array('switch'))); |
||
447 | $this->assertTrue(Validation::cc('6333427174594051', array('switch'))); |
||
448 | $this->assertTrue(Validation::cc('5641829037102700', array('switch'))); |
||
449 | $this->assertTrue(Validation::cc('5641826495463046', array('switch'))); |
||
450 | $this->assertTrue(Validation::cc('6333480852979946', array('switch'))); |
||
451 | $this->assertTrue(Validation::cc('5641827761302876', array('switch'))); |
||
452 | $this->assertTrue(Validation::cc('5641825083505317', array('switch'))); |
||
453 | $this->assertTrue(Validation::cc('6759298096003991', array('switch'))); |
||
454 | $this->assertTrue(Validation::cc('4936119165483420', array('switch'))); |
||
455 | $this->assertTrue(Validation::cc('4936190990500993', array('switch'))); |
||
456 | $this->assertTrue(Validation::cc('4903356467384927', array('switch'))); |
||
457 | $this->assertTrue(Validation::cc('6333372765092554', array('switch'))); |
||
458 | $this->assertTrue(Validation::cc('5641821330950570', array('switch'))); |
||
459 | $this->assertTrue(Validation::cc('6759841558826118', array('switch'))); |
||
460 | $this->assertTrue(Validation::cc('4936164540922452', array('switch'))); |
||
461 | //Switch 18
|
||
462 | $this->assertTrue(Validation::cc('493622764224625174', array('switch'))); |
||
463 | $this->assertTrue(Validation::cc('564182823396913535', array('switch'))); |
||
464 | $this->assertTrue(Validation::cc('675917308304801234', array('switch'))); |
||
465 | $this->assertTrue(Validation::cc('675919890024220298', array('switch'))); |
||
466 | $this->assertTrue(Validation::cc('633308376862556751', array('switch'))); |
||
467 | $this->assertTrue(Validation::cc('564182377633208779', array('switch'))); |
||
468 | $this->assertTrue(Validation::cc('564182870014926787', array('switch'))); |
||
469 | $this->assertTrue(Validation::cc('675979788553829819', array('switch'))); |
||
470 | $this->assertTrue(Validation::cc('493668394358130935', array('switch'))); |
||
471 | $this->assertTrue(Validation::cc('493637431790930965', array('switch'))); |
||
472 | $this->assertTrue(Validation::cc('633321438601941513', array('switch'))); |
||
473 | $this->assertTrue(Validation::cc('675913800898840986', array('switch'))); |
||
474 | $this->assertTrue(Validation::cc('564182592016841547', array('switch'))); |
||
475 | $this->assertTrue(Validation::cc('564182428380440899', array('switch'))); |
||
476 | $this->assertTrue(Validation::cc('493696376827623463', array('switch'))); |
||
477 | $this->assertTrue(Validation::cc('675977939286485757', array('switch'))); |
||
478 | $this->assertTrue(Validation::cc('490302699502091579', array('switch'))); |
||
479 | $this->assertTrue(Validation::cc('564182085013662230', array('switch'))); |
||
480 | $this->assertTrue(Validation::cc('493693054263310167', array('switch'))); |
||
481 | $this->assertTrue(Validation::cc('633321755966697525', array('switch'))); |
||
482 | $this->assertTrue(Validation::cc('675996851719732811', array('switch'))); |
||
483 | $this->assertTrue(Validation::cc('493699211208281028', array('switch'))); |
||
484 | $this->assertTrue(Validation::cc('493697817378356614', array('switch'))); |
||
485 | $this->assertTrue(Validation::cc('675968224161768150', array('switch'))); |
||
486 | $this->assertTrue(Validation::cc('493669416873337627', array('switch'))); |
||
487 | $this->assertTrue(Validation::cc('564182439172549714', array('switch'))); |
||
488 | $this->assertTrue(Validation::cc('675926914467673598', array('switch'))); |
||
489 | $this->assertTrue(Validation::cc('564182565231977809', array('switch'))); |
||
490 | $this->assertTrue(Validation::cc('675966282607849002', array('switch'))); |
||
491 | $this->assertTrue(Validation::cc('493691609704348548', array('switch'))); |
||
492 | $this->assertTrue(Validation::cc('675933118546065120', array('switch'))); |
||
493 | $this->assertTrue(Validation::cc('493631116677238592', array('switch'))); |
||
494 | $this->assertTrue(Validation::cc('675921142812825938', array('switch'))); |
||
495 | $this->assertTrue(Validation::cc('633338311815675113', array('switch'))); |
||
496 | $this->assertTrue(Validation::cc('633323539867338621', array('switch'))); |
||
497 | $this->assertTrue(Validation::cc('675964912740845663', array('switch'))); |
||
498 | $this->assertTrue(Validation::cc('633334008833727504', array('switch'))); |
||
499 | $this->assertTrue(Validation::cc('493631941273687169', array('switch'))); |
||
500 | $this->assertTrue(Validation::cc('564182971729706785', array('switch'))); |
||
501 | $this->assertTrue(Validation::cc('633303461188963496', array('switch'))); |
||
502 | //Switch 19
|
||
503 | $this->assertTrue(Validation::cc('6759603460617628716', array('switch'))); |
||
504 | $this->assertTrue(Validation::cc('4936705825268647681', array('switch'))); |
||
505 | $this->assertTrue(Validation::cc('5641829846600479183', array('switch'))); |
||
506 | $this->assertTrue(Validation::cc('6759389846573792530', array('switch'))); |
||
507 | $this->assertTrue(Validation::cc('4936189558712637603', array('switch'))); |
||
508 | $this->assertTrue(Validation::cc('5641822217393868189', array('switch'))); |
||
509 | $this->assertTrue(Validation::cc('4903075563780057152', array('switch'))); |
||
510 | $this->assertTrue(Validation::cc('4936510653566569547', array('switch'))); |
||
511 | $this->assertTrue(Validation::cc('4936503083627303364', array('switch'))); |
||
512 | $this->assertTrue(Validation::cc('4936777334398116272', array('switch'))); |
||
513 | $this->assertTrue(Validation::cc('5641823876900554860', array('switch'))); |
||
514 | $this->assertTrue(Validation::cc('6759619236903407276', array('switch'))); |
||
515 | $this->assertTrue(Validation::cc('6759011470269978117', array('switch'))); |
||
516 | $this->assertTrue(Validation::cc('6333175833997062502', array('switch'))); |
||
517 | $this->assertTrue(Validation::cc('6759498728789080439', array('switch'))); |
||
518 | $this->assertTrue(Validation::cc('4903020404168157841', array('switch'))); |
||
519 | $this->assertTrue(Validation::cc('6759354334874804313', array('switch'))); |
||
520 | $this->assertTrue(Validation::cc('6759900856420875115', array('switch'))); |
||
521 | $this->assertTrue(Validation::cc('5641827269346868860', array('switch'))); |
||
522 | $this->assertTrue(Validation::cc('5641828995047453870', array('switch'))); |
||
523 | $this->assertTrue(Validation::cc('6333321884754806543', array('switch'))); |
||
524 | $this->assertTrue(Validation::cc('6333108246283715901', array('switch'))); |
||
525 | $this->assertTrue(Validation::cc('6759572372800700102', array('switch'))); |
||
526 | $this->assertTrue(Validation::cc('4903095096797974933', array('switch'))); |
||
527 | $this->assertTrue(Validation::cc('6333354315797920215', array('switch'))); |
||
528 | $this->assertTrue(Validation::cc('6759163746089433755', array('switch'))); |
||
529 | $this->assertTrue(Validation::cc('6759871666634807647', array('switch'))); |
||
530 | $this->assertTrue(Validation::cc('5641827883728575248', array('switch'))); |
||
531 | $this->assertTrue(Validation::cc('4936527975051407847', array('switch'))); |
||
532 | $this->assertTrue(Validation::cc('5641823318396882141', array('switch'))); |
||
533 | $this->assertTrue(Validation::cc('6759123772311123708', array('switch'))); |
||
534 | $this->assertTrue(Validation::cc('4903054736148271088', array('switch'))); |
||
535 | $this->assertTrue(Validation::cc('4936477526808883952', array('switch'))); |
||
536 | $this->assertTrue(Validation::cc('4936433964890967966', array('switch'))); |
||
537 | $this->assertTrue(Validation::cc('6333245128906049344', array('switch'))); |
||
538 | $this->assertTrue(Validation::cc('4936321036970553134', array('switch'))); |
||
539 | $this->assertTrue(Validation::cc('4936111816358702773', array('switch'))); |
||
540 | $this->assertTrue(Validation::cc('4936196077254804290', array('switch'))); |
||
541 | $this->assertTrue(Validation::cc('6759558831206830183', array('switch'))); |
||
542 | $this->assertTrue(Validation::cc('5641827998830403137', array('switch'))); |
||
543 | //VISA 13 digit
|
||
544 | $this->assertTrue(Validation::cc('4024007174754', array('visa'))); |
||
545 | $this->assertTrue(Validation::cc('4104816460717', array('visa'))); |
||
546 | $this->assertTrue(Validation::cc('4716229700437', array('visa'))); |
||
547 | $this->assertTrue(Validation::cc('4539305400213', array('visa'))); |
||
548 | $this->assertTrue(Validation::cc('4728260558665', array('visa'))); |
||
549 | $this->assertTrue(Validation::cc('4929100131792', array('visa'))); |
||
550 | $this->assertTrue(Validation::cc('4024007117308', array('visa'))); |
||
551 | $this->assertTrue(Validation::cc('4539915491024', array('visa'))); |
||
552 | $this->assertTrue(Validation::cc('4539790901139', array('visa'))); |
||
553 | $this->assertTrue(Validation::cc('4485284914909', array('visa'))); |
||
554 | $this->assertTrue(Validation::cc('4782793022350', array('visa'))); |
||
555 | $this->assertTrue(Validation::cc('4556899290685', array('visa'))); |
||
556 | $this->assertTrue(Validation::cc('4024007134774', array('visa'))); |
||
557 | $this->assertTrue(Validation::cc('4333412341316', array('visa'))); |
||
558 | $this->assertTrue(Validation::cc('4539534204543', array('visa'))); |
||
559 | $this->assertTrue(Validation::cc('4485640373626', array('visa'))); |
||
560 | $this->assertTrue(Validation::cc('4929911445746', array('visa'))); |
||
561 | $this->assertTrue(Validation::cc('4539292550806', array('visa'))); |
||
562 | $this->assertTrue(Validation::cc('4716523014030', array('visa'))); |
||
563 | $this->assertTrue(Validation::cc('4024007125152', array('visa'))); |
||
564 | $this->assertTrue(Validation::cc('4539758883311', array('visa'))); |
||
565 | $this->assertTrue(Validation::cc('4024007103258', array('visa'))); |
||
566 | $this->assertTrue(Validation::cc('4916933155767', array('visa'))); |
||
567 | $this->assertTrue(Validation::cc('4024007159672', array('visa'))); |
||
568 | $this->assertTrue(Validation::cc('4716935544871', array('visa'))); |
||
569 | $this->assertTrue(Validation::cc('4929415177779', array('visa'))); |
||
570 | $this->assertTrue(Validation::cc('4929748547896', array('visa'))); |
||
571 | $this->assertTrue(Validation::cc('4929153468612', array('visa'))); |
||
572 | $this->assertTrue(Validation::cc('4539397132104', array('visa'))); |
||
573 | $this->assertTrue(Validation::cc('4485293435540', array('visa'))); |
||
574 | $this->assertTrue(Validation::cc('4485799412720', array('visa'))); |
||
575 | $this->assertTrue(Validation::cc('4916744757686', array('visa'))); |
||
576 | $this->assertTrue(Validation::cc('4556475655426', array('visa'))); |
||
577 | $this->assertTrue(Validation::cc('4539400441625', array('visa'))); |
||
578 | $this->assertTrue(Validation::cc('4485437129173', array('visa'))); |
||
579 | $this->assertTrue(Validation::cc('4716253605320', array('visa'))); |
||
580 | $this->assertTrue(Validation::cc('4539366156589', array('visa'))); |
||
581 | $this->assertTrue(Validation::cc('4916498061392', array('visa'))); |
||
582 | $this->assertTrue(Validation::cc('4716127163779', array('visa'))); |
||
583 | $this->assertTrue(Validation::cc('4024007183078', array('visa'))); |
||
584 | $this->assertTrue(Validation::cc('4041553279654', array('visa'))); |
||
585 | $this->assertTrue(Validation::cc('4532380121960', array('visa'))); |
||
586 | $this->assertTrue(Validation::cc('4485906062491', array('visa'))); |
||
587 | $this->assertTrue(Validation::cc('4539365115149', array('visa'))); |
||
588 | $this->assertTrue(Validation::cc('4485146516702', array('visa'))); |
||
589 | //VISA 16 digit
|
||
590 | $this->assertTrue(Validation::cc('4916375389940009', array('visa'))); |
||
591 | $this->assertTrue(Validation::cc('4929167481032610', array('visa'))); |
||
592 | $this->assertTrue(Validation::cc('4485029969061519', array('visa'))); |
||
593 | $this->assertTrue(Validation::cc('4485573845281759', array('visa'))); |
||
594 | $this->assertTrue(Validation::cc('4485669810383529', array('visa'))); |
||
595 | $this->assertTrue(Validation::cc('4929615806560327', array('visa'))); |
||
596 | $this->assertTrue(Validation::cc('4556807505609535', array('visa'))); |
||
597 | $this->assertTrue(Validation::cc('4532611336232890', array('visa'))); |
||
598 | $this->assertTrue(Validation::cc('4532201952422387', array('visa'))); |
||
599 | $this->assertTrue(Validation::cc('4485073797976290', array('visa'))); |
||
600 | $this->assertTrue(Validation::cc('4024007157580969', array('visa'))); |
||
601 | $this->assertTrue(Validation::cc('4053740470212274', array('visa'))); |
||
602 | $this->assertTrue(Validation::cc('4716265831525676', array('visa'))); |
||
603 | $this->assertTrue(Validation::cc('4024007100222966', array('visa'))); |
||
604 | $this->assertTrue(Validation::cc('4539556148303244', array('visa'))); |
||
605 | $this->assertTrue(Validation::cc('4532449879689709', array('visa'))); |
||
606 | $this->assertTrue(Validation::cc('4916805467840986', array('visa'))); |
||
607 | $this->assertTrue(Validation::cc('4532155644440233', array('visa'))); |
||
608 | $this->assertTrue(Validation::cc('4467977802223781', array('visa'))); |
||
609 | $this->assertTrue(Validation::cc('4539224637000686', array('visa'))); |
||
610 | $this->assertTrue(Validation::cc('4556629187064965', array('visa'))); |
||
611 | $this->assertTrue(Validation::cc('4532970205932943', array('visa'))); |
||
612 | $this->assertTrue(Validation::cc('4821470132041850', array('visa'))); |
||
613 | $this->assertTrue(Validation::cc('4916214267894485', array('visa'))); |
||
614 | $this->assertTrue(Validation::cc('4024007169073284', array('visa'))); |
||
615 | $this->assertTrue(Validation::cc('4716783351296122', array('visa'))); |
||
616 | $this->assertTrue(Validation::cc('4556480171913795', array('visa'))); |
||
617 | $this->assertTrue(Validation::cc('4929678411034997', array('visa'))); |
||
618 | $this->assertTrue(Validation::cc('4682061913519392', array('visa'))); |
||
619 | $this->assertTrue(Validation::cc('4916495481746474', array('visa'))); |
||
620 | $this->assertTrue(Validation::cc('4929007108460499', array('visa'))); |
||
621 | $this->assertTrue(Validation::cc('4539951357838586', array('visa'))); |
||
622 | $this->assertTrue(Validation::cc('4716482691051558', array('visa'))); |
||
623 | $this->assertTrue(Validation::cc('4916385069917516', array('visa'))); |
||
624 | $this->assertTrue(Validation::cc('4929020289494641', array('visa'))); |
||
625 | $this->assertTrue(Validation::cc('4532176245263774', array('visa'))); |
||
626 | $this->assertTrue(Validation::cc('4556242273553949', array('visa'))); |
||
627 | $this->assertTrue(Validation::cc('4481007485188614', array('visa'))); |
||
628 | $this->assertTrue(Validation::cc('4716533372139623', array('visa'))); |
||
629 | $this->assertTrue(Validation::cc('4929152038152632', array('visa'))); |
||
630 | $this->assertTrue(Validation::cc('4539404037310550', array('visa'))); |
||
631 | $this->assertTrue(Validation::cc('4532800925229140', array('visa'))); |
||
632 | $this->assertTrue(Validation::cc('4916845885268360', array('visa'))); |
||
633 | $this->assertTrue(Validation::cc('4394514669078434', array('visa'))); |
||
634 | $this->assertTrue(Validation::cc('4485611378115042', array('visa'))); |
||
635 | //Visa Electron
|
||
636 | $this->assertTrue(Validation::cc('4175003346287100', array('electron'))); |
||
637 | $this->assertTrue(Validation::cc('4913042516577228', array('electron'))); |
||
638 | $this->assertTrue(Validation::cc('4917592325659381', array('electron'))); |
||
639 | $this->assertTrue(Validation::cc('4917084924450511', array('electron'))); |
||
640 | $this->assertTrue(Validation::cc('4917994610643999', array('electron'))); |
||
641 | $this->assertTrue(Validation::cc('4175005933743585', array('electron'))); |
||
642 | $this->assertTrue(Validation::cc('4175008373425044', array('electron'))); |
||
643 | $this->assertTrue(Validation::cc('4913119763664154', array('electron'))); |
||
644 | $this->assertTrue(Validation::cc('4913189017481812', array('electron'))); |
||
645 | $this->assertTrue(Validation::cc('4913085104968622', array('electron'))); |
||
646 | $this->assertTrue(Validation::cc('4175008803122021', array('electron'))); |
||
647 | $this->assertTrue(Validation::cc('4913294453962489', array('electron'))); |
||
648 | $this->assertTrue(Validation::cc('4175009797419290', array('electron'))); |
||
649 | $this->assertTrue(Validation::cc('4175005028142917', array('electron'))); |
||
650 | $this->assertTrue(Validation::cc('4913940802385364', array('electron'))); |
||
651 | //Voyager
|
||
652 | $this->assertTrue(Validation::cc('869940697287073', array('voyager'))); |
||
653 | $this->assertTrue(Validation::cc('869934523596112', array('voyager'))); |
||
654 | $this->assertTrue(Validation::cc('869958670174621', array('voyager'))); |
||
655 | $this->assertTrue(Validation::cc('869921250068209', array('voyager'))); |
||
656 | $this->assertTrue(Validation::cc('869972521242198', array('voyager'))); |
||
657 | } |
||
658 | |||
659 | /**
|
||
660 | * testLuhn method
|
||
661 | *
|
||
662 | * @return void
|
||
663 | */
|
||
664 | public function testLuhn() { |
||
665 | //American Express
|
||
666 | $this->assertTrue(Validation::luhn('370482756063980', true)); |
||
667 | //BankCard
|
||
668 | $this->assertTrue(Validation::luhn('5610745867413420', true)); |
||
669 | //Diners Club 14
|
||
670 | $this->assertTrue(Validation::luhn('30155483651028', true)); |
||
671 | //2004 MasterCard/Diners Club Alliance International 14
|
||
672 | $this->assertTrue(Validation::luhn('36747701998969', true)); |
||
673 | //2004 MasterCard/Diners Club Alliance US & Canada 16
|
||
674 | $this->assertTrue(Validation::luhn('5597511346169950', true)); |
||
675 | //Discover
|
||
676 | $this->assertTrue(Validation::luhn('6011802876467237', true)); |
||
677 | //enRoute
|
||
678 | $this->assertTrue(Validation::luhn('201496944158937', true)); |
||
679 | //JCB 15 digit
|
||
680 | $this->assertTrue(Validation::luhn('210034762247893', true)); |
||
681 | //JCB 16 digit
|
||
682 | $this->assertTrue(Validation::luhn('3096806857839939', true)); |
||
683 | //Maestro (debit card)
|
||
684 | $this->assertTrue(Validation::luhn('5020147409985219', true)); |
||
685 | //Mastercard
|
||
686 | $this->assertTrue(Validation::luhn('5580424361774366', true)); |
||
687 | //Solo 16
|
||
688 | $this->assertTrue(Validation::luhn('6767432107064987', true)); |
||
689 | //Solo 18
|
||
690 | $this->assertTrue(Validation::luhn('676714834398858593', true)); |
||
691 | //Solo 19
|
||
692 | $this->assertTrue(Validation::luhn('6767838565218340113', true)); |
||
693 | //Switch 16
|
||
694 | $this->assertTrue(Validation::luhn('5641829171515733', true)); |
||
695 | //Switch 18
|
||
696 | $this->assertTrue(Validation::luhn('493622764224625174', true)); |
||
697 | //Switch 19
|
||
698 | $this->assertTrue(Validation::luhn('6759603460617628716', true)); |
||
699 | //VISA 13 digit
|
||
700 | $this->assertTrue(Validation::luhn('4024007174754', true)); |
||
701 | //VISA 16 digit
|
||
702 | $this->assertTrue(Validation::luhn('4916375389940009', true)); |
||
703 | //Visa Electron
|
||
704 | $this->assertTrue(Validation::luhn('4175003346287100', true)); |
||
705 | //Voyager
|
||
706 | $this->assertTrue(Validation::luhn('869940697287073', true)); |
||
707 | |||
708 | $this->assertFalse(Validation::luhn('0000000000000000', true)); |
||
709 | |||
710 | $this->assertFalse(Validation::luhn('869940697287173', true)); |
||
711 | } |
||
712 | |||
713 | /**
|
||
714 | * testCustomRegexForCc method
|
||
715 | *
|
||
716 | * @return void
|
||
717 | */
|
||
718 | public function testCustomRegexForCc() { |
||
719 | $this->assertTrue(Validation::cc('12332105933743585', null, null, '/123321\\d{11}/')); |
||
720 | $this->assertFalse(Validation::cc('1233210593374358', null, null, '/123321\\d{11}/')); |
||
721 | $this->assertFalse(Validation::cc('12312305933743585', null, null, '/123321\\d{11}/')); |
||
722 | } |
||
723 | |||
724 | /**
|
||
725 | * testCustomRegexForCcWithLuhnCheck method
|
||
726 | *
|
||
727 | * @return void
|
||
728 | */
|
||
729 | public function testCustomRegexForCcWithLuhnCheck() { |
||
730 | $this->assertTrue(Validation::cc('12332110426226941', null, true, '/123321\\d{11}/')); |
||
731 | $this->assertFalse(Validation::cc('12332105933743585', null, true, '/123321\\d{11}/')); |
||
732 | $this->assertFalse(Validation::cc('12332105933743587', null, true, '/123321\\d{11}/')); |
||
733 | $this->assertFalse(Validation::cc('12312305933743585', null, true, '/123321\\d{11}/')); |
||
734 | } |
||
735 | |||
736 | /**
|
||
737 | * testFastCc method
|
||
738 | *
|
||
739 | * @return void
|
||
740 | */
|
||
741 | public function testFastCc() { |
||
742 | // too short
|
||
743 | $this->assertFalse(Validation::cc('123456789012')); |
||
744 | //American Express
|
||
745 | $this->assertTrue(Validation::cc('370482756063980')); |
||
746 | //Diners Club 14
|
||
747 | $this->assertTrue(Validation::cc('30155483651028')); |
||
748 | //2004 MasterCard/Diners Club Alliance International 14
|
||
749 | $this->assertTrue(Validation::cc('36747701998969')); |
||
750 | //2004 MasterCard/Diners Club Alliance US & Canada 16
|
||
751 | $this->assertTrue(Validation::cc('5597511346169950')); |
||
752 | //Discover
|
||
753 | $this->assertTrue(Validation::cc('6011802876467237')); |
||
754 | //Mastercard
|
||
755 | $this->assertTrue(Validation::cc('5580424361774366')); |
||
756 | //VISA 13 digit
|
||
757 | $this->assertTrue(Validation::cc('4024007174754')); |
||
758 | //VISA 16 digit
|
||
759 | $this->assertTrue(Validation::cc('4916375389940009')); |
||
760 | //Visa Electron
|
||
761 | $this->assertTrue(Validation::cc('4175003346287100')); |
||
762 | } |
||
763 | |||
764 | /**
|
||
765 | * testAllCc method
|
||
766 | *
|
||
767 | * @return void
|
||
768 | */
|
||
769 | public function testAllCc() { |
||
770 | //American Express
|
||
771 | $this->assertTrue(Validation::cc('370482756063980', 'all')); |
||
772 | //BankCard
|
||
773 | $this->assertTrue(Validation::cc('5610745867413420', 'all')); |
||
774 | //Diners Club 14
|
||
775 | $this->assertTrue(Validation::cc('30155483651028', 'all')); |
||
776 | //2004 MasterCard/Diners Club Alliance International 14
|
||
777 | $this->assertTrue(Validation::cc('36747701998969', 'all')); |
||
778 | //2004 MasterCard/Diners Club Alliance US & Canada 16
|
||
779 | $this->assertTrue(Validation::cc('5597511346169950', 'all')); |
||
780 | //Discover
|
||
781 | $this->assertTrue(Validation::cc('6011802876467237', 'all')); |
||
782 | //enRoute
|
||
783 | $this->assertTrue(Validation::cc('201496944158937', 'all')); |
||
784 | //JCB 15 digit
|
||
785 | $this->assertTrue(Validation::cc('210034762247893', 'all')); |
||
786 | //JCB 16 digit
|
||
787 | $this->assertTrue(Validation::cc('3096806857839939', 'all')); |
||
788 | //Maestro (debit card)
|
||
789 | $this->assertTrue(Validation::cc('5020147409985219', 'all')); |
||
790 | //Mastercard
|
||
791 | $this->assertTrue(Validation::cc('5580424361774366', 'all')); |
||
792 | //Solo 16
|
||
793 | $this->assertTrue(Validation::cc('6767432107064987', 'all')); |
||
794 | //Solo 18
|
||
795 | $this->assertTrue(Validation::cc('676714834398858593', 'all')); |
||
796 | //Solo 19
|
||
797 | $this->assertTrue(Validation::cc('6767838565218340113', 'all')); |
||
798 | //Switch 16
|
||
799 | $this->assertTrue(Validation::cc('5641829171515733', 'all')); |
||
800 | //Switch 18
|
||
801 | $this->assertTrue(Validation::cc('493622764224625174', 'all')); |
||
802 | //Switch 19
|
||
803 | $this->assertTrue(Validation::cc('6759603460617628716', 'all')); |
||
804 | //VISA 13 digit
|
||
805 | $this->assertTrue(Validation::cc('4024007174754', 'all')); |
||
806 | //VISA 16 digit
|
||
807 | $this->assertTrue(Validation::cc('4916375389940009', 'all')); |
||
808 | //Visa Electron
|
||
809 | $this->assertTrue(Validation::cc('4175003346287100', 'all')); |
||
810 | //Voyager
|
||
811 | $this->assertTrue(Validation::cc('869940697287073', 'all')); |
||
812 | } |
||
813 | |||
814 | /**
|
||
815 | * testAllCcDeep method
|
||
816 | *
|
||
817 | * @return void
|
||
818 | */
|
||
819 | public function testAllCcDeep() { |
||
820 | //American Express
|
||
821 | $this->assertTrue(Validation::cc('370482756063980', 'all', true)); |
||
822 | //BankCard
|
||
823 | $this->assertTrue(Validation::cc('5610745867413420', 'all', true)); |
||
824 | //Diners Club 14
|
||
825 | $this->assertTrue(Validation::cc('30155483651028', 'all', true)); |
||
826 | //2004 MasterCard/Diners Club Alliance International 14
|
||
827 | $this->assertTrue(Validation::cc('36747701998969', 'all', true)); |
||
828 | //2004 MasterCard/Diners Club Alliance US & Canada 16
|
||
829 | $this->assertTrue(Validation::cc('5597511346169950', 'all', true)); |
||
830 | //Discover
|
||
831 | $this->assertTrue(Validation::cc('6011802876467237', 'all', true)); |
||
832 | //enRoute
|
||
833 | $this->assertTrue(Validation::cc('201496944158937', 'all', true)); |
||
834 | //JCB 15 digit
|
||
835 | $this->assertTrue(Validation::cc('210034762247893', 'all', true)); |
||
836 | //JCB 16 digit
|
||
837 | $this->assertTrue(Validation::cc('3096806857839939', 'all', true)); |
||
838 | //Maestro (debit card)
|
||
839 | $this->assertTrue(Validation::cc('5020147409985219', 'all', true)); |
||
840 | //Mastercard
|
||
841 | $this->assertTrue(Validation::cc('5580424361774366', 'all', true)); |
||
842 | //Solo 16
|
||
843 | $this->assertTrue(Validation::cc('6767432107064987', 'all', true)); |
||
844 | //Solo 18
|
||
845 | $this->assertTrue(Validation::cc('676714834398858593', 'all', true)); |
||
846 | //Solo 19
|
||
847 | $this->assertTrue(Validation::cc('6767838565218340113', 'all', true)); |
||
848 | //Switch 16
|
||
849 | $this->assertTrue(Validation::cc('5641829171515733', 'all', true)); |
||
850 | //Switch 18
|
||
851 | $this->assertTrue(Validation::cc('493622764224625174', 'all', true)); |
||
852 | //Switch 19
|
||
853 | $this->assertTrue(Validation::cc('6759603460617628716', 'all', true)); |
||
854 | //VISA 13 digit
|
||
855 | $this->assertTrue(Validation::cc('4024007174754', 'all', true)); |
||
856 | //VISA 16 digit
|
||
857 | $this->assertTrue(Validation::cc('4916375389940009', 'all', true)); |
||
858 | //Visa Electron
|
||
859 | $this->assertTrue(Validation::cc('4175003346287100', 'all', true)); |
||
860 | //Voyager
|
||
861 | $this->assertTrue(Validation::cc('869940697287073', 'all', true)); |
||
862 | } |
||
863 | |||
864 | /**
|
||
865 | * testComparison method
|
||
866 | *
|
||
867 | * @return void
|
||
868 | */
|
||
869 | public function testComparison() { |
||
870 | $this->assertFalse(Validation::comparison(7, null, 6)); |
||
871 | $this->assertTrue(Validation::comparison(7, 'is greater', 6)); |
||
872 | $this->assertTrue(Validation::comparison(7, '>', 6)); |
||
873 | $this->assertTrue(Validation::comparison(6, 'is less', 7)); |
||
874 | $this->assertTrue(Validation::comparison(6, '<', 7)); |
||
875 | $this->assertTrue(Validation::comparison(7, 'greater or equal', 7)); |
||
876 | $this->assertTrue(Validation::comparison(7, '>=', 7)); |
||
877 | $this->assertTrue(Validation::comparison(7, 'greater or equal', 6)); |
||
878 | $this->assertTrue(Validation::comparison(7, '>=', 6)); |
||
879 | $this->assertTrue(Validation::comparison(6, 'less or equal', 7)); |
||
880 | $this->assertTrue(Validation::comparison(6, '<=', 7)); |
||
881 | $this->assertTrue(Validation::comparison(7, 'equal to', 7)); |
||
882 | $this->assertTrue(Validation::comparison(7, '==', 7)); |
||
883 | $this->assertTrue(Validation::comparison(7, 'not equal', 6)); |
||
884 | $this->assertTrue(Validation::comparison(7, '!=', 6)); |
||
885 | $this->assertFalse(Validation::comparison(6, 'is greater', 7)); |
||
886 | $this->assertFalse(Validation::comparison(6, '>', 7)); |
||
887 | $this->assertFalse(Validation::comparison(7, 'is less', 6)); |
||
888 | $this->assertFalse(Validation::comparison(7, '<', 6)); |
||
889 | $this->assertFalse(Validation::comparison(6, 'greater or equal', 7)); |
||
890 | $this->assertFalse(Validation::comparison(6, '>=', 7)); |
||
891 | $this->assertFalse(Validation::comparison(6, 'greater or equal', 7)); |
||
892 | $this->assertFalse(Validation::comparison(6, '>=', 7)); |
||
893 | $this->assertFalse(Validation::comparison(7, 'less or equal', 6)); |
||
894 | $this->assertFalse(Validation::comparison(7, '<=', 6)); |
||
895 | $this->assertFalse(Validation::comparison(7, 'equal to', 6)); |
||
896 | $this->assertFalse(Validation::comparison(7, '==', 6)); |
||
897 | $this->assertFalse(Validation::comparison(7, 'not equal', 7)); |
||
898 | $this->assertFalse(Validation::comparison(7, '!=', 7)); |
||
899 | |||
900 | $this->assertTrue(Validation::comparison('6.5', '!=', 6)); |
||
901 | $this->assertTrue(Validation::comparison('6.5', '<', 7)); |
||
902 | } |
||
903 | |||
904 | /**
|
||
905 | * Test comparison casting values before comparisons.
|
||
906 | *
|
||
907 | * @return void
|
||
908 | */
|
||
909 | public function testComparisonTypeChecks() { |
||
910 | $this->assertFalse(Validation::comparison('\x028', '>=', 1), 'hexish encoding fails'); |
||
911 | $this->assertFalse(Validation::comparison('0b010', '>=', 1), 'binary string data fails'); |
||
912 | $this->assertFalse(Validation::comparison('0x01', '>=', 1), 'hex string data fails'); |
||
913 | $this->assertFalse(Validation::comparison('0x1', '>=', 1), 'hex string data fails'); |
||
914 | |||
915 | $this->assertFalse(Validation::comparison('\x028', '>=', 1.5), 'hexish encoding fails'); |
||
916 | $this->assertFalse(Validation::comparison('0b010', '>=', 1.5), 'binary string data fails'); |
||
917 | $this->assertFalse(Validation::comparison('0x02', '>=', 1.5), 'hex string data fails'); |
||
918 | } |
||
919 | |||
920 | /**
|
||
921 | * testCustom method
|
||
922 | *
|
||
923 | * @return void
|
||
924 | */
|
||
925 | public function testCustom() { |
||
926 | $this->assertTrue(Validation::custom('12345', '/(?<!\\S)\\d++(?!\\S)/')); |
||
927 | $this->assertFalse(Validation::custom('Text', '/(?<!\\S)\\d++(?!\\S)/')); |
||
928 | $this->assertFalse(Validation::custom('123.45', '/(?<!\\S)\\d++(?!\\S)/')); |
||
929 | $this->assertFalse(Validation::custom('missing regex')); |
||
930 | } |
||
931 | |||
932 | /**
|
||
933 | * testDateDdmmyyyy method
|
||
934 | *
|
||
935 | * @return void
|
||
936 | */
|
||
937 | public function testDateDdmmyyyy() { |
||
938 | $this->assertTrue(Validation::date('27-12-2006', array('dmy'))); |
||
939 | $this->assertTrue(Validation::date('27.12.2006', array('dmy'))); |
||
940 | $this->assertTrue(Validation::date('27/12/2006', array('dmy'))); |
||
941 | $this->assertTrue(Validation::date('27 12 2006', array('dmy'))); |
||
942 | $this->assertFalse(Validation::date('00-00-0000', array('dmy'))); |
||
943 | $this->assertFalse(Validation::date('00.00.0000', array('dmy'))); |
||
944 | $this->assertFalse(Validation::date('00/00/0000', array('dmy'))); |
||
945 | $this->assertFalse(Validation::date('00 00 0000', array('dmy'))); |
||
946 | $this->assertFalse(Validation::date('31-11-2006', array('dmy'))); |
||
947 | $this->assertFalse(Validation::date('31.11.2006', array('dmy'))); |
||
948 | $this->assertFalse(Validation::date('31/11/2006', array('dmy'))); |
||
949 | $this->assertFalse(Validation::date('31 11 2006', array('dmy'))); |
||
950 | } |
||
951 | |||
952 | /**
|
||
953 | * testDateDdmmyyyyLeapYear method
|
||
954 | *
|
||
955 | * @return void
|
||
956 | */
|
||
957 | public function testDateDdmmyyyyLeapYear() { |
||
958 | $this->assertTrue(Validation::date('29-02-2004', array('dmy'))); |
||
959 | $this->assertTrue(Validation::date('29.02.2004', array('dmy'))); |
||
960 | $this->assertTrue(Validation::date('29/02/2004', array('dmy'))); |
||
961 | $this->assertTrue(Validation::date('29 02 2004', array('dmy'))); |
||
962 | $this->assertFalse(Validation::date('29-02-2006', array('dmy'))); |
||
963 | $this->assertFalse(Validation::date('29.02.2006', array('dmy'))); |
||
964 | $this->assertFalse(Validation::date('29/02/2006', array('dmy'))); |
||
965 | $this->assertFalse(Validation::date('29 02 2006', array('dmy'))); |
||
966 | } |
||
967 | |||
968 | /**
|
||
969 | * testDateDdmmyy method
|
||
970 | *
|
||
971 | * @return void
|
||
972 | */
|
||
973 | public function testDateDdmmyy() { |
||
974 | $this->assertTrue(Validation::date('27-12-06', array('dmy'))); |
||
975 | $this->assertTrue(Validation::date('27.12.06', array('dmy'))); |
||
976 | $this->assertTrue(Validation::date('27/12/06', array('dmy'))); |
||
977 | $this->assertTrue(Validation::date('27 12 06', array('dmy'))); |
||
978 | $this->assertFalse(Validation::date('00-00-00', array('dmy'))); |
||
979 | $this->assertFalse(Validation::date('00.00.00', array('dmy'))); |
||
980 | $this->assertFalse(Validation::date('00/00/00', array('dmy'))); |
||
981 | $this->assertFalse(Validation::date('00 00 00', array('dmy'))); |
||
982 | $this->assertFalse(Validation::date('31-11-06', array('dmy'))); |
||
983 | $this->assertFalse(Validation::date('31.11.06', array('dmy'))); |
||
984 | $this->assertFalse(Validation::date('31/11/06', array('dmy'))); |
||
985 | $this->assertFalse(Validation::date('31 11 06', array('dmy'))); |
||
986 | } |
||
987 | |||
988 | /**
|
||
989 | * testDateDdmmyyLeapYear method
|
||
990 | *
|
||
991 | * @return void
|
||
992 | */
|
||
993 | public function testDateDdmmyyLeapYear() { |
||
994 | $this->assertTrue(Validation::date('29-02-04', array('dmy'))); |
||
995 | $this->assertTrue(Validation::date('29.02.04', array('dmy'))); |
||
996 | $this->assertTrue(Validation::date('29/02/04', array('dmy'))); |
||
997 | $this->assertTrue(Validation::date('29 02 04', array('dmy'))); |
||
998 | $this->assertFalse(Validation::date('29-02-06', array('dmy'))); |
||
999 | $this->assertFalse(Validation::date('29.02.06', array('dmy'))); |
||
1000 | $this->assertFalse(Validation::date('29/02/06', array('dmy'))); |
||
1001 | $this->assertFalse(Validation::date('29 02 06', array('dmy'))); |
||
1002 | } |
||
1003 | |||
1004 | /**
|
||
1005 | * testDateDmyy method
|
||
1006 | *
|
||
1007 | * @return void
|
||
1008 | */
|
||
1009 | public function testDateDmyy() { |
||
1010 | $this->assertTrue(Validation::date('7-2-06', array('dmy'))); |
||
1011 | $this->assertTrue(Validation::date('7.2.06', array('dmy'))); |
||
1012 | $this->assertTrue(Validation::date('7/2/06', array('dmy'))); |
||
1013 | $this->assertTrue(Validation::date('7 2 06', array('dmy'))); |
||
1014 | $this->assertFalse(Validation::date('0-0-00', array('dmy'))); |
||
1015 | $this->assertFalse(Validation::date('0.0.00', array('dmy'))); |
||
1016 | $this->assertFalse(Validation::date('0/0/00', array('dmy'))); |
||
1017 | $this->assertFalse(Validation::date('0 0 00', array('dmy'))); |
||
1018 | $this->assertFalse(Validation::date('32-2-06', array('dmy'))); |
||
1019 | $this->assertFalse(Validation::date('32.2.06', array('dmy'))); |
||
1020 | $this->assertFalse(Validation::date('32/2/06', array('dmy'))); |
||
1021 | $this->assertFalse(Validation::date('32 2 06', array('dmy'))); |
||
1022 | } |
||
1023 | |||
1024 | /**
|
||
1025 | * testDateDmyyLeapYear method
|
||
1026 | *
|
||
1027 | * @return void
|
||
1028 | */
|
||
1029 | public function testDateDmyyLeapYear() { |
||
1030 | $this->assertTrue(Validation::date('29-2-04', array('dmy'))); |
||
1031 | $this->assertTrue(Validation::date('29.2.04', array('dmy'))); |
||
1032 | $this->assertTrue(Validation::date('29/2/04', array('dmy'))); |
||
1033 | $this->assertTrue(Validation::date('29 2 04', array('dmy'))); |
||
1034 | $this->assertFalse(Validation::date('29-2-06', array('dmy'))); |
||
1035 | $this->assertFalse(Validation::date('29.2.06', array('dmy'))); |
||
1036 | $this->assertFalse(Validation::date('29/2/06', array('dmy'))); |
||
1037 | $this->assertFalse(Validation::date('29 2 06', array('dmy'))); |
||
1038 | } |
||
1039 | |||
1040 | /**
|
||
1041 | * testDateDmyyyy method
|
||
1042 | *
|
||
1043 | * @return void
|
||
1044 | */
|
||
1045 | public function testDateDmyyyy() { |
||
1046 | $this->assertTrue(Validation::date('7-2-2006', array('dmy'))); |
||
1047 | $this->assertTrue(Validation::date('7.2.2006', array('dmy'))); |
||
1048 | $this->assertTrue(Validation::date('7/2/2006', array('dmy'))); |
||
1049 | $this->assertTrue(Validation::date('7 2 2006', array('dmy'))); |
||
1050 | $this->assertFalse(Validation::date('0-0-0000', array('dmy'))); |
||
1051 | $this->assertFalse(Validation::date('0.0.0000', array('dmy'))); |
||
1052 | $this->assertFalse(Validation::date('0/0/0000', array('dmy'))); |
||
1053 | $this->assertFalse(Validation::date('0 0 0000', array('dmy'))); |
||
1054 | $this->assertFalse(Validation::date('32-2-2006', array('dmy'))); |
||
1055 | $this->assertFalse(Validation::date('32.2.2006', array('dmy'))); |
||
1056 | $this->assertFalse(Validation::date('32/2/2006', array('dmy'))); |
||
1057 | $this->assertFalse(Validation::date('32 2 2006', array('dmy'))); |
||
1058 | } |
||
1059 | |||
1060 | /**
|
||
1061 | * testDateDmyyyyLeapYear method
|
||
1062 | *
|
||
1063 | * @return void
|
||
1064 | */
|
||
1065 | public function testDateDmyyyyLeapYear() { |
||
1066 | $this->assertTrue(Validation::date('29-2-2004', array('dmy'))); |
||
1067 | $this->assertTrue(Validation::date('29.2.2004', array('dmy'))); |
||
1068 | $this->assertTrue(Validation::date('29/2/2004', array('dmy'))); |
||
1069 | $this->assertTrue(Validation::date('29 2 2004', array('dmy'))); |
||
1070 | $this->assertFalse(Validation::date('29-2-2006', array('dmy'))); |
||
1071 | $this->assertFalse(Validation::date('29.2.2006', array('dmy'))); |
||
1072 | $this->assertFalse(Validation::date('29/2/2006', array('dmy'))); |
||
1073 | $this->assertFalse(Validation::date('29 2 2006', array('dmy'))); |
||
1074 | } |
||
1075 | |||
1076 | /**
|
||
1077 | * testDateMmddyyyy method
|
||
1078 | *
|
||
1079 | * @return void
|
||
1080 | */
|
||
1081 | public function testDateMmddyyyy() { |
||
1082 | $this->assertTrue(Validation::date('12-27-2006', array('mdy'))); |
||
1083 | $this->assertTrue(Validation::date('12.27.2006', array('mdy'))); |
||
1084 | $this->assertTrue(Validation::date('12/27/2006', array('mdy'))); |
||
1085 | $this->assertTrue(Validation::date('12 27 2006', array('mdy'))); |
||
1086 | $this->assertFalse(Validation::date('00-00-0000', array('mdy'))); |
||
1087 | $this->assertFalse(Validation::date('00.00.0000', array('mdy'))); |
||
1088 | $this->assertFalse(Validation::date('00/00/0000', array('mdy'))); |
||
1089 | $this->assertFalse(Validation::date('00 00 0000', array('mdy'))); |
||
1090 | $this->assertFalse(Validation::date('11-31-2006', array('mdy'))); |
||
1091 | $this->assertFalse(Validation::date('11.31.2006', array('mdy'))); |
||
1092 | $this->assertFalse(Validation::date('11/31/2006', array('mdy'))); |
||
1093 | $this->assertFalse(Validation::date('11 31 2006', array('mdy'))); |
||
1094 | } |
||
1095 | |||
1096 | /**
|
||
1097 | * testDateMmddyyyyLeapYear method
|
||
1098 | *
|
||
1099 | * @return void
|
||
1100 | */
|
||
1101 | public function testDateMmddyyyyLeapYear() { |
||
1102 | $this->assertTrue(Validation::date('02-29-2004', array('mdy'))); |
||
1103 | $this->assertTrue(Validation::date('02.29.2004', array('mdy'))); |
||
1104 | $this->assertTrue(Validation::date('02/29/2004', array('mdy'))); |
||
1105 | $this->assertTrue(Validation::date('02 29 2004', array('mdy'))); |
||
1106 | $this->assertFalse(Validation::date('02-29-2006', array('mdy'))); |
||
1107 | $this->assertFalse(Validation::date('02.29.2006', array('mdy'))); |
||
1108 | $this->assertFalse(Validation::date('02/29/2006', array('mdy'))); |
||
1109 | $this->assertFalse(Validation::date('02 29 2006', array('mdy'))); |
||
1110 | } |
||
1111 | |||
1112 | /**
|
||
1113 | * testDateMmddyy method
|
||
1114 | *
|
||
1115 | * @return void
|
||
1116 | */
|
||
1117 | public function testDateMmddyy() { |
||
1118 | $this->assertTrue(Validation::date('12-27-06', array('mdy'))); |
||
1119 | $this->assertTrue(Validation::date('12.27.06', array('mdy'))); |
||
1120 | $this->assertTrue(Validation::date('12/27/06', array('mdy'))); |
||
1121 | $this->assertTrue(Validation::date('12 27 06', array('mdy'))); |
||
1122 | $this->assertFalse(Validation::date('00-00-00', array('mdy'))); |
||
1123 | $this->assertFalse(Validation::date('00.00.00', array('mdy'))); |
||
1124 | $this->assertFalse(Validation::date('00/00/00', array('mdy'))); |
||
1125 | $this->assertFalse(Validation::date('00 00 00', array('mdy'))); |
||
1126 | $this->assertFalse(Validation::date('11-31-06', array('mdy'))); |
||
1127 | $this->assertFalse(Validation::date('11.31.06', array('mdy'))); |
||
1128 | $this->assertFalse(Validation::date('11/31/06', array('mdy'))); |
||
1129 | $this->assertFalse(Validation::date('11 31 06', array('mdy'))); |
||
1130 | } |
||
1131 | |||
1132 | /**
|
||
1133 | * testDateMmddyyLeapYear method
|
||
1134 | *
|
||
1135 | * @return void
|
||
1136 | */
|
||
1137 | public function testDateMmddyyLeapYear() { |
||
1138 | $this->assertTrue(Validation::date('02-29-04', array('mdy'))); |
||
1139 | $this->assertTrue(Validation::date('02.29.04', array('mdy'))); |
||
1140 | $this->assertTrue(Validation::date('02/29/04', array('mdy'))); |
||
1141 | $this->assertTrue(Validation::date('02 29 04', array('mdy'))); |
||
1142 | $this->assertFalse(Validation::date('02-29-06', array('mdy'))); |
||
1143 | $this->assertFalse(Validation::date('02.29.06', array('mdy'))); |
||
1144 | $this->assertFalse(Validation::date('02/29/06', array('mdy'))); |
||
1145 | $this->assertFalse(Validation::date('02 29 06', array('mdy'))); |
||
1146 | } |
||
1147 | |||
1148 | /**
|
||
1149 | * testDateMdyy method
|
||
1150 | *
|
||
1151 | * @return void
|
||
1152 | */
|
||
1153 | public function testDateMdyy() { |
||
1154 | $this->assertTrue(Validation::date('2-7-06', array('mdy'))); |
||
1155 | $this->assertTrue(Validation::date('2.7.06', array('mdy'))); |
||
1156 | $this->assertTrue(Validation::date('2/7/06', array('mdy'))); |
||
1157 | $this->assertTrue(Validation::date('2 7 06', array('mdy'))); |
||
1158 | $this->assertFalse(Validation::date('0-0-00', array('mdy'))); |
||
1159 | $this->assertFalse(Validation::date('0.0.00', array('mdy'))); |
||
1160 | $this->assertFalse(Validation::date('0/0/00', array('mdy'))); |
||
1161 | $this->assertFalse(Validation::date('0 0 00', array('mdy'))); |
||
1162 | $this->assertFalse(Validation::date('2-32-06', array('mdy'))); |
||
1163 | $this->assertFalse(Validation::date('2.32.06', array('mdy'))); |
||
1164 | $this->assertFalse(Validation::date('2/32/06', array('mdy'))); |
||
1165 | $this->assertFalse(Validation::date('2 32 06', array('mdy'))); |
||
1166 | } |
||
1167 | |||
1168 | /**
|
||
1169 | * testDateMdyyLeapYear method
|
||
1170 | *
|
||
1171 | * @return void
|
||
1172 | */
|
||
1173 | public function testDateMdyyLeapYear() { |
||
1174 | $this->assertTrue(Validation::date('2-29-04', array('mdy'))); |
||
1175 | $this->assertTrue(Validation::date('2.29.04', array('mdy'))); |
||
1176 | $this->assertTrue(Validation::date('2/29/04', array('mdy'))); |
||
1177 | $this->assertTrue(Validation::date('2 29 04', array('mdy'))); |
||
1178 | $this->assertFalse(Validation::date('2-29-06', array('mdy'))); |
||
1179 | $this->assertFalse(Validation::date('2.29.06', array('mdy'))); |
||
1180 | $this->assertFalse(Validation::date('2/29/06', array('mdy'))); |
||
1181 | $this->assertFalse(Validation::date('2 29 06', array('mdy'))); |
||
1182 | } |
||
1183 | |||
1184 | /**
|
||
1185 | * testDateMdyyyy method
|
||
1186 | *
|
||
1187 | * @return void
|
||
1188 | */
|
||
1189 | public function testDateMdyyyy() { |
||
1190 | $this->assertTrue(Validation::date('2-7-2006', array('mdy'))); |
||
1191 | $this->assertTrue(Validation::date('2.7.2006', array('mdy'))); |
||
1192 | $this->assertTrue(Validation::date('2/7/2006', array('mdy'))); |
||
1193 | $this->assertTrue(Validation::date('2 7 2006', array('mdy'))); |
||
1194 | $this->assertFalse(Validation::date('0-0-0000', array('mdy'))); |
||
1195 | $this->assertFalse(Validation::date('0.0.0000', array('mdy'))); |
||
1196 | $this->assertFalse(Validation::date('0/0/0000', array('mdy'))); |
||
1197 | $this->assertFalse(Validation::date('0 0 0000', array('mdy'))); |
||
1198 | $this->assertFalse(Validation::date('2-32-2006', array('mdy'))); |
||
1199 | $this->assertFalse(Validation::date('2.32.2006', array('mdy'))); |
||
1200 | $this->assertFalse(Validation::date('2/32/2006', array('mdy'))); |
||
1201 | $this->assertFalse(Validation::date('2 32 2006', array('mdy'))); |
||
1202 | } |
||
1203 | |||
1204 | /**
|
||
1205 | * testDateMdyyyyLeapYear method
|
||
1206 | *
|
||
1207 | * @return void
|
||
1208 | */
|
||
1209 | public function testDateMdyyyyLeapYear() { |
||
1210 | $this->assertTrue(Validation::date('2-29-2004', array('mdy'))); |
||
1211 | $this->assertTrue(Validation::date('2.29.2004', array('mdy'))); |
||
1212 | $this->assertTrue(Validation::date('2/29/2004', array('mdy'))); |
||
1213 | $this->assertTrue(Validation::date('2 29 2004', array('mdy'))); |
||
1214 | $this->assertFalse(Validation::date('2-29-2006', array('mdy'))); |
||
1215 | $this->assertFalse(Validation::date('2.29.2006', array('mdy'))); |
||
1216 | $this->assertFalse(Validation::date('2/29/2006', array('mdy'))); |
||
1217 | $this->assertFalse(Validation::date('2 29 2006', array('mdy'))); |
||
1218 | } |
||
1219 | |||
1220 | /**
|
||
1221 | * testDateYyyymmdd method
|
||
1222 | *
|
||
1223 | * @return void
|
||
1224 | */
|
||
1225 | public function testDateYyyymmdd() { |
||
1226 | $this->assertTrue(Validation::date('2006-12-27', array('ymd'))); |
||
1227 | $this->assertTrue(Validation::date('2006.12.27', array('ymd'))); |
||
1228 | $this->assertTrue(Validation::date('2006/12/27', array('ymd'))); |
||
1229 | $this->assertTrue(Validation::date('2006 12 27', array('ymd'))); |
||
1230 | $this->assertFalse(Validation::date('2006-11-31', array('ymd'))); |
||
1231 | $this->assertFalse(Validation::date('2006.11.31', array('ymd'))); |
||
1232 | $this->assertFalse(Validation::date('2006/11/31', array('ymd'))); |
||
1233 | $this->assertFalse(Validation::date('2006 11 31', array('ymd'))); |
||
1234 | } |
||
1235 | |||
1236 | /**
|
||
1237 | * testDateYyyymmddLeapYear method
|
||
1238 | *
|
||
1239 | * @return void
|
||
1240 | */
|
||
1241 | public function testDateYyyymmddLeapYear() { |
||
1242 | $this->assertTrue(Validation::date('2004-02-29', array('ymd'))); |
||
1243 | $this->assertTrue(Validation::date('2004.02.29', array('ymd'))); |
||
1244 | $this->assertTrue(Validation::date('2004/02/29', array('ymd'))); |
||
1245 | $this->assertTrue(Validation::date('2004 02 29', array('ymd'))); |
||
1246 | $this->assertFalse(Validation::date('2006-02-29', array('ymd'))); |
||
1247 | $this->assertFalse(Validation::date('2006.02.29', array('ymd'))); |
||
1248 | $this->assertFalse(Validation::date('2006/02/29', array('ymd'))); |
||
1249 | $this->assertFalse(Validation::date('2006 02 29', array('ymd'))); |
||
1250 | } |
||
1251 | |||
1252 | /**
|
||
1253 | * testDateYymmdd method
|
||
1254 | *
|
||
1255 | * @return void
|
||
1256 | */
|
||
1257 | public function testDateYymmdd() { |
||
1258 | $this->assertTrue(Validation::date('06-12-27', array('ymd'))); |
||
1259 | $this->assertTrue(Validation::date('06.12.27', array('ymd'))); |
||
1260 | $this->assertTrue(Validation::date('06/12/27', array('ymd'))); |
||
1261 | $this->assertTrue(Validation::date('06 12 27', array('ymd'))); |
||
1262 | $this->assertFalse(Validation::date('12/27/2600', array('ymd'))); |
||
1263 | $this->assertFalse(Validation::date('12.27.2600', array('ymd'))); |
||
1264 | $this->assertFalse(Validation::date('12/27/2600', array('ymd'))); |
||
1265 | $this->assertFalse(Validation::date('12 27 2600', array('ymd'))); |
||
1266 | $this->assertFalse(Validation::date('06-11-31', array('ymd'))); |
||
1267 | $this->assertFalse(Validation::date('06.11.31', array('ymd'))); |
||
1268 | $this->assertFalse(Validation::date('06/11/31', array('ymd'))); |
||
1269 | $this->assertFalse(Validation::date('06 11 31', array('ymd'))); |
||
1270 | } |
||
1271 | |||
1272 | /**
|
||
1273 | * testDateYymmddLeapYear method
|
||
1274 | *
|
||
1275 | * @return void
|
||
1276 | */
|
||
1277 | public function testDateYymmddLeapYear() { |
||
1278 | $this->assertTrue(Validation::date('2004-02-29', array('ymd'))); |
||
1279 | $this->assertTrue(Validation::date('2004.02.29', array('ymd'))); |
||
1280 | $this->assertTrue(Validation::date('2004/02/29', array('ymd'))); |
||
1281 | $this->assertTrue(Validation::date('2004 02 29', array('ymd'))); |
||
1282 | $this->assertFalse(Validation::date('2006-02-29', array('ymd'))); |
||
1283 | $this->assertFalse(Validation::date('2006.02.29', array('ymd'))); |
||
1284 | $this->assertFalse(Validation::date('2006/02/29', array('ymd'))); |
||
1285 | $this->assertFalse(Validation::date('2006 02 29', array('ymd'))); |
||
1286 | } |
||
1287 | |||
1288 | /**
|
||
1289 | * testDateDdMMMMyyyy method
|
||
1290 | *
|
||
1291 | * @return void
|
||
1292 | */
|
||
1293 | public function testDateDdMMMMyyyy() { |
||
1294 | $this->assertTrue(Validation::date('27 December 2006', array('dMy'))); |
||
1295 | $this->assertTrue(Validation::date('27 Dec 2006', array('dMy'))); |
||
1296 | $this->assertFalse(Validation::date('2006 Dec 27', array('dMy'))); |
||
1297 | $this->assertFalse(Validation::date('2006 December 27', array('dMy'))); |
||
1298 | } |
||
1299 | |||
1300 | /**
|
||
1301 | * testDateDdMMMMyyyyLeapYear method
|
||
1302 | *
|
||
1303 | * @return void
|
||
1304 | */
|
||
1305 | public function testDateDdMMMMyyyyLeapYear() { |
||
1306 | $this->assertTrue(Validation::date('29 February 2004', array('dMy'))); |
||
1307 | $this->assertFalse(Validation::date('29 February 2006', array('dMy'))); |
||
1308 | } |
||
1309 | |||
1310 | /**
|
||
1311 | * testDateMmmmDdyyyy method
|
||
1312 | *
|
||
1313 | * @return void
|
||
1314 | */
|
||
1315 | public function testDateMmmmDdyyyy() { |
||
1316 | $this->assertTrue(Validation::date('December 27, 2006', array('Mdy'))); |
||
1317 | $this->assertTrue(Validation::date('Dec 27, 2006', array('Mdy'))); |
||
1318 | $this->assertTrue(Validation::date('December 27 2006', array('Mdy'))); |
||
1319 | $this->assertTrue(Validation::date('Dec 27 2006', array('Mdy'))); |
||
1320 | $this->assertFalse(Validation::date('27 Dec 2006', array('Mdy'))); |
||
1321 | $this->assertFalse(Validation::date('2006 December 27', array('Mdy'))); |
||
1322 | $this->assertTrue(Validation::date('Sep 12, 2011', array('Mdy'))); |
||
1323 | } |
||
1324 | |||
1325 | /**
|
||
1326 | * testDateMmmmDdyyyyLeapYear method
|
||
1327 | *
|
||
1328 | * @return void
|
||
1329 | */
|
||
1330 | public function testDateMmmmDdyyyyLeapYear() { |
||
1331 | $this->assertTrue(Validation::date('February 29, 2004', array('Mdy'))); |
||
1332 | $this->assertTrue(Validation::date('Feb 29, 2004', array('Mdy'))); |
||
1333 | $this->assertTrue(Validation::date('February 29 2004', array('Mdy'))); |
||
1334 | $this->assertTrue(Validation::date('Feb 29 2004', array('Mdy'))); |
||
1335 | $this->assertFalse(Validation::date('February 29, 2006', array('Mdy'))); |
||
1336 | } |
||
1337 | |||
1338 | /**
|
||
1339 | * testDateMy method
|
||
1340 | *
|
||
1341 | * @return void
|
||
1342 | */
|
||
1343 | public function testDateMy() { |
||
1344 | $this->assertTrue(Validation::date('December 2006', array('My'))); |
||
1345 | $this->assertTrue(Validation::date('Dec 2006', array('My'))); |
||
1346 | $this->assertTrue(Validation::date('December/2006', array('My'))); |
||
1347 | $this->assertTrue(Validation::date('Dec/2006', array('My'))); |
||
1348 | } |
||
1349 | |||
1350 | /**
|
||
1351 | * testDateMyNumeric method
|
||
1352 | *
|
||
1353 | * @return void
|
||
1354 | */
|
||
1355 | public function testDateMyNumeric() { |
||
1356 | $this->assertTrue(Validation::date('01/2006', array('my'))); |
||
1357 | $this->assertTrue(Validation::date('12-2006', array('my'))); |
||
1358 | $this->assertTrue(Validation::date('12.2006', array('my'))); |
||
1359 | $this->assertTrue(Validation::date('12 2006', array('my'))); |
||
1360 | $this->assertTrue(Validation::date('01/06', array('my'))); |
||
1361 | $this->assertTrue(Validation::date('12-06', array('my'))); |
||
1362 | $this->assertTrue(Validation::date('12.06', array('my'))); |
||
1363 | $this->assertTrue(Validation::date('12 06', array('my'))); |
||
1364 | $this->assertFalse(Validation::date('13 06', array('my'))); |
||
1365 | $this->assertFalse(Validation::date('13 2006', array('my'))); |
||
1366 | } |
||
1367 | |||
1368 | /**
|
||
1369 | * testDateYmNumeric method
|
||
1370 | *
|
||
1371 | * @return void
|
||
1372 | */
|
||
1373 | public function testDateYmNumeric() { |
||
1374 | $this->assertTrue(Validation::date('2006/12', array('ym'))); |
||
1375 | $this->assertTrue(Validation::date('2006-12', array('ym'))); |
||
1376 | $this->assertTrue(Validation::date('2006-12', array('ym'))); |
||
1377 | $this->assertTrue(Validation::date('2006 12', array('ym'))); |
||
1378 | $this->assertTrue(Validation::date('2006 12', array('ym'))); |
||
1379 | $this->assertTrue(Validation::date('1900-01', array('ym'))); |
||
1380 | $this->assertTrue(Validation::date('2153-01', array('ym'))); |
||
1381 | $this->assertTrue(Validation::date('06/12', array('ym'))); |
||
1382 | $this->assertTrue(Validation::date('06-12', array('ym'))); |
||
1383 | $this->assertTrue(Validation::date('06-12', array('ym'))); |
||
1384 | $this->assertTrue(Validation::date('06 12', array('ym'))); |
||
1385 | $this->assertFalse(Validation::date('2006/12 ', array('ym'))); |
||
1386 | $this->assertFalse(Validation::date('2006/12/', array('ym'))); |
||
1387 | $this->assertFalse(Validation::date('06/12 ', array('ym'))); |
||
1388 | $this->assertFalse(Validation::date('06/13 ', array('ym'))); |
||
1389 | } |
||
1390 | |||
1391 | /**
|
||
1392 | * testDateY method
|
||
1393 | *
|
||
1394 | * @return void
|
||
1395 | */
|
||
1396 | public function testDateY() { |
||
1397 | $this->assertTrue(Validation::date('1900', array('y'))); |
||
1398 | $this->assertTrue(Validation::date('1984', array('y'))); |
||
1399 | $this->assertTrue(Validation::date('2006', array('y'))); |
||
1400 | $this->assertTrue(Validation::date('2008', array('y'))); |
||
1401 | $this->assertTrue(Validation::date('2013', array('y'))); |
||
1402 | $this->assertTrue(Validation::date('2104', array('y'))); |
||
1403 | $this->assertTrue(Validation::date('1899', array('y'))); |
||
1404 | $this->assertFalse(Validation::date('20009', array('y'))); |
||
1405 | $this->assertFalse(Validation::date(' 2012', array('y'))); |
||
1406 | $this->assertFalse(Validation::date('3000', array('y'))); |
||
1407 | $this->assertFalse(Validation::date('1799', array('y'))); |
||
1408 | } |
||
1409 | |||
1410 | /**
|
||
1411 | * Test validating dates with multiple formats
|
||
1412 | *
|
||
1413 | * @return void
|
||
1414 | */
|
||
1415 | public function testDateMultiple() { |
||
1416 | $this->assertTrue(Validation::date('2011-12-31', array('ymd', 'dmy'))); |
||
1417 | $this->assertTrue(Validation::date('31-12-2011', array('ymd', 'dmy'))); |
||
1418 | } |
||
1419 | |||
1420 | /**
|
||
1421 | * testTime method
|
||
1422 | *
|
||
1423 | * @return void
|
||
1424 | */
|
||
1425 | public function testTime() { |
||
1426 | $this->assertTrue(Validation::time('00:00')); |
||
1427 | $this->assertTrue(Validation::time('23:59')); |
||
1428 | $this->assertFalse(Validation::time('24:00')); |
||
1429 | $this->assertTrue(Validation::time('12:00')); |
||
1430 | $this->assertTrue(Validation::time('12:01')); |
||
1431 | $this->assertTrue(Validation::time('12:01am')); |
||
1432 | $this->assertTrue(Validation::time('12:01pm')); |
||
1433 | $this->assertTrue(Validation::time('1pm')); |
||
1434 | $this->assertTrue(Validation::time('1 pm')); |
||
1435 | $this->assertTrue(Validation::time('1 PM')); |
||
1436 | $this->assertTrue(Validation::time('01:00')); |
||
1437 | $this->assertFalse(Validation::time('1:00')); |
||
1438 | $this->assertTrue(Validation::time('1:00pm')); |
||
1439 | $this->assertFalse(Validation::time('13:00pm')); |
||
1440 | $this->assertFalse(Validation::time('9:00')); |
||
1441 | } |
||
1442 | |||
1443 | /**
|
||
1444 | * testBoolean method
|
||
1445 | *
|
||
1446 | * @return void
|
||
1447 | */
|
||
1448 | public function testBoolean() { |
||
1449 | $this->assertTrue(Validation::boolean('0')); |
||
1450 | $this->assertTrue(Validation::boolean('1')); |
||
1451 | $this->assertTrue(Validation::boolean(0)); |
||
1452 | $this->assertTrue(Validation::boolean(1)); |
||
1453 | $this->assertTrue(Validation::boolean(true)); |
||
1454 | $this->assertTrue(Validation::boolean(false)); |
||
1455 | $this->assertFalse(Validation::boolean('true')); |
||
1456 | $this->assertFalse(Validation::boolean('false')); |
||
1457 | $this->assertFalse(Validation::boolean('-1')); |
||
1458 | $this->assertFalse(Validation::boolean('2')); |
||
1459 | $this->assertFalse(Validation::boolean('Boo!')); |
||
1460 | } |
||
1461 | |||
1462 | /**
|
||
1463 | * testDateCustomRegx method
|
||
1464 | *
|
||
1465 | * @return void
|
||
1466 | */
|
||
1467 | public function testDateCustomRegx() { |
||
1468 | $this->assertTrue(Validation::date('2006-12-27', null, '%^(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$%')); |
||
1469 | $this->assertFalse(Validation::date('12-27-2006', null, '%^(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$%')); |
||
1470 | } |
||
1471 | |||
1472 | /**
|
||
1473 | * Test numbers with any number of decimal places, including none.
|
||
1474 | *
|
||
1475 | * @return void
|
||
1476 | */
|
||
1477 | public function testDecimalWithPlacesNull() { |
||
1478 | $this->assertTrue(Validation::decimal('+1234.54321', null)); |
||
1479 | $this->assertTrue(Validation::decimal('-1234.54321', null)); |
||
1480 | $this->assertTrue(Validation::decimal('1234.54321', null)); |
||
1481 | $this->assertTrue(Validation::decimal('+0123.45e6', null)); |
||
1482 | $this->assertTrue(Validation::decimal('-0123.45e6', null)); |
||
1483 | $this->assertTrue(Validation::decimal('0123.45e6', null)); |
||
1484 | $this->assertTrue(Validation::decimal(1234.56, null)); |
||
1485 | $this->assertTrue(Validation::decimal(1234.00, null)); |
||
1486 | $this->assertTrue(Validation::decimal(1234., null)); |
||
1487 | $this->assertTrue(Validation::decimal('1234.00', null)); |
||
1488 | $this->assertTrue(Validation::decimal(.0, null)); |
||
1489 | $this->assertTrue(Validation::decimal(.00, null)); |
||
1490 | $this->assertTrue(Validation::decimal('.00', null)); |
||
1491 | $this->assertTrue(Validation::decimal(.01, null)); |
||
1492 | $this->assertTrue(Validation::decimal('.01', null)); |
||
1493 | $this->assertTrue(Validation::decimal('1234', null)); |
||
1494 | $this->assertTrue(Validation::decimal('-1234', null)); |
||
1495 | $this->assertTrue(Validation::decimal('+1234', null)); |
||
1496 | $this->assertTrue(Validation::decimal((float)1234, null)); |
||
1497 | $this->assertTrue(Validation::decimal((double)1234, null)); |
||
1498 | $this->assertTrue(Validation::decimal((int)1234, null)); |
||
1499 | |||
1500 | $this->assertFalse(Validation::decimal('', null)); |
||
1501 | $this->assertFalse(Validation::decimal('string', null)); |
||
1502 | $this->assertFalse(Validation::decimal('1234.', null)); |
||
1503 | } |
||
1504 | |||
1505 | /**
|
||
1506 | * Test numbers with any number of decimal places greater than 0, or a float|double.
|
||
1507 | *
|
||
1508 | * @return void
|
||
1509 | */
|
||
1510 | public function testDecimalWithPlacesTrue() { |
||
1511 | $this->assertTrue(Validation::decimal('+1234.54321', true)); |
||
1512 | $this->assertTrue(Validation::decimal('-1234.54321', true)); |
||
1513 | $this->assertTrue(Validation::decimal('1234.54321', true)); |
||
1514 | $this->assertTrue(Validation::decimal('+0123.45e6', true)); |
||
1515 | $this->assertTrue(Validation::decimal('-0123.45e6', true)); |
||
1516 | $this->assertTrue(Validation::decimal('0123.45e6', true)); |
||
1517 | $this->assertTrue(Validation::decimal(1234.56, true)); |
||
1518 | $this->assertTrue(Validation::decimal(1234.00, true)); |
||
1519 | $this->assertTrue(Validation::decimal(1234., true)); |
||
1520 | $this->assertTrue(Validation::decimal('1234.00', true)); |
||
1521 | $this->assertTrue(Validation::decimal(.0, true)); |
||
1522 | $this->assertTrue(Validation::decimal(.00, true)); |
||
1523 | $this->assertTrue(Validation::decimal('.00', true)); |
||
1524 | $this->assertTrue(Validation::decimal(.01, true)); |
||
1525 | $this->assertTrue(Validation::decimal('.01', true)); |
||
1526 | $this->assertTrue(Validation::decimal((float)1234, true)); |
||
1527 | $this->assertTrue(Validation::decimal((double)1234, true)); |
||
1528 | |||
1529 | $this->assertFalse(Validation::decimal('', true)); |
||
1530 | $this->assertFalse(Validation::decimal('string', true)); |
||
1531 | $this->assertFalse(Validation::decimal('1234.', true)); |
||
1532 | $this->assertFalse(Validation::decimal((int)1234, true)); |
||
1533 | $this->assertFalse(Validation::decimal('1234', true)); |
||
1534 | $this->assertFalse(Validation::decimal('-1234', true)); |
||
1535 | $this->assertFalse(Validation::decimal('+1234', true)); |
||
1536 | } |
||
1537 | |||
1538 | /**
|
||
1539 | * Test numbers with exactly that many number of decimal places.
|
||
1540 | *
|
||
1541 | * @return void
|
||
1542 | */
|
||
1543 | public function testDecimalWithPlacesNumeric() { |
||
1544 | $this->assertTrue(Validation::decimal('.27', '2')); |
||
1545 | $this->assertTrue(Validation::decimal(0.27, 2)); |
||
1546 | $this->assertTrue(Validation::decimal(-0.27, 2)); |
||
1547 | $this->assertTrue(Validation::decimal(0.27, 2)); |
||
1548 | $this->assertTrue(Validation::decimal('0.277', '3')); |
||
1549 | $this->assertTrue(Validation::decimal(0.277, 3)); |
||
1550 | $this->assertTrue(Validation::decimal(-0.277, 3)); |
||
1551 | $this->assertTrue(Validation::decimal(0.277, 3)); |
||
1552 | $this->assertTrue(Validation::decimal('1234.5678', '4')); |
||
1553 | $this->assertTrue(Validation::decimal(1234.5678, 4)); |
||
1554 | $this->assertTrue(Validation::decimal(-1234.5678, 4)); |
||
1555 | $this->assertTrue(Validation::decimal(1234.5678, 4)); |
||
1556 | $this->assertTrue(Validation::decimal('.00', 2)); |
||
1557 | $this->assertTrue(Validation::decimal(.01, 2)); |
||
1558 | $this->assertTrue(Validation::decimal('.01', 2)); |
||
1559 | |||
1560 | $this->assertFalse(Validation::decimal('', 1)); |
||
1561 | $this->assertFalse(Validation::decimal('string', 1)); |
||
1562 | $this->assertFalse(Validation::decimal(1234., 1)); |
||
1563 | $this->assertFalse(Validation::decimal('1234.', 1)); |
||
1564 | $this->assertFalse(Validation::decimal(.0, 1)); |
||
1565 | $this->assertFalse(Validation::decimal(.00, 2)); |
||
1566 | $this->assertFalse(Validation::decimal((float)1234, 1)); |
||
1567 | $this->assertFalse(Validation::decimal((double)1234, 1)); |
||
1568 | $this->assertFalse(Validation::decimal((int)1234, 1)); |
||
1569 | $this->assertFalse(Validation::decimal('1234.5678', '3')); |
||
1570 | $this->assertFalse(Validation::decimal(1234.5678, 3)); |
||
1571 | $this->assertFalse(Validation::decimal(-1234.5678, 3)); |
||
1572 | $this->assertFalse(Validation::decimal(1234.5678, 3)); |
||
1573 | } |
||
1574 | |||
1575 | /**
|
||
1576 | * Test decimal() with invalid places parameter.
|
||
1577 | *
|
||
1578 | * @return void
|
||
1579 | */
|
||
1580 | public function testDecimalWithInvalidPlaces() { |
||
1581 | $this->assertFalse(Validation::decimal('.27', 'string')); |
||
1582 | $this->assertFalse(Validation::decimal(1234.5678, (array)true)); |
||
1583 | $this->assertFalse(Validation::decimal(-1234.5678, (object)true)); |
||
1584 | } |
||
1585 | |||
1586 | /**
|
||
1587 | * testDecimalCustomRegex method
|
||
1588 | *
|
||
1589 | * @return void
|
||
1590 | */
|
||
1591 | public function testDecimalCustomRegex() { |
||
1592 | $this->assertTrue(Validation::decimal('1.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s')); |
||
1593 | $this->assertFalse(Validation::decimal('.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s')); |
||
1594 | } |
||
1595 | |||
1596 | /**
|
||
1597 | * Test localized floats with decimal.
|
||
1598 | *
|
||
1599 | * @return void
|
||
1600 | */
|
||
1601 | public function testDecimalLocaleSet() { |
||
1602 | $this->skipIf(DS === '\\', 'The locale is not supported in Windows and affects other tests.'); |
||
1603 | $restore = setlocale(LC_NUMERIC, 0); |
||
1604 | $this->skipIf(setlocale(LC_NUMERIC, 'da_DK') === false, "The Danish locale isn't available."); |
||
1605 | |||
1606 | $this->assertTrue(Validation::decimal(1.54), '1.54 should be considered a valid float'); |
||
1607 | $this->assertTrue(Validation::decimal('1.54'), '"1.54" should be considered a valid float'); |
||
1608 | |||
1609 | $this->assertTrue(Validation::decimal(12345.67), '12345.67 should be considered a valid float'); |
||
1610 | $this->assertTrue(Validation::decimal('12,345.67'), '"12,345.67" should be considered a valid float'); |
||
1611 | |||
1612 | setlocale(LC_NUMERIC, $restore); |
||
1613 | } |
||
1614 | |||
1615 | /**
|
||
1616 | * testEmail method
|
||
1617 | *
|
||
1618 | * @return void
|
||
1619 | */
|
||
1620 | public function testEmail() { |
||
1621 | $this->assertTrue(Validation::email('abc.efg@domain.com')); |
||
1622 | $this->assertTrue(Validation::email('efg@domain.com')); |
||
1623 | $this->assertTrue(Validation::email('abc-efg@domain.com')); |
||
1624 | $this->assertTrue(Validation::email('abc_efg@domain.com')); |
||
1625 | $this->assertTrue(Validation::email('raw@test.ra.ru')); |
||
1626 | $this->assertTrue(Validation::email('abc-efg@domain-hyphened.com')); |
||
1627 | $this->assertTrue(Validation::email("p.o'malley@domain.com")); |
||
1628 | $this->assertTrue(Validation::email('abc+efg@domain.com')); |
||
1629 | $this->assertTrue(Validation::email('abc&efg@domain.com')); |
||
1630 | $this->assertTrue(Validation::email('abc.efg@12345.com')); |
||
1631 | $this->assertTrue(Validation::email('abc.efg@12345.co.jp')); |
||
1632 | $this->assertTrue(Validation::email('abc@g.cn')); |
||
1633 | $this->assertTrue(Validation::email('abc@x.com')); |
||
1634 | $this->assertTrue(Validation::email('henrik@sbcglobal.net')); |
||
1635 | $this->assertTrue(Validation::email('sani@sbcglobal.net')); |
||
1636 | |||
1637 | // all ICANN TLDs
|
||
1638 | $this->assertTrue(Validation::email('abc@example.aero')); |
||
1639 | $this->assertTrue(Validation::email('abc@example.asia')); |
||
1640 | $this->assertTrue(Validation::email('abc@example.biz')); |
||
1641 | $this->assertTrue(Validation::email('abc@example.cat')); |
||
1642 | $this->assertTrue(Validation::email('abc@example.com')); |
||
1643 | $this->assertTrue(Validation::email('abc@example.coop')); |
||
1644 | $this->assertTrue(Validation::email('abc@example.edu')); |
||
1645 | $this->assertTrue(Validation::email('abc@example.gov')); |
||
1646 | $this->assertTrue(Validation::email('abc@example.info')); |
||
1647 | $this->assertTrue(Validation::email('abc@example.int')); |
||
1648 | $this->assertTrue(Validation::email('abc@example.jobs')); |
||
1649 | $this->assertTrue(Validation::email('abc@example.mil')); |
||
1650 | $this->assertTrue(Validation::email('abc@example.mobi')); |
||
1651 | $this->assertTrue(Validation::email('abc@example.museum')); |
||
1652 | $this->assertTrue(Validation::email('abc@example.name')); |
||
1653 | $this->assertTrue(Validation::email('abc@example.net')); |
||
1654 | $this->assertTrue(Validation::email('abc@example.org')); |
||
1655 | $this->assertTrue(Validation::email('abc@example.pro')); |
||
1656 | $this->assertTrue(Validation::email('abc@example.tel')); |
||
1657 | $this->assertTrue(Validation::email('abc@example.travel')); |
||
1658 | $this->assertTrue(Validation::email('someone@st.t-com.hr')); |
||
1659 | |||
1660 | // gTLD's
|
||
1661 | $this->assertTrue(Validation::email('example@host.local')); |
||
1662 | $this->assertTrue(Validation::email('example@x.org')); |
||
1663 | $this->assertTrue(Validation::email('example@host.xxx')); |
||
1664 | |||
1665 | // strange, but technically valid email addresses
|
||
1666 | $this->assertTrue(Validation::email('S=postmaster/OU=rz/P=uni-frankfurt/A=d400/C=de@gateway.d400.de')); |
||
1667 | $this->assertTrue(Validation::email('customer/department=shipping@example.com')); |
||
1668 | $this->assertTrue(Validation::email('$A12345@example.com')); |
||
1669 | $this->assertTrue(Validation::email('!def!xyz%abc@example.com')); |
||
1670 | $this->assertTrue(Validation::email('_somename@example.com')); |
||
1671 | |||
1672 | /// Unicode
|
||
1673 | $this->assertTrue(Validation::email('some@eräume.foo')); |
||
1674 | $this->assertTrue(Validation::email('äu@öe.eräume.foo')); |
||
1675 | $this->assertTrue(Validation::email('Nyrée.surname@example.com')); |
||
1676 | |||
1677 | // invalid addresses
|
||
1678 | $this->assertFalse(Validation::email('abc@example')); |
||
1679 | $this->assertFalse(Validation::email('abc@example.c')); |
||
1680 | $this->assertFalse(Validation::email('abc@example.com.')); |
||
1681 | $this->assertFalse(Validation::email('abc.@example.com')); |
||
1682 | $this->assertFalse(Validation::email('abc@example..com')); |
||
1683 | $this->assertFalse(Validation::email('abc@example.com.a')); |
||
1684 | $this->assertFalse(Validation::email('abc;@example.com')); |
||
1685 | $this->assertFalse(Validation::email('abc@example.com;')); |
||
1686 | $this->assertFalse(Validation::email('abc@efg@example.com')); |
||
1687 | $this->assertFalse(Validation::email('abc@@example.com')); |
||
1688 | $this->assertFalse(Validation::email('abc efg@example.com')); |
||
1689 | $this->assertFalse(Validation::email('abc,efg@example.com')); |
||
1690 | $this->assertFalse(Validation::email('abc@sub,example.com')); |
||
1691 | $this->assertFalse(Validation::email("abc@sub'example.com")); |
||
1692 | $this->assertFalse(Validation::email('abc@sub/example.com')); |
||
1693 | $this->assertFalse(Validation::email('abc@yahoo!.com')); |
||
1694 | $this->assertFalse(Validation::email('abc@example_underscored.com')); |
||
1695 | $this->assertFalse(Validation::email('raw@test.ra.ru....com')); |
||
1696 | } |
||
1697 | |||
1698 | /**
|
||
1699 | * testEmailDeep method
|
||
1700 | *
|
||
1701 | * @return void
|
||
1702 | */
|
||
1703 | public function testEmailDeep() { |
||
1704 | $this->skipIf(gethostbynamel('example.abcd'), 'Your DNS service responds for non-existant domains, skipping deep email checks.'); |
||
1705 | |||
1706 | $this->assertTrue(Validation::email('abc.efg@cakephp.org', true)); |
||
1707 | $this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true)); |
||
1708 | } |
||
1709 | |||
1710 | /**
|
||
1711 | * testEmailCustomRegex method
|
||
1712 | *
|
||
1713 | * @return void
|
||
1714 | */
|
||
1715 | public function testEmailCustomRegex() { |
||
1716 | $this->assertTrue(Validation::email('abc.efg@cakephp.org', null, '/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i')); |
||
1717 | $this->assertFalse(Validation::email('abc.efg@com.caphpkeinvalid', null, '/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i')); |
||
1718 | } |
||
1719 | |||
1720 | /**
|
||
1721 | * testEqualTo method
|
||
1722 | *
|
||
1723 | * @return void
|
||
1724 | */
|
||
1725 | public function testEqualTo() { |
||
1726 | $this->assertTrue(Validation::equalTo("1", "1")); |
||
1727 | $this->assertFalse(Validation::equalTo(1, "1")); |
||
1728 | $this->assertFalse(Validation::equalTo("", null)); |
||
1729 | $this->assertFalse(Validation::equalTo("", false)); |
||
1730 | $this->assertFalse(Validation::equalTo(0, false)); |
||
1731 | $this->assertFalse(Validation::equalTo(null, false)); |
||
1732 | } |
||
1733 | |||
1734 | /**
|
||
1735 | * testIpV4 method
|
||
1736 | *
|
||
1737 | * @return void
|
||
1738 | */
|
||
1739 | public function testIpV4() { |
||
1740 | $this->assertTrue(Validation::ip('0.0.0.0', 'ipv4')); |
||
1741 | $this->assertTrue(Validation::ip('192.168.1.156')); |
||
1742 | $this->assertTrue(Validation::ip('255.255.255.255')); |
||
1743 | $this->assertFalse(Validation::ip('127.0.0')); |
||
1744 | $this->assertFalse(Validation::ip('127.0.0.a')); |
||
1745 | $this->assertFalse(Validation::ip('127.0.0.256')); |
||
1746 | $this->assertFalse(Validation::ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv4'), 'IPv6 is not valid IPv4'); |
||
1747 | } |
||
1748 | |||
1749 | /**
|
||
1750 | * testIp v6
|
||
1751 | *
|
||
1752 | * @return void
|
||
1753 | */
|
||
1754 | public function testIpv6() { |
||
1755 | $this->assertTrue(Validation::ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'IPv6')); |
||
1756 | $this->assertTrue(Validation::ip('2001:db8:85a3:0:0:8a2e:370:7334', 'IPv6')); |
||
1757 | $this->assertTrue(Validation::ip('2001:db8:85a3::8a2e:370:7334', 'IPv6')); |
||
1758 | $this->assertTrue(Validation::ip('2001:0db8:0000:0000:0000:0000:1428:57ab', 'IPv6')); |
||
1759 | $this->assertTrue(Validation::ip('2001:0db8:0000:0000:0000::1428:57ab', 'IPv6')); |
||
1760 | $this->assertTrue(Validation::ip('2001:0db8:0:0:0:0:1428:57ab', 'IPv6')); |
||
1761 | $this->assertTrue(Validation::ip('2001:0db8:0:0::1428:57ab', 'IPv6')); |
||
1762 | $this->assertTrue(Validation::ip('2001:0db8::1428:57ab', 'IPv6')); |
||
1763 | $this->assertTrue(Validation::ip('2001:db8::1428:57ab', 'IPv6')); |
||
1764 | $this->assertTrue(Validation::ip('0000:0000:0000:0000:0000:0000:0000:0001', 'IPv6')); |
||
1765 | $this->assertTrue(Validation::ip('::1', 'IPv6')); |
||
1766 | $this->assertTrue(Validation::ip('::ffff:12.34.56.78', 'IPv6')); |
||
1767 | $this->assertTrue(Validation::ip('::ffff:0c22:384e', 'IPv6')); |
||
1768 | $this->assertTrue(Validation::ip('2001:0db8:1234:0000:0000:0000:0000:0000', 'IPv6')); |
||
1769 | $this->assertTrue(Validation::ip('2001:0db8:1234:ffff:ffff:ffff:ffff:ffff', 'IPv6')); |
||
1770 | $this->assertTrue(Validation::ip('2001:db8:a::123', 'IPv6')); |
||
1771 | $this->assertTrue(Validation::ip('fe80::', 'IPv6')); |
||
1772 | $this->assertTrue(Validation::ip('::ffff:192.0.2.128', 'IPv6')); |
||
1773 | $this->assertTrue(Validation::ip('::ffff:c000:280', 'IPv6')); |
||
1774 | |||
1775 | $this->assertFalse(Validation::ip('123', 'IPv6')); |
||
1776 | $this->assertFalse(Validation::ip('ldkfj', 'IPv6')); |
||
1777 | $this->assertFalse(Validation::ip('2001::FFD3::57ab', 'IPv6')); |
||
1778 | $this->assertFalse(Validation::ip('2001:db8:85a3::8a2e:37023:7334', 'IPv6')); |
||
1779 | $this->assertFalse(Validation::ip('2001:db8:85a3::8a2e:370k:7334', 'IPv6')); |
||
1780 | $this->assertFalse(Validation::ip('1:2:3:4:5:6:7:8:9', 'IPv6')); |
||
1781 | $this->assertFalse(Validation::ip('1::2::3', 'IPv6')); |
||
1782 | $this->assertFalse(Validation::ip('1:::3:4:5', 'IPv6')); |
||
1783 | $this->assertFalse(Validation::ip('1:2:3::4:5:6:7:8:9', 'IPv6')); |
||
1784 | $this->assertFalse(Validation::ip('::ffff:2.3.4', 'IPv6')); |
||
1785 | $this->assertFalse(Validation::ip('::ffff:257.1.2.3', 'IPv6')); |
||
1786 | $this->assertFalse(Validation::ip('255.255.255.255', 'ipv6'), 'IPv4 is not valid IPv6'); |
||
1787 | } |
||
1788 | |||
1789 | /**
|
||
1790 | * testMaxLength method
|
||
1791 | *
|
||
1792 | * @return void
|
||
1793 | */
|
||
1794 | public function testMaxLength() { |
||
1795 | $this->assertTrue(Validation::maxLength('ab', 3)); |
||
1796 | $this->assertTrue(Validation::maxLength('abc', 3)); |
||
1797 | $this->assertTrue(Validation::maxLength('ÆΔΩЖÇ', 10)); |
||
1798 | |||
1799 | $this->assertFalse(Validation::maxLength('abcd', 3)); |
||
1800 | $this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3)); |
||
1801 | } |
||
1802 | |||
1803 | /**
|
||
1804 | * testMinLength method
|
||
1805 | *
|
||
1806 | * @return void
|
||
1807 | */
|
||
1808 | public function testMinLength() { |
||
1809 | $this->assertFalse(Validation::minLength('ab', 3)); |
||
1810 | $this->assertFalse(Validation::minLength('ÆΔΩЖÇ', 10)); |
||
1811 | |||
1812 | $this->assertTrue(Validation::minLength('abc', 3)); |
||
1813 | $this->assertTrue(Validation::minLength('abcd', 3)); |
||
1814 | $this->assertTrue(Validation::minLength('ÆΔΩЖÇ', 2)); |
||
1815 | } |
||
1816 | |||
1817 | /**
|
||
1818 | * testUrl method
|
||
1819 | *
|
||
1820 | * @return void
|
||
1821 | */
|
||
1822 | public function testUrl() { |
||
1823 | $this->assertTrue(Validation::url('http://www.cakephp.org')); |
||
1824 | $this->assertTrue(Validation::url('http://cakephp.org')); |
||
1825 | $this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor')); |
||
1826 | $this->assertTrue(Validation::url('http://192.168.0.1')); |
||
1827 | $this->assertTrue(Validation::url('https://www.cakephp.org')); |
||
1828 | $this->assertTrue(Validation::url('https://cakephp.org')); |
||
1829 | $this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor')); |
||
1830 | $this->assertTrue(Validation::url('https://192.168.0.1')); |
||
1831 | $this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake')); |
||
1832 | $this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake')); |
||
1833 | $this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake')); |
||
1834 | $this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake')); |
||
1835 | $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake')); |
||
1836 | $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake')); |
||
1837 | $this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake')); |
||
1838 | $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start')); |
||
1839 | $this->assertTrue(Validation::url('www.domain.tld')); |
||
1840 | $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com')); |
||
1841 | $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2')); |
||
1842 | $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php')); |
||
1843 | $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params')); |
||
1844 | $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor')); |
||
1845 | $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing')); |
||
1846 | $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)')); |
||
1847 | $this->assertTrue(Validation::url('http://www.cakephp.org', true)); |
||
1848 | $this->assertTrue(Validation::url('http://example.com/~userdir/')); |
||
1849 | $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); |
||
1850 | $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); |
||
1851 | $this->assertTrue(Validation::url('http://www.domain.longttldnotallowed')); |
||
1852 | $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); |
||
1853 | $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); |
||
1854 | $this->assertFalse(Validation::url('http://w_w.domain.co_m')); |
||
1855 | $this->assertFalse(Validation::url('http://www.domain.12com')); |
||
1856 | $this->assertFalse(Validation::url('http://www.-invaliddomain.tld')); |
||
1857 | $this->assertFalse(Validation::url('http://www.domain.-invalidtld')); |
||
1858 | $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com')); |
||
1859 | $this->assertFalse(Validation::url('http://www.underscore_domain.org')); |
||
1860 | $this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com')); |
||
1861 | $this->assertFalse(Validation::url('http://en.(wikipedia).org/')); |
||
1862 | $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); |
||
1863 | $this->assertFalse(Validation::url('--.example.com')); |
||
1864 | $this->assertFalse(Validation::url('www.cakephp.org', true)); |
||
1865 | |||
1866 | $this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html')); |
||
1867 | $this->assertTrue(Validation::url('http://www.zwischenraume.de')); |
||
1868 | $this->assertTrue(Validation::url('http://www.zwischenraume.cz')); |
||
1869 | $this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed'); |
||
1870 | $this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg')); |
||
1871 | $this->assertTrue(Validation::url('http://www.eräume.foo')); |
||
1872 | $this->assertTrue(Validation::url('http://äüö.eräume.foo')); |
||
1873 | |||
1874 | $this->assertTrue(Validation::url('http://cakephp.org:80')); |
||
1875 | $this->assertTrue(Validation::url('http://cakephp.org:443')); |
||
1876 | $this->assertTrue(Validation::url('http://cakephp.org:2000')); |
||
1877 | $this->assertTrue(Validation::url('http://cakephp.org:27000')); |
||
1878 | $this->assertTrue(Validation::url('http://cakephp.org:65000')); |
||
1879 | |||
1880 | $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]')); |
||
1881 | $this->assertTrue(Validation::url('[::1]')); |
||
1882 | $this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80')); |
||
1883 | $this->assertTrue(Validation::url('[::1]:80')); |
||
1884 | $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]')); |
||
1885 | $this->assertTrue(Validation::url('http://[::1]')); |
||
1886 | $this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80')); |
||
1887 | $this->assertTrue(Validation::url('http://[::1]:80')); |
||
1888 | |||
1889 | $this->assertFalse(Validation::url('[1::2::3]')); |
||
1890 | } |
||
1891 | |||
1892 | public function testUuid() { |
||
1893 | $this->assertTrue(Validation::uuid('00000000-0000-0000-0000-000000000000')); |
||
1894 | $this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000')); |
||
1895 | $this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000')); |
||
1896 | $this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000')); |
||
1897 | $this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000')); |
||
1898 | $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000')); |
||
1899 | $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000')); |
||
1900 | $this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000')); |
||
1901 | $this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000')); |
||
1902 | } |
||
1903 | |||
1904 | /**
|
||
1905 | * testInList method
|
||
1906 | *
|
||
1907 | * @return void
|
||
1908 | */
|
||
1909 | public function testInList() { |
||
1910 | $this->assertTrue(Validation::inList('one', array('one', 'two'))); |
||
1911 | $this->assertTrue(Validation::inList('two', array('one', 'two'))); |
||
1912 | $this->assertFalse(Validation::inList('three', array('one', 'two'))); |
||
1913 | $this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3))); |
||
1914 | $this->assertFalse(Validation::inList('one', array(0, 1, 2, 3))); |
||
1915 | $this->assertTrue(Validation::inList('2', array(1, 2, 3))); |
||
1916 | $this->assertFalse(Validation::inList('2x', array(1, 2, 3))); |
||
1917 | $this->assertFalse(Validation::inList(2, array('1', '2x', '3'))); |
||
1918 | $this->assertFalse(Validation::inList('One', array('one', 'two'))); |
||
1919 | |||
1920 | // No hexadecimal for numbers.
|
||
1921 | $this->assertFalse(Validation::inList('0x7B', array('ABC', '123'))); |
||
1922 | $this->assertFalse(Validation::inList('0x7B', array('ABC', 123))); |
||
1923 | |||
1924 | // case insensitive
|
||
1925 | $this->assertTrue(Validation::inList('one', array('One', 'Two'), true)); |
||
1926 | $this->assertTrue(Validation::inList('Two', array('one', 'two'), true)); |
||
1927 | $this->assertFalse(Validation::inList('three', array('one', 'two'), true)); |
||
1928 | } |
||
1929 | |||
1930 | /**
|
||
1931 | * testRange method
|
||
1932 | *
|
||
1933 | * @return void
|
||
1934 | */
|
||
1935 | public function testRange() { |
||
1936 | $this->assertFalse(Validation::range(20, 100, 1)); |
||
1937 | $this->assertTrue(Validation::range(20, 1, 100)); |
||
1938 | $this->assertFalse(Validation::range(.5, 1, 100)); |
||
1939 | $this->assertTrue(Validation::range(.5, 0, 100)); |
||
1940 | $this->assertTrue(Validation::range(5)); |
||
1941 | $this->assertTrue(Validation::range(-5, -10, 1)); |
||
1942 | $this->assertFalse(Validation::range('word')); |
||
1943 | } |
||
1944 | |||
1945 | /**
|
||
1946 | * Test range type checks
|
||
1947 | *
|
||
1948 | * @return void
|
||
1949 | */
|
||
1950 | public function testRangeTypeChecks() { |
||
1951 | $this->assertFalse(Validation::range('\x028', 1, 5), 'hexish encoding fails'); |
||
1952 | $this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails'); |
||
1953 | $this->assertFalse(Validation::range('0x01', 1, 5), 'hex string data fails'); |
||
1954 | $this->assertFalse(Validation::range('0x1', 1, 5), 'hex string data fails'); |
||
1955 | |||
1956 | $this->assertFalse(Validation::range('\x028', 1, 5), 'hexish encoding fails'); |
||
1957 | $this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails'); |
||
1958 | $this->assertFalse(Validation::range('0x02', 1, 5), 'hex string data fails'); |
||
1959 | } |
||
1960 | |||
1961 | /**
|
||
1962 | * testExtension method
|
||
1963 | *
|
||
1964 | * @return void
|
||
1965 | */
|
||
1966 | public function testExtension() { |
||
1967 | $this->assertTrue(Validation::extension('extension.jpeg')); |
||
1968 | $this->assertTrue(Validation::extension('extension.JPEG')); |
||
1969 | $this->assertTrue(Validation::extension('extension.gif')); |
||
1970 | $this->assertTrue(Validation::extension('extension.GIF')); |
||
1971 | $this->assertTrue(Validation::extension('extension.png')); |
||
1972 | $this->assertTrue(Validation::extension('extension.jpg')); |
||
1973 | $this->assertTrue(Validation::extension('extension.JPG')); |
||
1974 | $this->assertFalse(Validation::extension('noextension')); |
||
1975 | $this->assertTrue(Validation::extension('extension.pdf', array('PDF'))); |
||
1976 | $this->assertFalse(Validation::extension('extension.jpg', array('GIF'))); |
||
1977 | $this->assertTrue(Validation::extension(array('extension.JPG', 'extension.gif', 'extension.png'))); |
||
1978 | $this->assertTrue(Validation::extension(array('file' => array('name' => 'file.jpg')))); |
||
1979 | $this->assertTrue(Validation::extension(array('file1' => array('name' => 'file.jpg'), |
||
1980 | 'file2' => array('name' => 'file.jpg'), |
||
1981 | 'file3' => array('name' => 'file.jpg')))); |
||
1982 | $this->assertFalse(Validation::extension(array('file1' => array('name' => 'file.jpg'), |
||
1983 | 'file2' => array('name' => 'file.jpg'), |
||
1984 | 'file3' => array('name' => 'file.jpg')), array('gif'))); |
||
1985 | |||
1986 | $this->assertFalse(Validation::extension(array('noextension', 'extension.JPG', 'extension.gif', 'extension.png'))); |
||
1987 | $this->assertFalse(Validation::extension(array('extension.pdf', 'extension.JPG', 'extension.gif', 'extension.png'))); |
||
1988 | } |
||
1989 | |||
1990 | /**
|
||
1991 | * testMoney method
|
||
1992 | *
|
||
1993 | * @return void
|
||
1994 | */
|
||
1995 | public function testMoney() { |
||
1996 | $this->assertTrue(Validation::money('100')); |
||
1997 | $this->assertTrue(Validation::money('100.11')); |
||
1998 | $this->assertTrue(Validation::money('100.112')); |
||
1999 | $this->assertTrue(Validation::money('100.1')); |
||
2000 | $this->assertTrue(Validation::money('100.111,1')); |
||
2001 | $this->assertTrue(Validation::money('100.111,11')); |
||
2002 | $this->assertFalse(Validation::money('100.111,111')); |
||
2003 | |||
2004 | $this->assertTrue(Validation::money('$100')); |
||
2005 | $this->assertTrue(Validation::money('$100.11')); |
||
2006 | $this->assertTrue(Validation::money('$100.112')); |
||
2007 | $this->assertTrue(Validation::money('$100.1')); |
||
2008 | $this->assertFalse(Validation::money('$100.1111')); |
||
2009 | $this->assertFalse(Validation::money('text')); |
||
2010 | |||
2011 | $this->assertTrue(Validation::money('100', 'right')); |
||
2012 | $this->assertTrue(Validation::money('100.11$', 'right')); |
||
2013 | $this->assertTrue(Validation::money('100.112$', 'right')); |
||
2014 | $this->assertTrue(Validation::money('100.1$', 'right')); |
||
2015 | $this->assertFalse(Validation::money('100.1111$', 'right')); |
||
2016 | |||
2017 | $this->assertTrue(Validation::money('€100')); |
||
2018 | $this->assertTrue(Validation::money('€100.11')); |
||
2019 | $this->assertTrue(Validation::money('€100.112')); |
||
2020 | $this->assertTrue(Validation::money('€100.1')); |
||
2021 | $this->assertFalse(Validation::money('€100.1111')); |
||
2022 | |||
2023 | $this->assertTrue(Validation::money('100', 'right')); |
||
2024 | $this->assertTrue(Validation::money('100.11€', 'right')); |
||
2025 | $this->assertTrue(Validation::money('100.112€', 'right')); |
||
2026 | $this->assertTrue(Validation::money('100.1€', 'right')); |
||
2027 | $this->assertFalse(Validation::money('100.1111€', 'right')); |
||
2028 | } |
||
2029 | |||
2030 | /**
|
||
2031 | * Test Multiple Select Validation
|
||
2032 | *
|
||
2033 | * @return void
|
||
2034 | */
|
||
2035 | public function testMultiple() { |
||
2036 | $this->assertTrue(Validation::multiple(array(0, 1, 2, 3))); |
||
2037 | $this->assertTrue(Validation::multiple(array(50, 32, 22, 0))); |
||
2038 | $this->assertTrue(Validation::multiple(array('str', 'var', 'enum', 0))); |
||
2039 | $this->assertFalse(Validation::multiple('')); |
||
2040 | $this->assertFalse(Validation::multiple(null)); |
||
2041 | $this->assertFalse(Validation::multiple(array())); |
||
2042 | $this->assertTrue(Validation::multiple(array(0))); |
||
2043 | $this->assertTrue(Validation::multiple(array('0'))); |
||
2044 | $this->assertFalse(Validation::multiple(array(''))); |
||
2045 | |||
2046 | $this->assertTrue(Validation::multiple(array(0, 3, 4, 5), array('in' => range(0, 10)))); |
||
2047 | $this->assertFalse(Validation::multiple(array(0, 15, 20, 5), array('in' => range(0, 10)))); |
||
2048 | $this->assertFalse(Validation::multiple(array(0, 5, 10, 11), array('in' => range(0, 10)))); |
||
2049 | $this->assertFalse(Validation::multiple(array('boo', 'foo', 'bar'), array('in' => array('foo', 'bar', 'baz')))); |
||
2050 | $this->assertFalse(Validation::multiple(array('foo', '1bar'), array('in' => range(0, 10)))); |
||
2051 | |||
2052 | $this->assertFalse(Validation::multiple(array(1, 5, 10, 11), array('max' => 3))); |
||
2053 | $this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 4))); |
||
2054 | $this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 4))); |
||
2055 | $this->assertTrue(Validation::multiple(array('foo', 'bar', 'baz'), array('max' => 3))); |
||
2056 | $this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('max' => 3))); |
||
2057 | |||
2058 | $this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('min' => 3))); |
||
2059 | $this->assertTrue(Validation::multiple(array(0, 5, 10, 11, 55), array('min' => 3))); |
||
2060 | $this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz'), array('min' => 5))); |
||
2061 | $this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('min' => 10))); |
||
2062 | |||
2063 | $this->assertTrue(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5))); |
||
2064 | $this->assertTrue(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5))); |
||
2065 | |||
2066 | $this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5))); |
||
2067 | $this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5))); |
||
2068 | |||
2069 | $this->assertFalse(Validation::multiple(array(-1, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3))); |
||
2070 | $this->assertFalse(Validation::multiple(array(-1, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2))); |
||
2071 | $this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5, 'min' => 2))); |
||
2072 | |||
2073 | $this->assertFalse(Validation::multiple(array('2x', '3x'), array('in' => array(1, 2, 3, 4, 5)))); |
||
2074 | $this->assertFalse(Validation::multiple(array(2, 3), array('in' => array('1x', '2x', '3x', '4x')))); |
||
2075 | $this->assertFalse(Validation::multiple(array('one'), array('in' => array('One', 'Two')))); |
||
2076 | $this->assertFalse(Validation::multiple(array('Two'), array('in' => array('one', 'two')))); |
||
2077 | |||
2078 | // case insensitive
|
||
2079 | $this->assertTrue(Validation::multiple(array('one'), array('in' => array('One', 'Two')), true)); |
||
2080 | $this->assertTrue(Validation::multiple(array('Two'), array('in' => array('one', 'two')), true)); |
||
2081 | $this->assertFalse(Validation::multiple(array('three'), array('in' => array('one', 'two')), true)); |
||
2082 | } |
||
2083 | |||
2084 | /**
|
||
2085 | * testNumeric method
|
||
2086 | *
|
||
2087 | * @return void
|
||
2088 | */
|
||
2089 | public function testNumeric() { |
||
2090 | $this->assertFalse(Validation::numeric('teststring')); |
||
2091 | $this->assertFalse(Validation::numeric('1.1test')); |
||
2092 | $this->assertFalse(Validation::numeric('2test')); |
||
2093 | |||
2094 | $this->assertTrue(Validation::numeric('2')); |
||
2095 | $this->assertTrue(Validation::numeric(2)); |
||
2096 | $this->assertTrue(Validation::numeric(2.2)); |
||
2097 | $this->assertTrue(Validation::numeric('2.2')); |
||
2098 | } |
||
2099 | |||
2100 | /**
|
||
2101 | * testNaturalNumber method
|
||
2102 | *
|
||
2103 | * @return void
|
||
2104 | */
|
||
2105 | public function testNaturalNumber() { |
||
2106 | $this->assertFalse(Validation::naturalNumber('teststring')); |
||
2107 | $this->assertFalse(Validation::naturalNumber('5.4')); |
||
2108 | $this->assertFalse(Validation::naturalNumber(99.004)); |
||
2109 | $this->assertFalse(Validation::naturalNumber('0,05')); |
||
2110 | $this->assertFalse(Validation::naturalNumber('-2')); |
||
2111 | $this->assertFalse(Validation::naturalNumber(-2)); |
||
2112 | $this->assertFalse(Validation::naturalNumber('0')); |
||
2113 | $this->assertFalse(Validation::naturalNumber('050')); |
||
2114 | |||
2115 | $this->assertTrue(Validation::naturalNumber('2')); |
||
2116 | $this->assertTrue(Validation::naturalNumber(49)); |
||
2117 | $this->assertTrue(Validation::naturalNumber('0', true)); |
||
2118 | $this->assertTrue(Validation::naturalNumber(0, true)); |
||
2119 | } |
||
2120 | |||
2121 | /**
|
||
2122 | * testPhone method
|
||
2123 | *
|
||
2124 | * @return void
|
||
2125 | */
|
||
2126 | public function testPhone() { |
||
2127 | $this->assertFalse(Validation::phone('teststring')); |
||
2128 | $this->assertFalse(Validation::phone('1-(33)-(333)-(4444)')); |
||
2129 | $this->assertFalse(Validation::phone('1-(33)-3333-4444')); |
||
2130 | $this->assertFalse(Validation::phone('1-(33)-33-4444')); |
||
2131 | $this->assertFalse(Validation::phone('1-(33)-3-44444')); |
||
2132 | $this->assertFalse(Validation::phone('1-(33)-3-444')); |
||
2133 | $this->assertFalse(Validation::phone('1-(33)-3-44')); |
||
2134 | |||
2135 | $this->assertFalse(Validation::phone('(055) 999-9999')); |
||
2136 | $this->assertFalse(Validation::phone('(155) 999-9999')); |
||
2137 | $this->assertFalse(Validation::phone('(595) 999-9999')); |
||
2138 | $this->assertFalse(Validation::phone('(213) 099-9999')); |
||
2139 | $this->assertFalse(Validation::phone('(213) 199-9999')); |
||
2140 | |||
2141 | // invalid area-codes
|
||
2142 | $this->assertFalse(Validation::phone('1-(511)-999-9999')); |
||
2143 | $this->assertFalse(Validation::phone('1-(555)-999-9999')); |
||
2144 | |||
2145 | // invalid exhange
|
||
2146 | $this->assertFalse(Validation::phone('1-(222)-511-9999')); |
||
2147 | |||
2148 | // invalid phone number
|
||
2149 | $this->assertFalse(Validation::phone('1-(222)-555-0199')); |
||
2150 | $this->assertFalse(Validation::phone('1-(222)-555-0122')); |
||
2151 | |||
2152 | // valid phone numbers
|
||
2153 | $this->assertTrue(Validation::phone('416-428-1234')); |
||
2154 | $this->assertTrue(Validation::phone('1-(369)-333-4444')); |
||
2155 | $this->assertTrue(Validation::phone('1-(973)-333-4444')); |
||
2156 | $this->assertTrue(Validation::phone('1-(313)-555-9999')); |
||
2157 | $this->assertTrue(Validation::phone('1-(222)-555-0299')); |
||
2158 | $this->assertTrue(Validation::phone('508-428-1234')); |
||
2159 | $this->assertTrue(Validation::phone('1-(508)-232-9651')); |
||
2160 | |||
2161 | $this->assertTrue(Validation::phone('1 (222) 333 4444')); |
||
2162 | $this->assertTrue(Validation::phone('+1 (222) 333 4444')); |
||
2163 | $this->assertTrue(Validation::phone('(222) 333 4444')); |
||
2164 | |||
2165 | $this->assertTrue(Validation::phone('1-(333)-333-4444')); |
||
2166 | $this->assertTrue(Validation::phone('1.(333)-333-4444')); |
||
2167 | $this->assertTrue(Validation::phone('1.(333).333-4444')); |
||
2168 | $this->assertTrue(Validation::phone('1.(333).333.4444')); |
||
2169 | $this->assertTrue(Validation::phone('1-333-333-4444')); |
||
2170 | } |
||
2171 | |||
2172 | /**
|
||
2173 | * testPostal method
|
||
2174 | *
|
||
2175 | * @return void
|
||
2176 | */
|
||
2177 | public function testPostal() { |
||
2178 | $this->assertFalse(Validation::postal('111', null, 'de')); |
||
2179 | $this->assertFalse(Validation::postal('1111', null, 'de')); |
||
2180 | $this->assertTrue(Validation::postal('13089', null, 'de')); |
||
2181 | |||
2182 | $this->assertFalse(Validation::postal('111', null, 'be')); |
||
2183 | $this->assertFalse(Validation::postal('0123', null, 'be')); |
||
2184 | $this->assertTrue(Validation::postal('1204', null, 'be')); |
||
2185 | |||
2186 | $this->assertFalse(Validation::postal('111', null, 'it')); |
||
2187 | $this->assertFalse(Validation::postal('1111', null, 'it')); |
||
2188 | $this->assertTrue(Validation::postal('13089', null, 'it')); |
||
2189 | |||
2190 | $this->assertFalse(Validation::postal('111', null, 'uk')); |
||
2191 | $this->assertFalse(Validation::postal('1111', null, 'uk')); |
||
2192 | $this->assertFalse(Validation::postal('AZA 0AB', null, 'uk')); |
||
2193 | $this->assertFalse(Validation::postal('X0A 0ABC', null, 'uk')); |
||
2194 | $this->assertTrue(Validation::postal('X0A 0AB', null, 'uk')); |
||
2195 | $this->assertTrue(Validation::postal('AZ0A 0AA', null, 'uk')); |
||
2196 | $this->assertTrue(Validation::postal('A89 2DD', null, 'uk')); |
||
2197 | |||
2198 | $this->assertFalse(Validation::postal('111', null, 'ca')); |
||
2199 | $this->assertFalse(Validation::postal('1111', null, 'ca')); |
||
2200 | $this->assertFalse(Validation::postal('D2A 0A0', null, 'ca')); |
||
2201 | $this->assertFalse(Validation::postal('BAA 0ABC', null, 'ca')); |
||
2202 | $this->assertFalse(Validation::postal('B2A AABC', null, 'ca')); |
||
2203 | $this->assertFalse(Validation::postal('B2A 2AB', null, 'ca')); |
||
2204 | $this->assertFalse(Validation::postal('K1A 1D1', null, 'ca')); |
||
2205 | $this->assertFalse(Validation::postal('K1O 1Q1', null, 'ca')); |
||
2206 | $this->assertFalse(Validation::postal('A1A 1U1', null, 'ca')); |
||
2207 | $this->assertFalse(Validation::postal('A1F 1B1', null, 'ca')); |
||
2208 | $this->assertTrue(Validation::postal('X0A 0A2', null, 'ca')); |
||
2209 | $this->assertTrue(Validation::postal('G4V 4C3', null, 'ca')); |
||
2210 | |||
2211 | $this->assertFalse(Validation::postal('111', null, 'us')); |
||
2212 | $this->assertFalse(Validation::postal('1111', null, 'us')); |
||
2213 | $this->assertFalse(Validation::postal('130896', null, 'us')); |
||
2214 | $this->assertFalse(Validation::postal('13089-33333', null, 'us')); |
||
2215 | $this->assertFalse(Validation::postal('13089-333', null, 'us')); |
||
2216 | $this->assertFalse(Validation::postal('13A89-4333', null, 'us')); |
||
2217 | $this->assertTrue(Validation::postal('13089-3333', null, 'us')); |
||
2218 | |||
2219 | $this->assertFalse(Validation::postal('111')); |
||
2220 | $this->assertFalse(Validation::postal('1111')); |
||
2221 | $this->assertFalse(Validation::postal('130896')); |
||
2222 | $this->assertFalse(Validation::postal('13089-33333')); |
||
2223 | $this->assertFalse(Validation::postal('13089-333')); |
||
2224 | $this->assertFalse(Validation::postal('13A89-4333')); |
||
2225 | $this->assertTrue(Validation::postal('13089-3333')); |
||
2226 | } |
||
2227 | |||
2228 | /**
|
||
2229 | * test that phone and postal pass to other classes.
|
||
2230 | *
|
||
2231 | * @return void
|
||
2232 | */
|
||
2233 | public function testPhonePostalSsnPass() { |
||
2234 | $this->assertTrue(Validation::postal('text', null, 'testNl')); |
||
2235 | $this->assertTrue(Validation::phone('text', null, 'testDe')); |
||
2236 | $this->assertTrue(Validation::ssn('text', null, 'testNl')); |
||
2237 | } |
||
2238 | |||
2239 | /**
|
||
2240 | * test pass through failure on postal
|
||
2241 | *
|
||
2242 | * @expectedException PHPUnit_Framework_Error
|
||
2243 | * @return void
|
||
2244 | */
|
||
2245 | public function testPassThroughMethodFailure() { |
||
2246 | Validation::phone('text', null, 'testNl'); |
||
2247 | } |
||
2248 | |||
2249 | /**
|
||
2250 | * test the pass through calling of an alternate locale with postal()
|
||
2251 | *
|
||
2252 | * @expectedException PHPUnit_Framework_Error
|
||
2253 | * @return void
|
||
2254 | */
|
||
2255 | public function testPassThroughClassFailure() { |
||
2256 | Validation::postal('text', null, 'AUTOFAIL'); |
||
2257 | } |
||
2258 | |||
2259 | /**
|
||
2260 | * test pass through method
|
||
2261 | *
|
||
2262 | * @return void
|
||
2263 | */
|
||
2264 | public function testPassThroughMethod() { |
||
2265 | $this->assertTrue(Validation::postal('text', null, 'testNl')); |
||
2266 | } |
||
2267 | |||
2268 | /**
|
||
2269 | * testSsn method
|
||
2270 | *
|
||
2271 | * @return void
|
||
2272 | */
|
||
2273 | public function testSsn() { |
||
2274 | $this->assertFalse(Validation::ssn('111-333', null, 'dk')); |
||
2275 | $this->assertFalse(Validation::ssn('111111-333', null, 'dk')); |
||
2276 | $this->assertTrue(Validation::ssn('111111-3334', null, 'dk')); |
||
2277 | |||
2278 | $this->assertFalse(Validation::ssn('1118333', null, 'nl')); |
||
2279 | $this->assertFalse(Validation::ssn('1234567890', null, 'nl')); |
||
2280 | $this->assertFalse(Validation::ssn('12345A789', null, 'nl')); |
||
2281 | $this->assertTrue(Validation::ssn('123456789', null, 'nl')); |
||
2282 | |||
2283 | $this->assertFalse(Validation::ssn('11-33-4333', null, 'us')); |
||
2284 | $this->assertFalse(Validation::ssn('113-3-4333', null, 'us')); |
||
2285 | $this->assertFalse(Validation::ssn('111-33-333', null, 'us')); |
||
2286 | $this->assertTrue(Validation::ssn('111-33-4333', null, 'us')); |
||
2287 | } |
||
2288 | |||
2289 | /**
|
||
2290 | * testUserDefined method
|
||
2291 | *
|
||
2292 | * @return void
|
||
2293 | */
|
||
2294 | public function testUserDefined() { |
||
2295 | $validator = new CustomValidator; |
||
2296 | $this->assertFalse(Validation::userDefined('33', $validator, 'customValidate')); |
||
2297 | $this->assertFalse(Validation::userDefined('3333', $validator, 'customValidate')); |
||
2298 | $this->assertTrue(Validation::userDefined('333', $validator, 'customValidate')); |
||
2299 | } |
||
2300 | |||
2301 | /**
|
||
2302 | * testDatetime method
|
||
2303 | *
|
||
2304 | * @return void
|
||
2305 | */
|
||
2306 | public function testDatetime() { |
||
2307 | $this->assertTrue(Validation::datetime('27-12-2006 01:00', 'dmy')); |
||
2308 | $this->assertTrue(Validation::datetime('27-12-2006 01:00', array('dmy'))); |
||
2309 | $this->assertFalse(Validation::datetime('27-12-2006 1:00', 'dmy')); |
||
2310 | |||
2311 | $this->assertTrue(Validation::datetime('27.12.2006 1:00pm', 'dmy')); |
||
2312 | $this->assertFalse(Validation::datetime('27.12.2006 13:00pm', 'dmy')); |
||
2313 | |||
2314 | $this->assertTrue(Validation::datetime('27/12/2006 1:00pm', 'dmy')); |
||
2315 | $this->assertFalse(Validation::datetime('27/12/2006 9:00', 'dmy')); |
||
2316 | |||
2317 | $this->assertTrue(Validation::datetime('27 12 2006 1:00pm', 'dmy')); |
||
2318 | $this->assertFalse(Validation::datetime('27 12 2006 24:00', 'dmy')); |
||
2319 | |||
2320 | $this->assertFalse(Validation::datetime('00-00-0000 1:00pm', 'dmy')); |
||
2321 | $this->assertFalse(Validation::datetime('00.00.0000 1:00pm', 'dmy')); |
||
2322 | $this->assertFalse(Validation::datetime('00/00/0000 1:00pm', 'dmy')); |
||
2323 | $this->assertFalse(Validation::datetime('00 00 0000 1:00pm', 'dmy')); |
||
2324 | $this->assertFalse(Validation::datetime('31-11-2006 1:00pm', 'dmy')); |
||
2325 | $this->assertFalse(Validation::datetime('31.11.2006 1:00pm', 'dmy')); |
||
2326 | $this->assertFalse(Validation::datetime('31/11/2006 1:00pm', 'dmy')); |
||
2327 | $this->assertFalse(Validation::datetime('31 11 2006 1:00pm', 'dmy')); |
||
2328 | } |
||
2329 | |||
2330 | /**
|
||
2331 | * testMimeType method
|
||
2332 | *
|
||
2333 | * @return void
|
||
2334 | */
|
||
2335 | public function testMimeType() { |
||
2336 | $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; |
||
2337 | $File = new File($image, false); |
||
2338 | |||
2339 | $this->skipIf(!$File->mime(), 'Cannot determine mimeType'); |
||
2340 | |||
2341 | $this->assertTrue(Validation::mimeType($image, array('image/gif'))); |
||
2342 | $this->assertTrue(Validation::mimeType(array('tmp_name' => $image), array('image/gif'))); |
||
2343 | $this->assertTrue(Validation::mimeType(array('tmp_name' => $image), '#image/.+#')); |
||
2344 | $this->assertTrue(Validation::mimeType($image, array('image/GIF'))); |
||
2345 | |||
2346 | $this->assertFalse(Validation::mimeType($image, array('image/png'))); |
||
2347 | $this->assertFalse(Validation::mimeType(array('tmp_name' => $image), array('image/png'))); |
||
2348 | } |
||
2349 | |||
2350 | /**
|
||
2351 | * testMimeTypeFalse method
|
||
2352 | *
|
||
2353 | * @expectedException CakeException
|
||
2354 | * @return void
|
||
2355 | */
|
||
2356 | public function testMimeTypeFalse() { |
||
2357 | $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; |
||
2358 | $File = new File($image, false); |
||
2359 | $this->skipIf($File->mime(), 'mimeType can be determined, no Exception will be thrown'); |
||
2360 | Validation::mimeType($image, array('image/gif')); |
||
2361 | } |
||
2362 | |||
2363 | /**
|
||
2364 | * testUploadError method
|
||
2365 | *
|
||
2366 | * @return void
|
||
2367 | */
|
||
2368 | public function testUploadError() { |
||
2369 | $this->assertTrue(Validation::uploadError(0)); |
||
2370 | $this->assertTrue(Validation::uploadError(array('error' => 0))); |
||
2371 | $this->assertTrue(Validation::uploadError(array('error' => '0'))); |
||
2372 | |||
2373 | $this->assertFalse(Validation::uploadError(2)); |
||
2374 | $this->assertFalse(Validation::uploadError(array('error' => 2))); |
||
2375 | $this->assertFalse(Validation::uploadError(array('error' => '2'))); |
||
2376 | } |
||
2377 | |||
2378 | /**
|
||
2379 | * testFileSize method
|
||
2380 | *
|
||
2381 | * @return void
|
||
2382 | */
|
||
2383 | public function testFileSize() { |
||
2384 | $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; |
||
2385 | $this->assertTrue(Validation::fileSize($image, '<', 1024)); |
||
2386 | $this->assertTrue(Validation::fileSize(array('tmp_name' => $image), 'isless', 1024)); |
||
2387 | $this->assertTrue(Validation::fileSize($image, '<', '1KB')); |
||
2388 | $this->assertTrue(Validation::fileSize($image, '>=', 200)); |
||
2389 | $this->assertTrue(Validation::fileSize($image, '==', 201)); |
||
2390 | $this->assertTrue(Validation::fileSize($image, '==', '201B')); |
||
2391 | |||
2392 | $this->assertFalse(Validation::fileSize($image, 'isgreater', 1024)); |
||
2393 | $this->assertFalse(Validation::fileSize(array('tmp_name' => $image), '>', '1KB')); |
||
2394 | } |
||
2395 | |||
2396 | } |