From b5f918765e296245b31cca2270112c4c1311c64e Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Dec 2011 20:39:04 -0500 Subject: [PATCH 1/4] Adding docs + exceptions for name translation. Closes #2367 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 10 +++++++++- .../Case/Model/Behavior/TranslateBehaviorTest.php | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 165ed8065..5ddebb57c 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -368,7 +368,10 @@ class TranslateBehavior extends ModelBehavior { /** * Bind translation for fields, optionally with hasMany association for - * fake field + * fake field. + * + * *Note* You should avoid binding translations that overlap existing model properties. + * This can cause un-expected and un-desirable behavior. * * @param Model $model instance of model * @param string|array $fields string with field or array(field1, field2=>AssocName, field3) @@ -391,6 +394,11 @@ class TranslateBehavior extends ModelBehavior { $field = $key; $association = $value; } + if ($field === 'name') { + throw new CakeException( + __d('cake_dev', 'You cannot bind a translation named "name".') + ); + } if (array_key_exists($field, $this->settings[$model->alias])) { unset($this->settings[$model->alias][$field]); diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 8c342a5e4..89fa6a864 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -868,4 +868,16 @@ class TranslateBehaviorTest extends CakeTestCase { $this->assertFalse($result); } + +/** + * Test that an exception is raised when you try to over-write the name attribute. + * + * @expectedException CakeException + * @return void + */ + public function testExceptionOnNameTranslation() { + $this->loadFixtures('Translate', 'TranslatedItem'); + $TestModel = new TranslatedItem(); + $TestModel->bindTranslation(array('name' => 'name')); + } } From c3e9a931d6d141f03207dd7345d3daa7bb6fb95c Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Dec 2011 20:54:26 -0500 Subject: [PATCH 2/4] Should have been association name, not field name. --- lib/Cake/Model/Behavior/TranslateBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 5ddebb57c..5c2460d06 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -394,7 +394,7 @@ class TranslateBehavior extends ModelBehavior { $field = $key; $association = $value; } - if ($field === 'name') { + if ($association === 'name') { throw new CakeException( __d('cake_dev', 'You cannot bind a translation named "name".') ); From 8b9770d34dd402019245389c062acf850f4323e0 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Sat, 31 Dec 2011 14:51:24 -0800 Subject: [PATCH 3/4] Fix types in docblocks in App class --- lib/Cake/Core/App.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index ba55143a3..707b345dc 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -204,7 +204,7 @@ class App { * * @param string $type type of path * @param string $plugin name of plugin - * @return string array + * @return array * @link http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::path */ public static function path($type, $plugin = null) { @@ -361,7 +361,7 @@ class App { * `App::core('Cache/Engine'); will return the full path to the cache engines package` * * @param string $type - * @return string full path to package + * @return array full path to package * @link http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::core */ public static function core($type) { @@ -573,7 +573,7 @@ class App { * based on Inflector::underscore($name) . ".$ext"; * @param array $search paths to search for files, array('path 1', 'path 2', 'path 3'); * @param string $file full name of the file to search for including extension - * @param boolean $return, return the loaded file, the file must have a return + * @param boolean $return Return the loaded file, the file must have a return * statement in it to work: return $variable; * @return boolean true if Class is already in memory or if file is found and loaded, false if not */ From ac408b38e3dda9458795f4df7f01a59db3f78443 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Jan 2012 12:57:35 -0500 Subject: [PATCH 4/4] Add Windows Phone OS to mobile browser list. Fixes #2428 --- lib/Cake/Network/CakeRequest.php | 2 +- lib/Cake/Test/Case/Network/CakeRequestTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 6adb2842b..8793944eb 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -107,7 +107,7 @@ class CakeRequest implements ArrayAccess { 'Android', 'AvantGo', 'BlackBerry', 'DoCoMo', 'Fennec', 'iPod', 'iPhone', 'J2ME', 'MIDP', 'NetFront', 'Nokia', 'Opera Mini', 'Opera Mobi', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'SonyEricsson', 'Symbian', 'UP\\.Browser', - 'webOS', 'Windows CE', 'Xiino' + 'webOS', 'Windows CE', 'Windows Phone OS', 'Xiino' )) ); diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 33bc02d82..6104be403 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -636,6 +636,10 @@ class CakeRequestTest extends CakeTestCase { $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0b6pre) Gecko/20100902 Firefox/4.0b6pre Fennec/2.0b1pre'; $this->assertTrue($request->is('mobile')); $this->assertTrue($request->isMobile()); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)'; + $this->assertTrue($request->is('mobile')); + $this->assertTrue($request->isMobile()); } /**