Skip to content

Commit

Permalink
Merge remote-tracking branch 'cakephp/2.2' into 3.0-namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed May 27, 2012
2 parents 57a76bf + 1c0f97e commit cdadaee
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 26 deletions.
4 changes: 3 additions & 1 deletion lib/Cake/Core/App.php
Expand Up @@ -582,8 +582,10 @@ public static function load($className) {
$paths[] = $pluginPath . 'Lib' . DS . $package . DS; $paths[] = $pluginPath . 'Lib' . DS . $package . DS;
$paths[] = $pluginPath . $package . DS; $paths[] = $pluginPath . $package . DS;
} }

$normalizedClassName = str_replace('\\', DS, $className);
foreach ($paths as $path) { foreach ($paths as $path) {
$file = $path . $className . '.php'; $file = $path . $normalizedClassName . '.php';
if (file_exists($file)) { if (file_exists($file)) {
self::_map($file, $className, $plugin); self::_map($file, $className, $plugin);
return include $file; return include $file;
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Model/Datasource/Session.php
Expand Up @@ -471,6 +471,9 @@ protected static function _configureSession() {
if (!empty($sessionConfig['handler'])) { if (!empty($sessionConfig['handler'])) {
$sessionConfig['ini']['session.save_handler'] = 'user'; $sessionConfig['ini']['session.save_handler'] = 'user';
} }
if (!isset($sessionConfig['ini']['session.gc_maxlifetime'])) {
$sessionConfig['ini']['session.gc_maxlifetime'] = $sessionConfig['timeout'] * 60;
}


if (empty($_SESSION)) { if (empty($_SESSION)) {
if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) { if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Request.php
Expand Up @@ -618,7 +618,7 @@ public function method() {
/** /**
* Get the host that the request was handled on. * Get the host that the request was handled on.
* *
* @return void * @return string
*/ */
public function host() { public function host() {
return env('HTTP_HOST'); return env('HTTP_HOST');
Expand Down
Expand Up @@ -402,7 +402,6 @@ public function testExtractModelValidationInPlugin() {
$this->assertNotRegExp($pattern, $result); $this->assertNotRegExp($pattern, $result);
} }



/** /**
* Test that the extract shell overwrites existing files with the overwrite parameter * Test that the extract shell overwrites existing files with the overwrite parameter
* *
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -315,7 +315,7 @@ public function testInteractiveFieldValidation() {
$this->Task->initValidations(); $this->Task->initValidations();
$this->Task->interactive = true; $this->Task->interactive = true;
$this->Task->expects($this->any())->method('in') $this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('21', 'y', '17', 'n')); ->will($this->onConsecutiveCalls('22', 'y', '17', 'n'));


$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength'); $expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
Expand All @@ -333,7 +333,7 @@ public function testInteractiveFieldValidationWithBogusResponse() {
$this->Task->interactive = true; $this->Task->interactive = true;


$this->Task->expects($this->any())->method('in') $this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('999999', '21', 'n')); ->will($this->onConsecutiveCalls('999999', '22', 'n'));


$this->Task->expects($this->at(7))->method('out') $this->Task->expects($this->at(7))->method('out')
->with($this->stringContains('make a valid')); ->with($this->stringContains('make a valid'));
Expand Down
Expand Up @@ -55,15 +55,6 @@ public function setUp() {
$this->response = $this->getMock('Cake\Network\Response'); $this->response = $this->getMock('Cake\Network\Response');
} }


/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
}

/** /**
* test applying settings in the constructor * test applying settings in the constructor
* *
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Test/TestCase/Model/Datasource/CakeSessionTest.php
Expand Up @@ -737,6 +737,8 @@ public function testCookieTimeoutFallback() {
TestCakeSession::start(); TestCakeSession::start();
$this->assertEquals(400, Configure::read('Session.cookieTimeout')); $this->assertEquals(400, Configure::read('Session.cookieTimeout'));
$this->assertEquals(400, Configure::read('Session.timeout')); $this->assertEquals(400, Configure::read('Session.timeout'));
$this->assertEquals(400 * 60, ini_get('session.cookie_lifetime'));
$this->assertEquals(400 * 60, ini_get('session.gc_maxlifetime'));


$_SESSION = null; $_SESSION = null;
Configure::write('Session', array( Configure::write('Session', array(
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/TestCase/Model/ModelWriteTest.php
Expand Up @@ -241,7 +241,7 @@ public function testCacheClearOnSave() {
$data = array( $data = array(
'OverallFavorite' => array( 'OverallFavorite' => array(
'id' => 22, 'id' => 22,
'model_type' => '8-track', 'model_type' => '8-track',
'model_id' => '3', 'model_id' => '3',
'priority' => '1' 'priority' => '1'
) )
Expand Down
Expand Up @@ -26,15 +26,6 @@
*/ */
class CakeValidationSetTest extends CakeTestCase { class CakeValidationSetTest extends CakeTestCase {


/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
}

/** /**
* testValidate method * testValidate method
* *
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/TestCase/Utility/SetTest.php
Expand Up @@ -1617,6 +1617,20 @@ public function testClassicExtract() {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }


/**
* test classicExtract with keys that exceed 32bit max int.
*
* @return void
*/
public function testClassicExtractMaxInt() {
$data = array(
'Data' => array(
'13376924712' => 'abc'
)
);
$this->assertEquals('abc', Set::classicExtract($data, 'Data.13376924712'));
}

/** /**
* testInsert method * testInsert method
* *
Expand Down
21 changes: 21 additions & 0 deletions lib/Cake/Test/TestCase/Utility/ValidationTest.php
Expand Up @@ -1963,6 +1963,27 @@ public function testNumeric() {
$this->assertTrue(Validation::numeric('2.2')); $this->assertTrue(Validation::numeric('2.2'));
} }


/**
* testNaturalNumber method
*
* @return void
*/
public function testNaturalNumber() {
$this->assertFalse(Validation::naturalNumber('teststring'));
$this->assertFalse(Validation::naturalNumber('5.4'));
$this->assertFalse(Validation::naturalNumber(99.004));
$this->assertFalse(Validation::naturalNumber('0,05'));
$this->assertFalse(Validation::naturalNumber('-2'));
$this->assertFalse(Validation::naturalNumber(-2));
$this->assertFalse(Validation::naturalNumber('0'));
$this->assertFalse(Validation::naturalNumber('050'));

$this->assertTrue(Validation::naturalNumber('2'));
$this->assertTrue(Validation::naturalNumber(49));
$this->assertTrue(Validation::naturalNumber('0', true));
$this->assertTrue(Validation::naturalNumber(0, true));
}

/** /**
* testPhone method * testPhone method
* *
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/Set.php
Expand Up @@ -562,8 +562,8 @@ public static function classicExtract($data, $path = null) {


foreach ($path as $i => $key) { foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key === '0') { if (is_numeric($key) && intval($key) > 0 || $key === '0') {
if (isset($data[intval($key)])) { if (isset($data[$key])) {
$data = $data[intval($key)]; $data = $data[$key];
} else { } else {
return null; return null;
} }
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -564,6 +564,19 @@ public static function numeric($check) {
return is_numeric($check); return is_numeric($check);
} }


/**
* Checks if a value is a natural number.
*
* @param string $check Value to check
* @param boolean $allowZero Set true to allow zero, defaults to false
* @return boolean Success
* @see http://en.wikipedia.org/wiki/Natural_number
*/
public static function naturalNumber($check, $allowZero = false) {
$regex = $allowZero ? '/^(?:0|[1-9][0-9]*)$/' : '/^[1-9][0-9]*$/';
return self::_check($check, $regex);
}

/** /**
* Check that a value is a valid phone number. * Check that a value is a valid phone number.
* *
Expand Down

0 comments on commit cdadaee

Please sign in to comment.