Skip to content

Commit

Permalink
Merge branch '1.3' into 1.3-1679
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed May 19, 2011
2 parents 5329c18 + 548f09c commit 104f6a5
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/config/core.php
Expand Up @@ -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
* ));
*
*/
Expand Down
3 changes: 3 additions & 0 deletions cake/console/libs/tasks/model.php
Expand Up @@ -353,6 +353,7 @@ function initValidations() {
$default++;
}
}
$choices[$default] = 'none'; // Needed since index starts at 1
$this->_validations = $choices;
return $choices;
}
Expand Down Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions cake/console/templates/skel/config/core.php
Expand Up @@ -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
* ));
*
*/
Expand Down
12 changes: 12 additions & 0 deletions cake/libs/cache.php
Expand Up @@ -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();
}
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions cake/libs/cache/memcache.php
Expand Up @@ -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)
);

Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/components/auth.php
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions cake/libs/view/helpers/form.php
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/view.php
Expand Up @@ -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;
}
Expand Down
12 changes: 11 additions & 1 deletion cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion cake/tests/cases/libs/cache/memcache.test.php
Expand Up @@ -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);
}
Expand Down
43 changes: 43 additions & 0 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -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
*
Expand Down
21 changes: 18 additions & 3 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 104f6a5

Please sign in to comment.