From 9e143bc3351d4cf03328e7446bdd9bfa8d517ef4 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 2 Jul 2009 23:48:10 +0000 Subject: [PATCH 1/5] fixes #6473, dot notation for sort in next/prev git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8213 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/paginator.php | 13 ++++---- .../libs/view/helpers/paginator.test.php | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index f5e197a05..8dd83a144 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -140,7 +140,9 @@ class PaginatorHelper extends AppHelper { if (isset($options['sort']) && !empty($options['sort'])) { if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) { - return $result[1]; + if ($result[0] == $this->defaultModel()) { + return $result[1]; + } } return $options['sort']; } elseif (isset($options['order']) && is_array($options['order'])) { @@ -149,6 +151,7 @@ class PaginatorHelper extends AppHelper { if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) { return $result[1]; } + return $options['order']; } return null; } @@ -223,13 +226,7 @@ class PaginatorHelper extends AppHelper { } $dir = 'asc'; $sortKey = $this->sortKey($options['model']); - $defaultModel = $this->defaultModel(); - - if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) { - $isSorted = ($sortKey === $defaultModel . '.' . $key); - } else { - $isSorted = ($sortKey === $key); - } + $isSorted = ($sortKey === $key); if ($isSorted && $this->sortDir($options['model']) === 'asc') { $dir = 'desc'; diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 6939f00b5..69095f1d8 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -911,5 +911,33 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->link('Page 3', array('page' => 3)); $this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result); } + +/** + * testNextLinkUsingDotNotation method + * + * @access public + * @return void + */ + function testNextLinkUsingDotNotation() { + Router::reload(); + Router::parse('/'); + Router::setRequestInfo(array( + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), + array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) + )); + + $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); + $this->Paginator->params['paging']['Article']['page'] = 1; + + $test = array('url'=> array( + 'page'=> '1', + 'sort'=>'Article.title', + 'direction'=>'asc', + )); + $this->Paginator->options($test); + + $result = $this->Paginator->next('Next'); + $this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result); + } } -?> +?> \ No newline at end of file From 8971aad8bf87528dec994b627e0cb57de59ad6f7 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 3 Jul 2009 00:14:36 +0000 Subject: [PATCH 2/5] closes #6413, scaffoldFields not working with add/edit methods git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8214 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/scaffolds/edit.ctp | 2 +- .../cases/libs/controller/scaffold.test.php | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/scaffolds/edit.ctp b/cake/libs/view/scaffolds/edit.ctp index b9ea9a24d..fd537d239 100644 --- a/cake/libs/view/scaffolds/edit.ctp +++ b/cake/libs/view/scaffolds/edit.ctp @@ -25,7 +25,7 @@
create(); - echo $form->inputs(null, array('created', 'modified', 'updated')); + echo $form->inputs($scaffoldFields, array('created', 'modified', 'updated')); echo $form->end(__('Submit', true)); ?>
diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 78dca4ee3..d0813a419 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -47,6 +47,37 @@ class ScaffoldMockController extends Controller { */ var $scaffold; } +/** + * ScaffoldMockControllerWithFields class + * + * @package cake + * @subpackage cake.tests.cases.libs.controller + */ +class ScaffoldMockControllerWithFields extends Controller { +/** + * name property + * + * @var string 'ScaffoldMock' + * @access public + */ + var $name = 'ScaffoldMock'; +/** + * scaffold property + * + * @var mixed + * @access public + */ + var $scaffold; +/** + * function _beforeScaffold + * + * @param string method + */ + function _beforeScaffold($method) { + $this->set('scaffoldFields', array('title')); + return true; + } +} /** * TestScaffoldMock class * @@ -619,5 +650,37 @@ class ScaffoldTest extends CakeTestCase { $this->assertEqual($result['pluralVar'], 'scaffoldMock'); $this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated')); } +/** + * test that the proper names and variable values are set by Scaffold + * + * @return void + **/ + function testEditScaffoldWithScaffoldFields() { + $this->Controller = new ScaffoldMockControllerWithFields(); + $this->Controller->action = 'edit'; + $this->Controller->here = '/scaffold_mock'; + $this->Controller->webroot = '/'; + $params = array( + 'plugin' => null, + 'pass' => array(1), + 'form' => array(), + 'named' => array(), + 'url' => array('url' =>'scaffold_mock'), + 'controller' => 'scaffold_mock', + 'action' => 'edit', + ); + //set router. + Router::reload(); + Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/'))); + $this->Controller->params = $params; + $this->Controller->controller = 'scaffold_mock'; + $this->Controller->base = '/'; + $this->Controller->constructClasses(); + ob_start(); + new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + + $this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); + } } ?> \ No newline at end of file From f79a68b2a60bdec3e86c17b1c8f769bcc1a5b843 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 3 Jul 2009 00:20:54 +0000 Subject: [PATCH 3/5] Minor refactor of variable names. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8215 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/auth.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a76c877ad..a68e5b6f2 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -263,8 +263,8 @@ class AuthComponent extends Object { */ function startup(&$controller) { $methods = array_flip($controller->methods); - $controllerAction = strtolower($controller->params['action']); - $lowerAllowedActions = array_map('strtolower', $this->allowedActions); + $action = strtolower($controller->params['action']); + $allowedActions = array_map('strtolower', $this->allowedActions); $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || @@ -276,7 +276,7 @@ class AuthComponent extends Object { $isMissingAction = ( $controller->scaffold === false && - !isset($methods[$controllerAction]) + !isset($methods[$action]) ); if ($isMissingAction) { @@ -298,7 +298,7 @@ class AuthComponent extends Object { $isAllowed = ( $this->allowedActions == array('*') || - in_array($controllerAction, $lowerAllowedActions) + in_array($action, $allowedActions) ); if ($loginAction != $url && $isAllowed) { From 45a51ed80930144865fa97c27302eb4db0b738b9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 3 Jul 2009 00:26:58 +0000 Subject: [PATCH 4/5] Changing return of Model::deleteAll(). When no records are matched by the delete conditions return is now (bool)true as no records matching those conditions exist. Test case added. Fixes #6453 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8216 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/model/model.test.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 102041086..fbf2e360b 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1811,7 +1811,7 @@ class Model extends Overloadable { ); if (empty($ids)) { - return false; + return true; } if ($callbacks) { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index c8e84769f..72e1d381c 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -7487,6 +7487,9 @@ class ModelTest extends CakeTestCase { 'published' => 'Y' ))); $this->assertEqual($result, $expected); + + $result = $TestModel->deleteAll(array('Article.user_id' => 999)); + $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); } /** * testRecursiveDel method From f2b7a26be8d125fc46fb4f816ae3b0fd5e6e53bf Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 3 Jul 2009 03:31:05 +0000 Subject: [PATCH 5/5] fixes #5710, HABTM - constraining unique ids, but removing non-unique git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8217 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 5 +-- cake/tests/cases/libs/model/model.test.php | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 1aa56f73d..1ad21c115 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -858,11 +858,8 @@ class DboSource extends DataSource { foreach ($fetch as $j => $data) { if ( - (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) && - (!in_array($data[$with][$joinKeys[1]], $uniqueIds)) + (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) ) { - $uniqueIds[] = $data[$with][$joinKeys[1]]; - if ($habtmFieldsCount <= 2) { unset($data[$with]); } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 72e1d381c..01f5159dd 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -13022,5 +13022,42 @@ class ModelTest extends CakeTestCase { $TestModel2 =& new ArticleB(); $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); } +/** + * testFetchingNonUniqueFKJoinTableRecords() + * + * Tests if the results are properly returned in the case there are non-unique FK's + * in the join table but another fields value is different. For example: + * something_id | something_else_id | doomed = 1 + * something_id | something_else_id | doomed = 0 + * Should return both records and not just one. + * + * @access public + * @return void + */ + function testFetchingNonUniqueFKJoinTableRecords() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); + + $joinThingData = array( + 'JoinThing' => array( + 'something_id' => 1, + 'something_else_id' => 2, + 'doomed' => '0', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ); + $Something->JoinThing->create($joinThingData); + $Something->JoinThing->save(); + + $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); + $this->assertEqual($result[0]['JoinThing']['doomed'], 1); + $this->assertEqual($result[1]['JoinThing']['doomed'], 0); + + $result = $Something->find('first'); + $this->assertEqual(count($result['SomethingElse']), 2); + $this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1); + $this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0); + } } ?> \ No newline at end of file