mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 08:13:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,20 +2,20 @@ | |||
| /** | ||||
|  * ValidationTest file | ||||
|  * | ||||
|  * PHP Version 5.x | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The Open Group Test Suite License | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Utility | ||||
|  * @since         CakePHP(tm) v 1.2.0.4206 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Validation', 'Utility'); | ||||
| 
 | ||||
| /** | ||||
|  | @ -28,8 +28,8 @@ class CustomValidator { | |||
| /** | ||||
|  * Makes sure that a given $email address is valid and unique | ||||
|  * | ||||
|  * @param string $email | ||||
|  * @return boolean | ||||
|  * @param string $check Email to check. | ||||
|  * @return bool | ||||
|  */ | ||||
| 	public static function customValidate($check) { | ||||
| 		return (bool)preg_match('/^[0-9]{3}$/', $check); | ||||
|  | @ -88,6 +88,25 @@ class TestDeValidation { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * ValidationStub | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Utility | ||||
|  */ | ||||
| class ValidationStub extends Validation { | ||||
| 
 | ||||
| /** | ||||
|  * Stub out is_uploaded_file check | ||||
|  * | ||||
|  * @param string $path | ||||
|  * @return void | ||||
|  */ | ||||
| 	protected static function _isUploadedFile($path) { | ||||
| 		return file_exists($path); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Test Case for Validation Class | ||||
|  * | ||||
|  | @ -124,37 +143,37 @@ class ValidationTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testNotEmpty method | ||||
|  * Test notBlank method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testNotEmpty() { | ||||
| 		$this->assertTrue(Validation::notEmpty('abcdefg')); | ||||
| 		$this->assertTrue(Validation::notEmpty('fasdf ')); | ||||
| 		$this->assertTrue(Validation::notEmpty('fooo' . chr(243) . 'blabla')); | ||||
| 		$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй')); | ||||
| 		$this->assertTrue(Validation::notEmpty('José')); | ||||
| 		$this->assertTrue(Validation::notEmpty('é')); | ||||
| 		$this->assertTrue(Validation::notEmpty('π')); | ||||
| 		$this->assertFalse(Validation::notEmpty("\t ")); | ||||
| 		$this->assertFalse(Validation::notEmpty("")); | ||||
| 	public function testNotBlank() { | ||||
| 		$this->assertTrue(Validation::notBlank('abcdefg')); | ||||
| 		$this->assertTrue(Validation::notBlank('fasdf ')); | ||||
| 		$this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla')); | ||||
| 		$this->assertTrue(Validation::notBlank('abçďĕʑʘπй')); | ||||
| 		$this->assertTrue(Validation::notBlank('José')); | ||||
| 		$this->assertTrue(Validation::notBlank('é')); | ||||
| 		$this->assertTrue(Validation::notBlank('π')); | ||||
| 		$this->assertFalse(Validation::notBlank("\t ")); | ||||
| 		$this->assertFalse(Validation::notBlank("")); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testNotEmptyISO88591Encoding method | ||||
|  * Test notBlank method with ISO88591 encoding | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testNotEmptyISO88591AppEncoding() { | ||||
| 	public function testNotBlankISO88591AppEncoding() { | ||||
| 		Configure::write('App.encoding', 'ISO-8859-1'); | ||||
| 		$this->assertTrue(Validation::notEmpty('abcdefg')); | ||||
| 		$this->assertTrue(Validation::notEmpty('fasdf ')); | ||||
| 		$this->assertTrue(Validation::notEmpty('fooo' . chr(243) . 'blabla')); | ||||
| 		$this->assertTrue(Validation::notEmpty('abçďĕʑʘπй')); | ||||
| 		$this->assertTrue(Validation::notEmpty('José')); | ||||
| 		$this->assertTrue(Validation::notEmpty(utf8_decode('José'))); | ||||
| 		$this->assertFalse(Validation::notEmpty("\t ")); | ||||
| 		$this->assertFalse(Validation::notEmpty("")); | ||||
| 		$this->assertTrue(Validation::notBlank('abcdefg')); | ||||
| 		$this->assertTrue(Validation::notBlank('fasdf ')); | ||||
| 		$this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla')); | ||||
| 		$this->assertTrue(Validation::notBlank('abçďĕʑʘπй')); | ||||
| 		$this->assertTrue(Validation::notBlank('José')); | ||||
| 		$this->assertTrue(Validation::notBlank(utf8_decode('José'))); | ||||
| 		$this->assertFalse(Validation::notBlank("\t ")); | ||||
| 		$this->assertFalse(Validation::notBlank("")); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -175,6 +194,7 @@ class ValidationTest extends CakeTestCase { | |||
| 
 | ||||
| 		$this->assertFalse(Validation::alphaNumeric('12 234')); | ||||
| 		$this->assertFalse(Validation::alphaNumeric('dfd 234')); | ||||
| 		$this->assertFalse(Validation::alphaNumeric("0\n")); | ||||
| 		$this->assertFalse(Validation::alphaNumeric("\n")); | ||||
| 		$this->assertFalse(Validation::alphaNumeric("\t")); | ||||
| 		$this->assertFalse(Validation::alphaNumeric("\r")); | ||||
|  | @ -183,36 +203,17 @@ class ValidationTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAlphaNumericPassedAsArray method | ||||
|  * testLengthBetween method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAlphaNumericPassedAsArray() { | ||||
| 		$this->assertTrue(Validation::alphaNumeric(array('check' => 'frferrf'))); | ||||
| 		$this->assertTrue(Validation::alphaNumeric(array('check' => '12234'))); | ||||
| 		$this->assertTrue(Validation::alphaNumeric(array('check' => '1w2e2r3t4y'))); | ||||
| 		$this->assertTrue(Validation::alphaNumeric(array('check' => '0'))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => '12 234'))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => 'dfd 234'))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => "\n"))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => "\t"))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => "\r"))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => ' '))); | ||||
| 		$this->assertFalse(Validation::alphaNumeric(array('check' => ''))); | ||||
| 	} | ||||
| 	public function testLengthBetween() { | ||||
| 		$this->assertTrue(Validation::lengthBetween('abcdefg', 1, 7)); | ||||
| 		$this->assertTrue(Validation::lengthBetween('', 0, 7)); | ||||
| 		$this->assertTrue(Validation::lengthBetween('אกあアꀀ豈', 1, 7)); | ||||
| 
 | ||||
| /** | ||||
|  * testBetween method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testBetween() { | ||||
| 		$this->assertTrue(Validation::between('abcdefg', 1, 7)); | ||||
| 		$this->assertTrue(Validation::between('', 0, 7)); | ||||
| 		$this->assertTrue(Validation::between('אกあアꀀ豈', 1, 7)); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::between('abcdefg', 1, 6)); | ||||
| 		$this->assertFalse(Validation::between('ÆΔΩЖÇ', 1, 3)); | ||||
| 		$this->assertFalse(Validation::lengthBetween('abcdefg', 1, 6)); | ||||
| 		$this->assertFalse(Validation::lengthBetween('ÆΔΩЖÇ', 1, 3)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -230,21 +231,6 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::blank('Blank')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testBlankAsArray method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testBlankAsArray() { | ||||
| 		$this->assertTrue(Validation::blank(array('check' => ''))); | ||||
| 		$this->assertTrue(Validation::blank(array('check' => ' '))); | ||||
| 		$this->assertTrue(Validation::blank(array('check' => "\n"))); | ||||
| 		$this->assertTrue(Validation::blank(array('check' => "\t"))); | ||||
| 		$this->assertTrue(Validation::blank(array('check' => "\r"))); | ||||
| 		$this->assertFalse(Validation::blank(array('check' => '    Blank'))); | ||||
| 		$this->assertFalse(Validation::blank(array('check' => 'Blank'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testcc method | ||||
|  * | ||||
|  | @ -417,6 +403,12 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertTrue(Validation::cc('5467639122779531', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('5297350261550024', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('5162739131368058', array('mc'))); | ||||
| 		//Mastercard (additional 2016 BIN)
 | ||||
| 		$this->assertTrue(Validation::cc('2221000000000009', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('2720999999999996', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('2223000010005798', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('2623430710235708', array('mc'))); | ||||
| 		$this->assertTrue(Validation::cc('2420452519835723', array('mc'))); | ||||
| 		//Solo 16
 | ||||
| 		$this->assertTrue(Validation::cc('6767432107064987', array('solo'))); | ||||
| 		$this->assertTrue(Validation::cc('6334667758225411', array('solo'))); | ||||
|  | @ -929,42 +921,25 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::comparison(7, '==', 6)); | ||||
| 		$this->assertFalse(Validation::comparison(7, 'not equal', 7)); | ||||
| 		$this->assertFalse(Validation::comparison(7, '!=', 7)); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::comparison('6.5', '!=', 6)); | ||||
| 		$this->assertTrue(Validation::comparison('6.5', '<', 7)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testComparisonAsArray method | ||||
|  * Test comparison casting values before comparisons. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testComparisonAsArray() { | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'is greater', 'check2' => 6))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>', 'check2' => 6))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'is less', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'greater or equal','check2' => 6))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '>=', 'check2' => 6))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => 'less or equal', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 6, 'operator' => '<=', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '==', 'check2' => 7))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 6))); | ||||
| 		$this->assertTrue(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'is greater', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'is less', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => 'greater or equal', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 6, 'operator' => '>=', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'less or equal', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '<=', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'equal to', 'check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '==','check2' => 6))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => 'not equal', 'check2' => 7))); | ||||
| 		$this->assertFalse(Validation::comparison(array('check1' => 7, 'operator' => '!=', 'check2' => 7))); | ||||
| 	public function testComparisonTypeChecks() { | ||||
| 		$this->assertFalse(Validation::comparison('\x028', '>=', 1), 'hexish encoding fails'); | ||||
| 		$this->assertFalse(Validation::comparison('0b010', '>=', 1), 'binary string data fails'); | ||||
| 		$this->assertFalse(Validation::comparison('0x01', '>=', 1), 'hex string data fails'); | ||||
| 		$this->assertFalse(Validation::comparison('0x1', '>=', 1), 'hex string data fails'); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::comparison('\x028', '>=', 1.5), 'hexish encoding fails'); | ||||
| 		$this->assertFalse(Validation::comparison('0b010', '>=', 1.5), 'binary string data fails'); | ||||
| 		$this->assertFalse(Validation::comparison('0x02', '>=', 1.5), 'hex string data fails'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -979,17 +954,6 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::custom('missing regex')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testCustomAsArray method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCustomAsArray() { | ||||
| 		$this->assertTrue(Validation::custom(array('check' => '12345', 'regex' => '/(?<!\\S)\\d++(?!\\S)/'))); | ||||
| 		$this->assertFalse(Validation::custom(array('check' => 'Text', 'regex' => '/(?<!\\S)\\d++(?!\\S)/'))); | ||||
| 		$this->assertFalse(Validation::custom(array('check' => '123.45', 'regex' => '/(?<!\\S)\\d++(?!\\S)/'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDateDdmmyyyy method | ||||
|  * | ||||
|  | @ -1414,14 +1378,58 @@ class ValidationTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testDateMyNumeric() { | ||||
| 		$this->assertTrue(Validation::date('12/2006', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('01/2006', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12-2006', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12.2006', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12 2006', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('12/06', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('12-06', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('12.06', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('12 06', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('01/06', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12-06', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12.06', array('my'))); | ||||
| 		$this->assertTrue(Validation::date('12 06', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('13 06', array('my'))); | ||||
| 		$this->assertFalse(Validation::date('13 2006', array('my'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDateYmNumeric method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDateYmNumeric() { | ||||
| 		$this->assertTrue(Validation::date('2006/12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('2006-12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('2006-12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('2006 12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('2006 12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('1900-01', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('2153-01', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('06/12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('06-12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('06-12', array('ym'))); | ||||
| 		$this->assertTrue(Validation::date('06 12', array('ym'))); | ||||
| 		$this->assertFalse(Validation::date('2006/12 ', array('ym'))); | ||||
| 		$this->assertFalse(Validation::date('2006/12/', array('ym'))); | ||||
| 		$this->assertFalse(Validation::date('06/12 ', array('ym'))); | ||||
| 		$this->assertFalse(Validation::date('06/13 ', array('ym'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDateY method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDateY() { | ||||
| 		$this->assertTrue(Validation::date('1900', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('1984', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('2006', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('2008', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('2013', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('2104', array('y'))); | ||||
| 		$this->assertTrue(Validation::date('1899', array('y'))); | ||||
| 		$this->assertFalse(Validation::date('20009', array('y'))); | ||||
| 		$this->assertFalse(Validation::date(' 2012', array('y'))); | ||||
| 		$this->assertFalse(Validation::date('3000', array('y'))); | ||||
| 		$this->assertFalse(Validation::date('1799', array('y'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1610,6 +1618,25 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::decimal('.54321', null, '/^[-+]?[0-9]+(\\.[0-9]+)?$/s')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test localized floats with decimal. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecimalLocaleSet() { | ||||
| 		$this->skipIf(DS === '\\', 'The locale is not supported in Windows and affects other tests.'); | ||||
| 		$restore = setlocale(LC_NUMERIC, 0); | ||||
| 		$this->skipIf(setlocale(LC_NUMERIC, 'da_DK') === false, "The Danish locale isn't available."); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::decimal(1.54), '1.54 should be considered a valid float'); | ||||
| 		$this->assertTrue(Validation::decimal('1.54'), '"1.54" should be considered a valid float'); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::decimal(12345.67), '12345.67 should be considered a valid float'); | ||||
| 		$this->assertTrue(Validation::decimal('12,345.67'), '"12,345.67" should be considered a valid float'); | ||||
| 
 | ||||
| 		setlocale(LC_NUMERIC, $restore); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEmail method | ||||
|  * | ||||
|  | @ -1667,6 +1694,11 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertTrue(Validation::email('!def!xyz%abc@example.com')); | ||||
| 		$this->assertTrue(Validation::email('_somename@example.com')); | ||||
| 
 | ||||
| 		/// Unicode
 | ||||
| 		$this->assertTrue(Validation::email('some@eräume.foo')); | ||||
| 		$this->assertTrue(Validation::email('äu@öe.eräume.foo')); | ||||
| 		$this->assertTrue(Validation::email('Nyrée.surname@example.com')); | ||||
| 
 | ||||
| 		// invalid addresses
 | ||||
| 		$this->assertFalse(Validation::email('abc@example')); | ||||
| 		$this->assertFalse(Validation::email('abc@example.c')); | ||||
|  | @ -1684,7 +1716,6 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::email("abc@sub'example.com")); | ||||
| 		$this->assertFalse(Validation::email('abc@sub/example.com')); | ||||
| 		$this->assertFalse(Validation::email('abc@yahoo!.com')); | ||||
| 		$this->assertFalse(Validation::email("Nyrée.surname@example.com")); | ||||
| 		$this->assertFalse(Validation::email('abc@example_underscored.com')); | ||||
| 		$this->assertFalse(Validation::email('raw@test.ra.ru....com')); | ||||
| 	} | ||||
|  | @ -1699,7 +1730,6 @@ class ValidationTest extends CakeTestCase { | |||
| 
 | ||||
| 		$this->assertTrue(Validation::email('abc.efg@cakephp.org', true)); | ||||
| 		$this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true)); | ||||
| 		$this->assertFalse(Validation::email('abc@example.abcd', true)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1855,6 +1885,7 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com')); | ||||
| 		$this->assertFalse(Validation::url('http://en.(wikipedia).org/')); | ||||
| 		$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); | ||||
| 		$this->assertFalse(Validation::url('--.example.com')); | ||||
| 		$this->assertFalse(Validation::url('www.cakephp.org', true)); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html')); | ||||
|  | @ -1862,6 +1893,8 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertTrue(Validation::url('http://www.zwischenraume.cz')); | ||||
| 		$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed'); | ||||
| 		$this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg')); | ||||
| 		$this->assertTrue(Validation::url('http://www.eräume.foo')); | ||||
| 		$this->assertTrue(Validation::url('http://äüö.eräume.foo')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::url('http://cakephp.org:80')); | ||||
| 		$this->assertTrue(Validation::url('http://cakephp.org:443')); | ||||
|  | @ -1882,6 +1915,7 @@ class ValidationTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| 	public function testUuid() { | ||||
| 		$this->assertTrue(Validation::uuid('00000000-0000-0000-0000-000000000000')); | ||||
| 		$this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000')); | ||||
| 		$this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000')); | ||||
| 		$this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000')); | ||||
|  | @ -1903,8 +1937,19 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::inList('three', array('one', 'two'))); | ||||
| 		$this->assertFalse(Validation::inList('1one', array(0, 1, 2, 3))); | ||||
| 		$this->assertFalse(Validation::inList('one', array(0, 1, 2, 3))); | ||||
| 		$this->assertFalse(Validation::inList('2', array(1, 2, 3))); | ||||
| 		$this->assertTrue(Validation::inList('2', array(1, 2, 3), false)); | ||||
| 		$this->assertTrue(Validation::inList('2', array(1, 2, 3))); | ||||
| 		$this->assertFalse(Validation::inList('2x', array(1, 2, 3))); | ||||
| 		$this->assertFalse(Validation::inList(2, array('1', '2x', '3'))); | ||||
| 		$this->assertFalse(Validation::inList('One', array('one', 'two'))); | ||||
| 
 | ||||
| 		// No hexadecimal for numbers.
 | ||||
| 		$this->assertFalse(Validation::inList('0x7B', array('ABC', '123'))); | ||||
| 		$this->assertFalse(Validation::inList('0x7B', array('ABC', 123))); | ||||
| 
 | ||||
| 		// case insensitive
 | ||||
| 		$this->assertTrue(Validation::inList('one', array('One', 'Two'), true)); | ||||
| 		$this->assertTrue(Validation::inList('Two', array('one', 'two'), true)); | ||||
| 		$this->assertFalse(Validation::inList('three', array('one', 'two'), true)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1922,6 +1967,22 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::range('word')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test range type checks | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRangeTypeChecks() { | ||||
| 		$this->assertFalse(Validation::range('\x028', 1, 5), 'hexish encoding fails'); | ||||
| 		$this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails'); | ||||
| 		$this->assertFalse(Validation::range('0x01', 1, 5), 'hex string data fails'); | ||||
| 		$this->assertFalse(Validation::range('0x1', 1, 5), 'hex string data fails'); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::range('\x028', 1, 5), 'hexish encoding fails'); | ||||
| 		$this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails'); | ||||
| 		$this->assertFalse(Validation::range('0x02', 1, 5), 'hex string data fails'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExtension method | ||||
|  * | ||||
|  | @ -1957,29 +2018,37 @@ class ValidationTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testMoney() { | ||||
| 		$this->assertTrue(Validation::money('100')); | ||||
| 		$this->assertTrue(Validation::money('100.11')); | ||||
| 		$this->assertTrue(Validation::money('100.112')); | ||||
| 		$this->assertTrue(Validation::money('100.1')); | ||||
| 		$this->assertTrue(Validation::money('100.111,1')); | ||||
| 		$this->assertTrue(Validation::money('100.111,11')); | ||||
| 		$this->assertFalse(Validation::money('100.111,111')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::money('$100')); | ||||
| 		$this->assertTrue(Validation::money('$100.11')); | ||||
| 		$this->assertTrue(Validation::money('$100.112')); | ||||
| 		$this->assertFalse(Validation::money('$100.1')); | ||||
| 		$this->assertTrue(Validation::money('$100.1')); | ||||
| 		$this->assertFalse(Validation::money('$100.1111')); | ||||
| 		$this->assertFalse(Validation::money('text')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::money('100', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.11$', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.112$', 'right')); | ||||
| 		$this->assertFalse(Validation::money('100.1$', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.1$', 'right')); | ||||
| 		$this->assertFalse(Validation::money('100.1111$', 'right')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::money('€100')); | ||||
| 		$this->assertTrue(Validation::money('€100.11')); | ||||
| 		$this->assertTrue(Validation::money('€100.112')); | ||||
| 		$this->assertFalse(Validation::money('€100.1')); | ||||
| 		$this->assertTrue(Validation::money('€100.1')); | ||||
| 		$this->assertFalse(Validation::money('€100.1111')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::money('100', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.11€', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.112€', 'right')); | ||||
| 		$this->assertFalse(Validation::money('100.1€', 'right')); | ||||
| 		$this->assertTrue(Validation::money('100.1€', 'right')); | ||||
| 		$this->assertFalse(Validation::money('100.1111€', 'right')); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -1995,8 +2064,9 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::multiple('')); | ||||
| 		$this->assertFalse(Validation::multiple(null)); | ||||
| 		$this->assertFalse(Validation::multiple(array())); | ||||
| 		$this->assertFalse(Validation::multiple(array(0))); | ||||
| 		$this->assertFalse(Validation::multiple(array('0'))); | ||||
| 		$this->assertTrue(Validation::multiple(array(0))); | ||||
| 		$this->assertTrue(Validation::multiple(array('0'))); | ||||
| 		$this->assertFalse(Validation::multiple(array(''))); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::multiple(array(0, 3, 4, 5), array('in' => range(0, 10)))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 15, 20, 5), array('in' => range(0, 10)))); | ||||
|  | @ -2004,8 +2074,9 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::multiple(array('boo', 'foo', 'bar'), array('in' => array('foo', 'bar', 'baz')))); | ||||
| 		$this->assertFalse(Validation::multiple(array('foo', '1bar'), array('in' => range(0, 10)))); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 3))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 3))); | ||||
| 		$this->assertFalse(Validation::multiple(array(1, 5, 10, 11), array('max' => 3))); | ||||
| 		$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 4))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 4))); | ||||
| 		$this->assertTrue(Validation::multiple(array('foo', 'bar', 'baz'), array('max' => 3))); | ||||
| 		$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('max' => 3))); | ||||
| 
 | ||||
|  | @ -2015,14 +2086,24 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('min' => 10))); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5))); | ||||
| 		$this->assertFalse(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5))); | ||||
| 		$this->assertTrue(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5), false)); | ||||
| 		$this->assertTrue(Validation::multiple(array('0', '5', '9'), array('in' => range(0, 10), 'max' => 5))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2))); | ||||
| 		$this->assertFalse(Validation::multiple(array(-1, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3))); | ||||
| 		$this->assertFalse(Validation::multiple(array(-1, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2))); | ||||
| 		$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5, 'min' => 2))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::multiple(array('2x', '3x'), array('in' => array(1, 2, 3, 4, 5)))); | ||||
| 		$this->assertFalse(Validation::multiple(array(2, 3), array('in' => array('1x', '2x', '3x', '4x')))); | ||||
| 		$this->assertFalse(Validation::multiple(array('one'), array('in' => array('One', 'Two')))); | ||||
| 		$this->assertFalse(Validation::multiple(array('Two'), array('in' => array('one', 'two')))); | ||||
| 
 | ||||
| 		// case insensitive
 | ||||
| 		$this->assertTrue(Validation::multiple(array('one'), array('in' => array('One', 'Two')), true)); | ||||
| 		$this->assertTrue(Validation::multiple(array('Two'), array('in' => array('one', 'two')), true)); | ||||
| 		$this->assertFalse(Validation::multiple(array('three'), array('in' => array('one', 'two')), true)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -2079,8 +2160,25 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::phone('(055) 999-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(155) 999-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(595) 999-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(555) 099-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(555) 199-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(213) 099-9999')); | ||||
| 		$this->assertFalse(Validation::phone('(213) 199-9999')); | ||||
| 
 | ||||
| 		// invalid area-codes
 | ||||
| 		$this->assertFalse(Validation::phone('1-(511)-999-9999')); | ||||
| 		$this->assertFalse(Validation::phone('1-(555)-999-9999')); | ||||
| 
 | ||||
| 		// invalid phone number
 | ||||
| 		$this->assertFalse(Validation::phone('1-(222)-555-0199')); | ||||
| 		$this->assertFalse(Validation::phone('1-(222)-555-0122')); | ||||
| 
 | ||||
| 		// valid phone numbers
 | ||||
| 		$this->assertTrue(Validation::phone('416-428-1234')); | ||||
| 		$this->assertTrue(Validation::phone('1-(369)-333-4444')); | ||||
| 		$this->assertTrue(Validation::phone('1-(973)-333-4444')); | ||||
| 		$this->assertTrue(Validation::phone('1-(313)-555-9999')); | ||||
| 		$this->assertTrue(Validation::phone('1-(222)-555-0299')); | ||||
| 		$this->assertTrue(Validation::phone('508-428-1234')); | ||||
| 		$this->assertTrue(Validation::phone('1-(508)-232-9651')); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::phone('1 (222) 333 4444')); | ||||
| 		$this->assertTrue(Validation::phone('+1 (222) 333 4444')); | ||||
|  | @ -2091,6 +2189,7 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertTrue(Validation::phone('1.(333).333-4444')); | ||||
| 		$this->assertTrue(Validation::phone('1.(333).333.4444')); | ||||
| 		$this->assertTrue(Validation::phone('1-333-333-4444')); | ||||
| 		$this->assertTrue(Validation::phone('1-800-211-4511')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -2125,6 +2224,10 @@ class ValidationTest extends CakeTestCase { | |||
| 		$this->assertFalse(Validation::postal('BAA 0ABC', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('B2A AABC', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('B2A 2AB', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('K1A 1D1', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('K1O 1Q1', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('A1A 1U1', null, 'ca')); | ||||
| 		$this->assertFalse(Validation::postal('A1F 1B1', null, 'ca')); | ||||
| 		$this->assertTrue(Validation::postal('X0A 0A2', null, 'ca')); | ||||
| 		$this->assertTrue(Validation::postal('G4V 4C3', null, 'ca')); | ||||
| 
 | ||||
|  | @ -2171,7 +2274,7 @@ class ValidationTest extends CakeTestCase { | |||
|  * | ||||
|  * @expectedException PHPUnit_Framework_Error | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testPassThroughClassFailure() { | ||||
| 		Validation::postal('text', null, 'AUTOFAIL'); | ||||
| 	} | ||||
|  | @ -2255,9 +2358,13 @@ class ValidationTest extends CakeTestCase { | |||
| 	public function testMimeType() { | ||||
| 		$image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; | ||||
| 		$File = new File($image, false); | ||||
| 
 | ||||
| 		$this->skipIf(!$File->mime(), 'Cannot determine mimeType'); | ||||
| 
 | ||||
| 		$this->assertTrue(Validation::mimeType($image, array('image/gif'))); | ||||
| 		$this->assertTrue(Validation::mimeType(array('tmp_name' => $image), array('image/gif'))); | ||||
| 		$this->assertTrue(Validation::mimeType(array('tmp_name' => $image), '#image/.+#')); | ||||
| 		$this->assertTrue(Validation::mimeType($image, array('image/GIF'))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::mimeType($image, array('image/png'))); | ||||
| 		$this->assertFalse(Validation::mimeType(array('tmp_name' => $image), array('image/png'))); | ||||
|  | @ -2277,15 +2384,164 @@ class ValidationTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMimeType method | ||||
|  * testUploadError method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadError() { | ||||
| 		$this->assertTrue(Validation::uploadError(0)); | ||||
| 		$this->assertTrue(Validation::uploadError(array('error' => 0))); | ||||
| 		$this->assertTrue(Validation::uploadError(array('error' => '0'))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::uploadError(2)); | ||||
| 		$this->assertFalse(Validation::uploadError(array('error' => 2))); | ||||
| 		$this->assertFalse(Validation::uploadError(array('error' => '2'))); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::uploadError(UPLOAD_ERR_NO_FILE)); | ||||
| 		$this->assertFalse(Validation::uploadError(UPLOAD_ERR_FORM_SIZE, true)); | ||||
| 		$this->assertFalse(Validation::uploadError(UPLOAD_ERR_INI_SIZE, true)); | ||||
| 		$this->assertFalse(Validation::uploadError(UPLOAD_ERR_NO_TMP_DIR, true)); | ||||
| 		$this->assertTrue(Validation::uploadError(UPLOAD_ERR_NO_FILE, true)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testFileSize method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFileSize() { | ||||
| 		$image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; | ||||
| 		$this->assertTrue(Validation::fileSize($image, '<', 1024)); | ||||
| 		$this->assertTrue(Validation::fileSize(array('tmp_name' => $image), 'isless', 1024)); | ||||
| 		$this->assertTrue(Validation::fileSize($image, '<', '1KB')); | ||||
| 		$this->assertTrue(Validation::fileSize($image, '>=', 200)); | ||||
| 		$this->assertTrue(Validation::fileSize($image, '==', 201)); | ||||
| 		$this->assertTrue(Validation::fileSize($image, '==', '201B')); | ||||
| 
 | ||||
| 		$this->assertFalse(Validation::fileSize($image, 'isgreater', 1024)); | ||||
| 		$this->assertFalse(Validation::fileSize(array('tmp_name' => $image), '>', '1KB')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test uploaded file validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadedFileErrorCode() { | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile('derp')); | ||||
| 		$invalid = array( | ||||
| 			'name' => 'testing' | ||||
| 		); | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile($invalid)); | ||||
| 		$file = array( | ||||
| 			'name' => 'cake.power.gif', | ||||
| 			'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif', | ||||
| 			'error' => UPLOAD_ERR_OK, | ||||
| 			'type' => 'image/gif', | ||||
| 			'size' => 201 | ||||
| 		); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file)); | ||||
| 		$file['error'] = UPLOAD_ERR_NO_FILE; | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile($file), 'Error upload should fail.'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test uploaded file validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadedFileMimeType() { | ||||
| 		$file = array( | ||||
| 			'name' => 'cake.power.gif', | ||||
| 			'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif', | ||||
| 			'error' => UPLOAD_ERR_OK, | ||||
| 			'type' => 'text/plain', | ||||
| 			'size' => 201 | ||||
| 		); | ||||
| 		$options = array( | ||||
| 			'types' => array('text/plain') | ||||
| 		); | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile($file, $options), 'Incorrect mimetype.'); | ||||
| 		$options = array( | ||||
| 			'types' => array('image/gif', 'image/png') | ||||
| 		); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file, $options)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test uploaded file validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadedFileSize() { | ||||
| 		$file = array( | ||||
| 			'name' => 'cake.power.gif', | ||||
| 			'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif', | ||||
| 			'error' => UPLOAD_ERR_OK, | ||||
| 			'type' => 'text/plain', | ||||
| 			'size' => 201 | ||||
| 		); | ||||
| 		$options = array( | ||||
| 			'minSize' => 500 | ||||
| 		); | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile($file, $options), 'Too small'); | ||||
| 		$options = array( | ||||
| 			'maxSize' => 100 | ||||
| 		); | ||||
| 		$this->assertFalse(ValidationStub::uploadedFile($file, $options), 'Too big'); | ||||
| 		$options = array( | ||||
| 			'minSize' => 100, | ||||
| 		); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file, $options)); | ||||
| 		$options = array( | ||||
| 			'maxSize' => 500, | ||||
| 		); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file, $options)); | ||||
| 		$options = array( | ||||
| 			'minSize' => 100, | ||||
| 			'maxSize' => 500 | ||||
| 		); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file, $options)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test uploaded file validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadedFileNoFile() { | ||||
| 		$file = array( | ||||
| 			'name' => '', | ||||
| 			'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif', | ||||
| 			'error' => UPLOAD_ERR_NO_FILE, | ||||
| 			'type' => '', | ||||
| 			'size' => 0 | ||||
| 		); | ||||
| 		$options = array( | ||||
| 			'optional' => true, | ||||
| 			'minSize' => 500, | ||||
| 			'types' => array('image/gif', 'image/png') | ||||
| 		); | ||||
| 		$this->assertTrue(Validation::uploadedFile($file, $options), 'No file should be ok.'); | ||||
| 		$options = array( | ||||
| 			'optional' => false | ||||
| 		); | ||||
| 		$this->assertFalse(Validation::uploadedFile($file, $options), 'File is required.'); | ||||
| 	} | ||||
| /** | ||||
|  * Test uploaded file validation. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testUploadedFileWithDifferentFileParametersOrder() { | ||||
| 		$file = array( | ||||
| 			'name' => 'cake.power.gif', | ||||
| 			'error' => UPLOAD_ERR_OK, | ||||
| 			'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif', | ||||
| 			'type' => 'text/plain', | ||||
| 			'size' => 201 | ||||
| 		); | ||||
| 		$options = array(); | ||||
| 		$this->assertTrue(ValidationStub::uploadedFile($file, $options), 'Wrong order'); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko