Permalink
Browse files

Merge branch '1.3' into 1.3-1679

  • Loading branch information...
2 parents 5329c18 + 548f09c commit 104f6a52fd49f23bbe4aca80a62fc0626323ec2f @ceeram ceeram committed May 19, 2011
View
@@ -297,6 +297,7 @@
* '127.0.0.1:11211' // localhost, default port 11211
* ), //[optional]
* 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
+ * 'persistent' => true, // [optional] set this to false for non-persistent connections
* ));
*
*/
@@ -353,6 +353,7 @@ function initValidations() {
$default++;
}
}
+ $choices[$default] = 'none'; // Needed since index starts at 1
$this->_validations = $choices;
return $choices;
}
@@ -391,6 +392,8 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
if ($fieldName == 'email') {
$guess = $methods['email'];
+ } elseif ($metaData['type'] == 'string' && $metaData['length'] == 36) {
+ $guess = $methods['uuid'];
} elseif ($metaData['type'] == 'string') {
$guess = $methods['notempty'];
} elseif ($metaData['type'] == 'integer') {
@@ -297,6 +297,7 @@
* '127.0.0.1:11211' // localhost, default port 11211
* ), //[optional]
* 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
+ * 'persistent' => true, // [optional] set this to false for non-persistent connections
* ));
*
*/
View
@@ -548,6 +548,18 @@ function settings($name = null) {
}
return array();
}
+
+/**
+ * Write the session when session data is persisted with cache.
+ *
+ * @return void
+ * @access public
+ */
+ function __destruct() {
+ if (Configure::read('Session.save') == 'cache' && function_exists('session_write_close')) {
+ session_write_close();
+ }
+ }
}
/**
@@ -67,7 +67,8 @@ function init($settings = array()) {
'engine'=> 'Memcache',
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array('127.0.0.1'),
- 'compress'=> false
+ 'compress'=> false,
+ 'persistent' => true
), $settings)
);
@@ -82,7 +83,7 @@ function init($settings = array()) {
$this->__Memcache =& new Memcache();
foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server);
- if ($this->__Memcache->addServer($host, $port)) {
+ if ($this->__Memcache->addServer($host, $port, $this->settings['persistent'])) {
$return = true;
}
}
@@ -841,7 +841,7 @@ function &getModel($name = null) {
*/
function identify($user = null, $conditions = null) {
if ($conditions === false) {
- $conditions = null;
+ $conditions = array();
} elseif (is_array($conditions)) {
$conditions = array_merge((array)$this->userScope, $conditions);
} else {
@@ -1832,9 +1832,8 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
- $check = str_replace(':', '', $days[1]);
- if (($check > 115959) && $timeFormat == '12') {
+ if (($time[0] > 12) && $timeFormat == '12') {
$time[0] = $time[0] - 12;
$meridian = 'pm';
} elseif ($time[0] == '00' && $timeFormat == '12') {
View
@@ -489,7 +489,7 @@ function renderLayout($content_for_layout, $layout = null) {
$this->output = $this->_render($layoutFileName, $dataForLayout, $loadHelpers, true);
if ($this->output === false) {
- $this->output = $this->_render($layoutFileName, $data_for_layout);
+ $this->output = $this->_render($layoutFileName, $dataForLayout);
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layoutFileName, $this->output), E_USER_ERROR);
return false;
}
@@ -197,21 +197,31 @@ function testFieldValidationGuessing() {
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('notempty' => 'notempty');
+ $this->assertEqual($expected, $result);
$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
$expected = array('date' => 'date');
+ $this->assertEqual($expected, $result);
$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
$expected = array('time' => 'time');
+ $this->assertEqual($expected, $result);
$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('email' => 'email');
+ $this->assertEqual($expected, $result);
$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
$expected = array('numeric' => 'numeric');
+ $this->assertEqual($expected, $result);
$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
- $expected = array('numeric' => 'numeric');
+ $expected = array('boolean' => 'boolean');
+ $this->assertEqual($expected, $result);
+
+ $result = $this->Task->fieldValidation('test', array('type' => 'string', 'length' => 36, 'null' => false));
+ $expected = array('uuid' => 'uuid');
+ $this->assertEqual($expected, $result);
}
/**
@@ -106,7 +106,8 @@ function testSettings() {
'probability' => 100,
'servers' => array('127.0.0.1'),
'compress' => false,
- 'engine' => 'Memcache'
+ 'engine' => 'Memcache',
+ 'persistent' => true,
);
$this->assertEqual($settings, $expecting);
}
@@ -552,6 +552,49 @@ function testIsErrorOrTests() {
$this->assertFalse($this->Controller->Auth->startup($this->Controller));
}
+/**
+ * testIdentify method
+ *
+ * @access public
+ * @return void
+ */
+ function testIdentify() {
+ $this->AuthUser =& new AuthUser();
+ $user['id'] = 1;
+ $user['username'] = 'mariano';
+ $user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
+ $this->AuthUser->save($user, false);
+
+ $this->Controller->Auth->initialize($this->Controller);
+ $this->Controller->Auth->userModel = 'AuthUser';
+ $this->Controller->Auth->startup($this->Controller);
+ $this->assertTrue($this->Controller->Auth->identify($user));
+ }
+
+/**
+ * testIdentifyWithConditions method
+ *
+ * @access public
+ * @return void
+ */
+ function testIdentifyWithConditions() {
+ $this->AuthUser =& new AuthUser();
+ $user['id'] = 1;
+ $user['username'] = 'mariano';
+ $user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
+ $this->AuthUser->save($user, false);
+
+ $this->Controller->Auth->initialize($this->Controller);
+ $this->Controller->Auth->startup($this->Controller);
+ $this->Controller->Auth->userModel = 'AuthUser';
+
+ $this->assertFalse($this->Controller->Auth->identify($user, array('AuthUser.id >' => 2)));
+
+ $this->Controller->Auth->userScope = array('id >' => 2);
+ $this->assertFalse($this->Controller->Auth->identify($user));
+ $this->assertTrue($this->Controller->Auth->identify($user, false));
+ }
+
/**
* testLogin method
*
@@ -1887,11 +1887,10 @@ function testInputCheckbox() {
}
/**
- * test form->input() with datetime, date and time types
+ * test form->input() with time types.
*
- * @return void
*/
- function testInputDatetime() {
+ function testInputTime() {
extract($this->dateRegex);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
@@ -1929,6 +1928,22 @@ function testInputDatetime() {
$this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
$this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
+ $result = $this->Form->input('Random.start_time', array(
+ 'type' => 'time',
+ 'selected' => '18:15'
+ ));
+ $this->assertPattern('#<option value="06"[^>]*>6</option>#', $result);
+ $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result);
+ $this->assertPattern('#<option value="pm"[^>]*>pm</option>#', $result);
+ }
+
+/**
+ * test form->input() with datetime, date and time types
+ *
+ * @return void
+ */
+ function testInputDatetime() {
+ extract($this->dateRegex);
$result = $this->Form->input('prueba', array(
'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
'maxYear' => date('Y') + 1 ,'interval' => 15

0 comments on commit 104f6a5

Please sign in to comment.