Merge branch 'master' into 2.4

This commit is contained in:
ADmad 2013-04-21 19:15:55 +05:30
commit 06a5c509c0
12 changed files with 95 additions and 32 deletions

View file

@ -153,12 +153,6 @@
*/
//Configure::write('Cache.viewPrefix', 'prefix');
/**
* Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.
*/
define('LOG_ERROR', LOG_ERR);
/**
* Session configuration.
*

View file

@ -144,12 +144,6 @@
*/
//Configure::write('Cache.viewPrefix', 'prefix');
/**
* Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.
*/
define('LOG_ERROR', LOG_ERR);
/**
* Session configuration.
*

View file

@ -723,7 +723,7 @@ class Controller extends Object implements CakeEventListener {
}
$this->uses = ($this->uses) ? (array)$this->uses : array();
if (!in_array($modelClass, $this->uses)) {
if (!in_array($modelClass, $this->uses, true)) {
$this->uses[] = $modelClass;
}

View file

@ -2588,7 +2588,7 @@ class DboSource extends DataSource {
}
if (!preg_match($operatorMatch, trim($operator))) {
$operator .= ' =';
$operator .= is_array($value) ? ' IN' : ' =';
}
$operator = trim($operator);

View file

@ -936,13 +936,21 @@ class HttpSocket extends CakeSocket {
/**
* Builds cookie headers for a request.
*
* Cookies can either be in the format returned in responses, or
* a simple key => value pair.
*
* @param array $cookies Array of cookies to send with the request.
* @return string Cookie header string to be sent with the request.
*/
public function buildCookies($cookies) {
$header = array();
foreach ($cookies as $name => $cookie) {
$header[] = $name . '=' . $this->_escapeToken($cookie['value'], array(';'));
if (is_array($cookie)) {
$value = $this->_escapeToken($cookie['value'], array(';'));
} else {
$value = $this->_escapeToken($cookie, array(';'));
}
$header[] = $name . '=' . $value;
}
return $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic');
}

View file

@ -194,7 +194,7 @@ class Router {
$routeClass !== 'CakeRoute' &&
(!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute'))
) {
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
throw new RouterException(__d('cake_dev', 'Route class not found, or route class is not a subclass of CakeRoute'));
}
return $routeClass;
}

View file

@ -447,11 +447,24 @@ class ControllerTest extends CakeTestCase {
$result = $Controller->loadModel('ControllerPost');
$this->assertTrue($result);
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
$this->assertTrue(in_array('ControllerPost', $Controller->uses));
$this->assertInstanceOf('ControllerPost', $Controller->ControllerPost);
$this->assertContains('ControllerPost', $Controller->uses);
}
ClassRegistry::flush();
unset($Controller);
/**
* Test loadModel() when uses = true.
*
* @return void
*/
public function testLoadModelUsesTrue() {
$request = new CakeRequest('controller_posts/index');
$response = $this->getMock('CakeResponse');
$Controller = new Controller($request, $response);
$Controller->uses = true;
$Controller->loadModel('ControllerPost');
$this->assertInstanceOf('ControllerPost', $Controller->ControllerPost);
$this->assertContains('ControllerPost', $Controller->uses);
}
/**

View file

@ -2446,6 +2446,11 @@ class MysqlTest extends CakeTestCase {
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$this->assertEquals($expected, $result);
$conditions = array('`Correction`.`source` collate utf8_bin' => array('kiwi', 'pear'));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE `Correction`.`source` collate utf8_bin IN ('kiwi', 'pear')";
$this->assertEquals($expected, $result);
$conditions = array('title' => 'user(s)');
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE `title` = 'user(s)'";
@ -2499,6 +2504,23 @@ class MysqlTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that array conditions with only one element work.
*
* @return
*/
public function testArrayConditionsOneElement() {
$conditions = array('id' => array(1));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE id = (1)";
$this->assertEquals($expected, $result);
$conditions = array('id NOT' => array(1));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE NOT (id = (1))";
$this->assertEquals($expected, $result);
}
/**
* testArrayConditionsParsingComplexKeys method
*

View file

@ -1674,7 +1674,9 @@ class ModelWriteTest extends BaseModelTest {
$TestModel->id = 2;
$data = array('Tag' => array('Tag' => array(2)));
$TestModel->save($data);
$result = $TestModel->save($data);
$this->assertEquals($data['Tag'], $result['Tag']);
$result = $TestModel->findById(2);
$expected = array(

View file

@ -1590,9 +1590,10 @@ class HttpSocketTest extends CakeTestCase {
'people' => array(
'value' => 'jim,jack,johnny;',
'path' => '/accounts'
)
),
'key' => 'value'
);
$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"\r\n";
$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"; key=value\r\n";
$result = $this->Socket->buildCookies($cookies);
$this->assertEquals($expect, $result);
}

View file

@ -2328,6 +2328,7 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
public function testInputTimeWithIntervalAnd12HourFormat() {
/*
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
@ -2347,6 +2348,37 @@ class FormHelperTest extends CakeTestCase {
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
*/
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 00:33:00'
));
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 13:33:00'
));
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 01:33:00'
));
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
}
/**

View file

@ -2374,6 +2374,10 @@ class FormHelper extends AppHelper {
$monthNames = $attributes['monthNames'];
$attributes = array_diff_key($attributes, $defaults);
if ($timeFormat == 12 && $hour == 12) {
$hour = 0;
}
if (!empty($interval) && $interval > 1 && !empty($min)) {
$current = new DateTime();
if ($year !== null) {
@ -2384,7 +2388,7 @@ class FormHelper extends AppHelper {
}
$change = (round($min * (1 / $interval)) * $interval) - $min;
$current->modify($change > 0 ? "+$change minutes" : "$change minutes");
$format = ($timeFormat === '12') ? 'Y m d h i a' : 'Y m d H i a';
$format = ($timeFormat == 12) ? 'Y m d h i a' : 'Y m d H i a';
$newTime = explode(' ', $current->format($format));
list($year, $month, $day, $hour, $min, $meridian) = $newTime;
}
@ -2505,15 +2509,8 @@ class FormHelper extends AppHelper {
if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
if ($time[0] >= 12 && $timeFormat == 12) {
if ($time[0] >= 12) {
$meridian = 'pm';
} elseif ($time[0] === '00' && $timeFormat == 12) {
$time[0] = 12;
} elseif ($time[0] >= 12) {
$meridian = 'pm';
}
if ($time[0] == 0 && $timeFormat == 12) {
$time[0] = 12;
}
$hour = $min = null;
if (isset($time[1])) {