From d01d291d13c8c4aed4a63b79525bafe905ad9a98 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 16 Apr 2013 12:32:00 -0400 Subject: [PATCH 01/10] Remove unused define. The LOG_ERROR constant is no longer used by the logging system. It is an unused relic from 1.x. Additionally changing the value of ERROR to not be error creates counterintuitive code. Fixes #3762 --- app/Config/core.php | 6 ------ lib/Cake/Console/Templates/skel/Config/core.php | 6 ------ 2 files changed, 12 deletions(-) diff --git a/app/Config/core.php b/app/Config/core.php index c705ece8a..df16a8b98 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -150,12 +150,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. * diff --git a/lib/Cake/Console/Templates/skel/Config/core.php b/lib/Cake/Console/Templates/skel/Config/core.php index c705ece8a..df16a8b98 100644 --- a/lib/Cake/Console/Templates/skel/Config/core.php +++ b/lib/Cake/Console/Templates/skel/Config/core.php @@ -150,12 +150,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. * From 4d8dd124491d1f16b4dd3ad056a2acd760b31f4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 18 Apr 2013 21:22:50 -0400 Subject: [PATCH 02/10] Add support for key => value cookies. This makes using simple arrays easier, and I feel it is a long standing omission from HttpSocket. Fixes #3771 --- lib/Cake/Network/Http/HttpSocket.php | 7 ++++++- lib/Cake/Test/Case/Network/Http/HttpSocketTest.php | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index e8a36ba9b..ebebad62c 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -942,7 +942,12 @@ class HttpSocket extends CakeSocket { 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'); } diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index b1ffa5c84..88d07e315 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -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); } From 3680ee0f1f681398713e93805745aa049ccf109b Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 18 Apr 2013 21:23:40 -0400 Subject: [PATCH 03/10] Add some docs for cookies. --- lib/Cake/Network/Http/HttpSocket.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index ebebad62c..5ffd4f8cd 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -936,6 +936,9 @@ 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. */ From 0f3d28c6ea968ca07921c5877b18d8e2ca88a620 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 18 Apr 2013 21:52:22 -0400 Subject: [PATCH 04/10] Fix condition parsing in mysql specific cases. When using collation + array values the incorrect operator would be used. IN should be used over =. Fixes #3772 --- lib/Cake/Model/Datasource/DboSource.php | 2 +- .../Model/Datasource/Database/MysqlTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 48282118d..f9b1a109c 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2588,7 +2588,7 @@ class DboSource extends DataSource { } if (!preg_match($operatorMatch, trim($operator))) { - $operator .= ' ='; + $operator .= is_array($value) ? ' IN' : ' ='; } $operator = trim($operator); diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 3ac46ef5a..7b60b649d 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -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 * From 63b392a26b2b4fc8d0936ad432491a273fc79dd7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 19 Apr 2013 12:13:58 -0400 Subject: [PATCH 05/10] Improve error message. One of the cases was not explained in the existing error message. Fixes #3773 --- lib/Cake/Routing/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 20f374f72..740a439f3 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -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; } From efd86a498afc19ada7ff01a2ee90cab7a5d3bbf3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 19 Apr 2013 12:16:18 -0400 Subject: [PATCH 06/10] Do type checks when looking for models in Controller::$uses. This solves issues with models not being added when $uses = true. Fixes #3774 --- lib/Cake/Controller/Controller.php | 2 +- .../Test/Case/Controller/ControllerTest.php | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 0e4ba7384..e279be969 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -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; } diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index 9e2d1619e..74b1d31c0 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -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); } /** From 842b1802d99344f6ce0b0182b1a5b39dd2a5f551 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 19 Apr 2013 19:37:23 +0200 Subject: [PATCH 07/10] add assert that habtm save does not return false --- lib/Cake/Test/Case/Model/ModelWriteTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index e69a9de8a..46ddd8a34 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -1652,7 +1652,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( From 78ea4da6816b041f04c784cd93326336a246ec70 Mon Sep 17 00:00:00 2001 From: Majna Date: Sat, 20 Apr 2013 17:51:50 +0200 Subject: [PATCH 08/10] Add test for time input with interval on first hour of the day --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 185f6b863..c566a7b2b 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2347,6 +2347,16 @@ class FormHelperTest extends CakeTestCase { $this->assertContains('', $result); $this->assertContains('', $result); $this->assertContains('', $result); + + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'timeFormat' => '12', + 'interval' => 10, + 'selected' => '2013-05-19 00:33:00' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); } /** From f6c30157050e6db3d05059b1e09bc0d66b6fd253 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Apr 2013 14:39:47 -0400 Subject: [PATCH 09/10] Add additional tests and fix incorrect meridian selection When dates around midnight were used with interval + 12hr formats, the incorrect meridian was selected. Refs #GH-1237 --- .../Test/Case/View/Helper/FormHelperTest.php | 22 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index c566a7b2b..c07c85838 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -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,7 @@ class FormHelperTest extends CakeTestCase { $this->assertContains('', $result); $this->assertContains('', $result); $this->assertContains('', $result); + */ $result = $this->Form->input('Model.start_time', array( 'type' => 'time', @@ -2357,6 +2359,26 @@ class FormHelperTest extends CakeTestCase { $this->assertContains('', $result); $this->assertContains('', $result); $this->assertContains('', $result); + + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'timeFormat' => '12', + 'interval' => 10, + 'selected' => '2013-05-19 13:33:00' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'timeFormat' => '12', + 'interval' => 10, + 'selected' => '2013-05-19 01:33:00' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 2711dd5c7..81014e047 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2380,11 +2380,12 @@ class FormHelper extends AppHelper { $current->setDate($year, $month, $day); } if ($hour !== null) { + $hour = $timeFormat == 12 && $hour == 12 ? 0 : $hour; $current->setTime($hour, $min); } $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,6 +2506,7 @@ class FormHelper extends AppHelper { if (!empty($timeFormat)) { $time = explode(':', $days[1]); + // TODO this code is stupid. if ($time[0] >= 12 && $timeFormat == 12) { $meridian = 'pm'; } elseif ($time[0] === '00' && $timeFormat == 12) { From 64da4e75c439680af6baa66ec340ee02c26a295a Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Apr 2013 14:48:54 -0400 Subject: [PATCH 10/10] Remove silly code. Changing the 12'th hour into 0 shouldn't be done when figuring out the meridian, it makes sorting things out later more complicated. Remove some duplicated code. --- lib/Cake/View/Helper/FormHelper.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 81014e047..c50a4fd36 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2374,13 +2374,16 @@ 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) { $current->setDate($year, $month, $day); } if ($hour !== null) { - $hour = $timeFormat == 12 && $hour == 12 ? 0 : $hour; $current->setTime($hour, $min); } $change = (round($min * (1 / $interval)) * $interval) - $min; @@ -2506,16 +2509,8 @@ class FormHelper extends AppHelper { if (!empty($timeFormat)) { $time = explode(':', $days[1]); - // TODO this code is stupid. - 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])) {