From 18be1418cde865210dcb6fa52b7be1720880b6c5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 17:32:29 -0400 Subject: [PATCH 01/49] Adding ability to inject an ajax provider class into paginator helper. updating tests. --- cake/libs/view/helpers/paginator.php | 26 +++++++++++++++++-- .../libs/view/helpers/paginator.test.php | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index fae687ae6..33afa5beb 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -33,7 +33,7 @@ class PaginatorHelper extends AppHelper { * * @var array */ - var $helpers = array('Html', 'Ajax'); + var $helpers = array('Html'); /** * Holds the default model for paged recordsets @@ -42,6 +42,13 @@ class PaginatorHelper extends AppHelper { */ var $__defaultModel = null; +/** + * The class used for 'Ajax' pagination links. + * + * @var string + **/ + var $_ajaxHelperClass = 'Js'; + /** * Holds the default options for pagination links * @@ -66,6 +73,21 @@ class PaginatorHelper extends AppHelper { */ var $options = array(); +/** + * Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links. + * + * Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper + * or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its + * adapter before including PaginatorHelper in your helpers array. + * + * @return void + **/ + function __construct($config = array()) { + $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; + $this->helpers[] = $ajaxProvider; + $this->_ajaxHelperClass = $ajaxProvider; + } + /** * Gets the current paging parameters from the resultset for the given model * @@ -271,7 +293,7 @@ class PaginatorHelper extends AppHelper { } $url = $this->url($url, true, $model); - $obj = isset($options['update']) ? 'Ajax' : 'Html'; + $obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html'; $url = array_merge(array('page' => $this->current($model)), $url); $url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true))); return $this->{$obj}->link($title, $url, $options); diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 329328ae8..857e7a1d4 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -42,7 +42,7 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ function setUp() { - $this->Paginator = new PaginatorHelper(); + $this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax')); $this->Paginator->params['paging'] = array( 'Article' => array( 'current' => 9, From 48e0e951ec439e14245606c9922100b5d1b471a9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 17:53:18 -0400 Subject: [PATCH 02/49] Adding tests to test arbitrary class injection. --- .../libs/view/helpers/paginator.test.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 857e7a1d4..4f958bf44 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -25,7 +25,9 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript')); +App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript', 'Js')); + +Mock::generate('JsHelper', 'PaginatorMockJsHelper'); /** * PaginatorHelperTest class @@ -1613,5 +1615,28 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); } + +/** + * test that mock classes injected into paginatorHelper are called when using link() + * + * @return void + **/ + function testMockAjaxProviderClassInjection() { + $Paginator =& new PaginatorHelper(array('ajax' => 'PaginatorMockJs')); + $Paginator->params['paging'] = array( + 'Article' => array( + 'current' => 9, + 'count' => 62, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 7, + 'defaults' => array(), + 'options' => array() + ) + ); + $Paginator->PaginatorMockJs =& new PaginatorMockJsHelper(); + $Paginator->PaginatorMockJs->expectOnce('link'); + $result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); + } } ?> \ No newline at end of file From 4e6aa35155b0756cbd23e1deb802535739025823 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 19:51:11 -0400 Subject: [PATCH 03/49] Adding warning errors when an incompatible class is used. --- cake/libs/view/helpers/paginator.php | 9 +++++++++ cake/tests/cases/libs/view/helpers/paginator.test.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 33afa5beb..a6872faa8 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -80,12 +80,21 @@ class PaginatorHelper extends AppHelper { * or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its * adapter before including PaginatorHelper in your helpers array. * + * The chosen custom helper must implement a `link()` method. + * * @return void **/ function __construct($config = array()) { $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; $this->helpers[] = $ajaxProvider; $this->_ajaxHelperClass = $ajaxProvider; + if (!method_exists($ajaxProvider . 'Helper', 'link')) { + $message = sprintf( + __('%s does not implement a link() method, it is incompatible with PaginatorHelper', true), + $ajaxProvider . 'Helper' + ); + trigger_error($message, E_USER_WARNING); + } } /** diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 4f958bf44..c197f1f95 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -1637,6 +1637,9 @@ class PaginatorHelperTest extends CakeTestCase { $Paginator->PaginatorMockJs =& new PaginatorMockJsHelper(); $Paginator->PaginatorMockJs->expectOnce('link'); $result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); + + $this->expectError(); + $Paginator =& new PaginatorHelper(array('ajax' => 'Form')); } } ?> \ No newline at end of file From 856392e916474c11f439964b500ed67cea81b2f8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 20:51:59 -0400 Subject: [PATCH 04/49] Fixing method dispatching errors in JsHelper with regards to Object::object, and PHP4 workarounds. --- cake/libs/view/helpers/js.php | 16 +++++++++++++++- cake/tests/cases/libs/view/helpers/js.test.php | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index a44f2bb1d..3073e7287 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -115,7 +115,7 @@ class JsHelper extends AppHelper { * @param string $method Method to be called * @param array $params Parameters for the method being called. * @access public - * @return mixed + * @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper **/ function call__($method, $params) { if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) { @@ -150,6 +150,20 @@ class JsHelper extends AppHelper { trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING); } +/** + * Workaround for Object::Object() existing. Since Object::object exists, it does not + * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for + * more information on this method. + * + * @param mixed $data Data to convert into JSON + * @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details. + * @return string encoded JSON + * @deprecated Remove when support for PHP4 and Object::object are removed. + **/ + function object($data = array(), $options = array()) { + return $this->{$this->__engineName}->object($data, $options); + } + /** * Writes all Javascript generated so far to a code block or * caches them to a file and returns a linked script. diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index ee87727bf..6dd5bce15 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -415,6 +415,17 @@ CODE; ); $this->assertTags($result, $expected); } + +/** + * Test that Object::Object() is not breaking json output in JsHelper + * + * @return void + **/ + function testObjectPassThrough() { + $result = $this->Js->object(array('one' => 'first', 'two' => 'second')); + $expected = '{"one":"first","two":"second"}'; + $this->assertEqual($result, $expected); + } } From 6b575673f7a42c38e73bd52d80507f40306f6bc6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 11 Aug 2009 23:33:41 -0400 Subject: [PATCH 05/49] Updating doc block. --- cake/libs/view/helpers/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 3073e7287..5b2a61ff6 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -215,7 +215,7 @@ class JsHelper extends AppHelper { /** * Get all the cached scripts * - * @param boolean $clear Whether or not to clear the script caches + * @param boolean $clear Whether or not to clear the script caches (default true) * @return array Array of scripts added to the request. **/ function getBuffer($clear = true) { From c02a8faebd85381bfa61eb6f24db0c7c0ab31369 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Aug 2009 09:24:23 -0400 Subject: [PATCH 06/49] Applying patch from 'evilbloodydemon'. Fixes JqueryEngine::request() when wrapCallbacks is true. Test cases added. Fixes #20 --- cake/libs/view/helpers/jquery_engine.php | 8 +++++++- .../cases/libs/view/helpers/jquery_engine.test.php | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index 476327b91..407eca62b 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -240,7 +240,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } $options['url'] = $url; if (isset($options['update'])) { - $options['success'] = 'function (msg, status) {$("' . $options['update'] . '").html(msg);}'; + $wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true; + if ($wrapCallbacks) { + $success = '$("' . $options['update'] . '").html(data);'; + } else { + $success = 'function (data, textStatus) {$("' . $options['update'] . '").html(data);}'; + } + $options['success'] = $success; unset($options['update']); } $callbacks = array('success', 'error', 'beforeSend', 'complete'); diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 65194a7df..0313f23d5 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -160,6 +160,12 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $expected = '$.ajax({url:"\\/posts\\/view\\/1"});'; $this->assertEqual($result, $expected); + $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( + 'update' => '#content' + )); + $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; + $this->assertEqual($result, $expected); + $result = $this->Jquery->request('/people/edit/1', array( 'method' => 'post', 'before' => 'doBefore', @@ -179,7 +185,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase { 'method' => 'post', 'wrapCallbacks' => false )); - $expected = '$.ajax({success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});'; + $expected = '$.ajax({success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});'; $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( @@ -190,7 +196,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase { 'data' => '$("#someId").serialize()', 'wrapCallbacks' => false )); - $expected = '$.ajax({data:$("#someId").serialize(), success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});'; + $expected = '$.ajax({data:$("#someId").serialize(), success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});'; $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( From abdcfcb5e8d5173223561e32071e75587646399e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Aug 2009 09:27:01 -0400 Subject: [PATCH 07/49] Fixing whitespace. --- .../cases/libs/view/helpers/jquery_engine.test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 0313f23d5..23d237cb0 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -160,11 +160,11 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $expected = '$.ajax({url:"\\/posts\\/view\\/1"});'; $this->assertEqual($result, $expected); - $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( - 'update' => '#content' - )); - $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; - $this->assertEqual($result, $expected); + $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( + 'update' => '#content' + )); + $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; + $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( 'method' => 'post', From b1a27b1760e3972a67dbe153c040f1eec663266d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 17:32:29 -0400 Subject: [PATCH 08/49] Adding ability to inject an ajax provider class into paginator helper. updating tests. --- cake/libs/view/helpers/paginator.php | 26 +++++++++++++++++-- .../libs/view/helpers/paginator.test.php | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index fae687ae6..33afa5beb 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -33,7 +33,7 @@ class PaginatorHelper extends AppHelper { * * @var array */ - var $helpers = array('Html', 'Ajax'); + var $helpers = array('Html'); /** * Holds the default model for paged recordsets @@ -42,6 +42,13 @@ class PaginatorHelper extends AppHelper { */ var $__defaultModel = null; +/** + * The class used for 'Ajax' pagination links. + * + * @var string + **/ + var $_ajaxHelperClass = 'Js'; + /** * Holds the default options for pagination links * @@ -66,6 +73,21 @@ class PaginatorHelper extends AppHelper { */ var $options = array(); +/** + * Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links. + * + * Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper + * or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its + * adapter before including PaginatorHelper in your helpers array. + * + * @return void + **/ + function __construct($config = array()) { + $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; + $this->helpers[] = $ajaxProvider; + $this->_ajaxHelperClass = $ajaxProvider; + } + /** * Gets the current paging parameters from the resultset for the given model * @@ -271,7 +293,7 @@ class PaginatorHelper extends AppHelper { } $url = $this->url($url, true, $model); - $obj = isset($options['update']) ? 'Ajax' : 'Html'; + $obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html'; $url = array_merge(array('page' => $this->current($model)), $url); $url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true))); return $this->{$obj}->link($title, $url, $options); diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 66904a2b1..6e2751bd9 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -42,7 +42,7 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ function setUp() { - $this->Paginator = new PaginatorHelper(); + $this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax')); $this->Paginator->params['paging'] = array( 'Article' => array( 'current' => 9, From 29881561d356fa22fee0dea800ad767d5b98eea4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 17:53:18 -0400 Subject: [PATCH 09/49] Adding tests to test arbitrary class injection. --- .../libs/view/helpers/paginator.test.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 6e2751bd9..20fb2842e 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -25,7 +25,9 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript')); +App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript', 'Js')); + +Mock::generate('JsHelper', 'PaginatorMockJsHelper'); /** * PaginatorHelperTest class @@ -1613,5 +1615,28 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); } + +/** + * test that mock classes injected into paginatorHelper are called when using link() + * + * @return void + **/ + function testMockAjaxProviderClassInjection() { + $Paginator =& new PaginatorHelper(array('ajax' => 'PaginatorMockJs')); + $Paginator->params['paging'] = array( + 'Article' => array( + 'current' => 9, + 'count' => 62, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 7, + 'defaults' => array(), + 'options' => array() + ) + ); + $Paginator->PaginatorMockJs =& new PaginatorMockJsHelper(); + $Paginator->PaginatorMockJs->expectOnce('link'); + $result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); + } } ?> \ No newline at end of file From a7e300a7c1c90bc64c7e85ce62732458c22befa7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 19:51:11 -0400 Subject: [PATCH 10/49] Adding warning errors when an incompatible class is used. --- cake/libs/view/helpers/paginator.php | 9 +++++++++ cake/tests/cases/libs/view/helpers/paginator.test.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 33afa5beb..a6872faa8 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -80,12 +80,21 @@ class PaginatorHelper extends AppHelper { * or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its * adapter before including PaginatorHelper in your helpers array. * + * The chosen custom helper must implement a `link()` method. + * * @return void **/ function __construct($config = array()) { $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; $this->helpers[] = $ajaxProvider; $this->_ajaxHelperClass = $ajaxProvider; + if (!method_exists($ajaxProvider . 'Helper', 'link')) { + $message = sprintf( + __('%s does not implement a link() method, it is incompatible with PaginatorHelper', true), + $ajaxProvider . 'Helper' + ); + trigger_error($message, E_USER_WARNING); + } } /** diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 20fb2842e..e7aa382c2 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -1637,6 +1637,9 @@ class PaginatorHelperTest extends CakeTestCase { $Paginator->PaginatorMockJs =& new PaginatorMockJsHelper(); $Paginator->PaginatorMockJs->expectOnce('link'); $result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); + + $this->expectError(); + $Paginator =& new PaginatorHelper(array('ajax' => 'Form')); } } ?> \ No newline at end of file From 08f0c7c1577b537f9c11f2d02b79d6ef7c521c0d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Aug 2009 20:51:59 -0400 Subject: [PATCH 11/49] Fixing method dispatching errors in JsHelper with regards to Object::object, and PHP4 workarounds. --- cake/libs/view/helpers/js.php | 16 +++++++++++++++- cake/tests/cases/libs/view/helpers/js.test.php | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index a44f2bb1d..3073e7287 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -115,7 +115,7 @@ class JsHelper extends AppHelper { * @param string $method Method to be called * @param array $params Parameters for the method being called. * @access public - * @return mixed + * @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper **/ function call__($method, $params) { if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) { @@ -150,6 +150,20 @@ class JsHelper extends AppHelper { trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING); } +/** + * Workaround for Object::Object() existing. Since Object::object exists, it does not + * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for + * more information on this method. + * + * @param mixed $data Data to convert into JSON + * @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details. + * @return string encoded JSON + * @deprecated Remove when support for PHP4 and Object::object are removed. + **/ + function object($data = array(), $options = array()) { + return $this->{$this->__engineName}->object($data, $options); + } + /** * Writes all Javascript generated so far to a code block or * caches them to a file and returns a linked script. diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index ee87727bf..6dd5bce15 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -415,6 +415,17 @@ CODE; ); $this->assertTags($result, $expected); } + +/** + * Test that Object::Object() is not breaking json output in JsHelper + * + * @return void + **/ + function testObjectPassThrough() { + $result = $this->Js->object(array('one' => 'first', 'two' => 'second')); + $expected = '{"one":"first","two":"second"}'; + $this->assertEqual($result, $expected); + } } From 4b88ba5f9d5179df7f9dc8bfe4cc1f4514e14ca2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 11 Aug 2009 23:33:41 -0400 Subject: [PATCH 12/49] Updating doc block. --- cake/libs/view/helpers/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 3073e7287..5b2a61ff6 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -215,7 +215,7 @@ class JsHelper extends AppHelper { /** * Get all the cached scripts * - * @param boolean $clear Whether or not to clear the script caches + * @param boolean $clear Whether or not to clear the script caches (default true) * @return array Array of scripts added to the request. **/ function getBuffer($clear = true) { From 459fcb7a1a0b229efe627c7772aa7c0b96d0c4b7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Aug 2009 09:24:23 -0400 Subject: [PATCH 13/49] Applying patch from 'evilbloodydemon'. Fixes JqueryEngine::request() when wrapCallbacks is true. Test cases added. Fixes #20 --- cake/libs/view/helpers/jquery_engine.php | 8 +++++++- .../cases/libs/view/helpers/jquery_engine.test.php | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index 476327b91..407eca62b 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -240,7 +240,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } $options['url'] = $url; if (isset($options['update'])) { - $options['success'] = 'function (msg, status) {$("' . $options['update'] . '").html(msg);}'; + $wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true; + if ($wrapCallbacks) { + $success = '$("' . $options['update'] . '").html(data);'; + } else { + $success = 'function (data, textStatus) {$("' . $options['update'] . '").html(data);}'; + } + $options['success'] = $success; unset($options['update']); } $callbacks = array('success', 'error', 'beforeSend', 'complete'); diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 65194a7df..0313f23d5 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -160,6 +160,12 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $expected = '$.ajax({url:"\\/posts\\/view\\/1"});'; $this->assertEqual($result, $expected); + $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( + 'update' => '#content' + )); + $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; + $this->assertEqual($result, $expected); + $result = $this->Jquery->request('/people/edit/1', array( 'method' => 'post', 'before' => 'doBefore', @@ -179,7 +185,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase { 'method' => 'post', 'wrapCallbacks' => false )); - $expected = '$.ajax({success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});'; + $expected = '$.ajax({success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});'; $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( @@ -190,7 +196,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase { 'data' => '$("#someId").serialize()', 'wrapCallbacks' => false )); - $expected = '$.ajax({data:$("#someId").serialize(), success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});'; + $expected = '$.ajax({data:$("#someId").serialize(), success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});'; $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( From 73a63a4b650301929ed1f3c60e6c8851f643aebc Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Aug 2009 09:27:01 -0400 Subject: [PATCH 14/49] Fixing whitespace. --- .../cases/libs/view/helpers/jquery_engine.test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 0313f23d5..23d237cb0 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -160,11 +160,11 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $expected = '$.ajax({url:"\\/posts\\/view\\/1"});'; $this->assertEqual($result, $expected); - $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( - 'update' => '#content' - )); - $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; - $this->assertEqual($result, $expected); + $result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array( + 'update' => '#content' + )); + $expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});'; + $this->assertEqual($result, $expected); $result = $this->Jquery->request('/people/edit/1', array( 'method' => 'post', From 06e59abb1f6e5250c7b32c1499d8476e084a6f2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Aug 2009 10:21:28 -0400 Subject: [PATCH 15/49] Removing trailing spaces. --- cake/libs/view/helpers/jquery_engine.php | 12 ++++++------ cake/libs/view/helpers/js.php | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index 407eca62b..b806794f0 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/cake/libs/view/helpers/jquery_engine.php @@ -160,7 +160,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { function event($type, $callback, $options = array()) { $defaults = array('wrap' => true, 'stop' => true); $options = array_merge($defaults, $options); - + $function = 'function (event) {%s}'; if ($options['wrap'] && $options['stop']) { $callback .= "\nreturn false;"; @@ -275,7 +275,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { /** * Create a Draggable element - * + * * Requires both Ui.Core and Ui.Draggable to be loaded. * * @param array $options Array of options for the draggable element. @@ -289,7 +289,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { /** * Create a Droppable element - * + * * Requires both Ui.Core and Ui.Droppable to be loaded. * * @param array $options Array of options for the droppable element. @@ -303,7 +303,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { /** * Create a Slider element - * + * * Requires both Ui.Core and Ui.Slider to be loaded. * * @param array $options Array of options for the droppable element. @@ -317,9 +317,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper { } /** - * Serialize a form attached to $selector. If the current selection is not an input or + * Serialize a form attached to $selector. If the current selection is not an input or * form, errors will be created in the Javascript. - * + * * @param array $options Options for the serialization * @return string completed form serialization script * @see JsHelper::serializeForm() for option list. diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 5b2a61ff6..2e6c60959 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -152,7 +152,7 @@ class JsHelper extends AppHelper { /** * Workaround for Object::Object() existing. Since Object::object exists, it does not - * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for + * fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for * more information on this method. * * @param mixed $data Data to convert into JSON @@ -927,10 +927,10 @@ class JsBaseEngineHelper extends AppHelper { } /** - * Prepare callbacks and wrap them with function ([args]) { } as defined in + * Prepare callbacks and wrap them with function ([args]) { } as defined in * _callbackArgs array. * - * @param string $method Name of the method you are preparing callbacks for. + * @param string $method Name of the method you are preparing callbacks for. * @param array $options Array of options being parsed * @param string $callbacks Additional Keys that contain callbacks * @access protected From 8d6135a8d1f21f2f9bea515b024d7ac52cd5b458 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 13 Aug 2009 11:39:59 -0300 Subject: [PATCH 16/49] Adding support for plugin models used in Auth::$userModel --- cake/libs/controller/components/auth.php | 62 +++++++++---------- .../libs/controller/components/auth.test.php | 50 +++++++++++++++ .../models/test_plugin_auth_user.php | 52 ++++++++++++++++ 3 files changed, 133 insertions(+), 31 deletions(-) create mode 100644 cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 4f2a6b6dd..ce4e0ab42 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -330,23 +330,24 @@ class AuthComponent extends Object { } if ($loginAction == $url) { - if (empty($controller->data) || !isset($controller->data[$this->userModel])) { + $model =& $this->getModel(); + if (empty($controller->data) || !isset($controller->data[$model->alias])) { if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) { $this->Session->write('Auth.redirect', $controller->referer(null, true)); } return false; } - $isValid = !empty($controller->data[$this->userModel][$this->fields['username']]) && - !empty($controller->data[$this->userModel][$this->fields['password']]); + $isValid = !empty($controller->data[$model->alias][$this->fields['username']]) && + !empty($controller->data[$model->alias][$this->fields['password']]); if ($isValid) { - $username = $controller->data[$this->userModel][$this->fields['username']]; - $password = $controller->data[$this->userModel][$this->fields['password']]; + $username = $controller->data[$model->alias][$this->fields['username']]; + $password = $controller->data[$model->alias][$this->fields['password']]; $data = array( - $this->userModel . '.' . $this->fields['username'] => $username, - $this->userModel . '.' . $this->fields['password'] => $password + $model->alias . '.' . $this->fields['username'] => $username, + $model->alias . '.' . $this->fields['password'] => $password ); if ($this->login($data)) { @@ -358,7 +359,7 @@ class AuthComponent extends Object { } $this->Session->setFlash($this->loginError, 'default', array(), 'auth'); - $controller->data[$this->userModel][$this->fields['password']] = null; + $controller->data[$model->alias][$this->fields['password']] = null; return false; } else { if (!$this->user()) { @@ -698,7 +699,8 @@ class AuthComponent extends Object { } if ($key == null) { - return array($this->userModel => $this->Session->read($this->sessionKey)); + $model =& $this->getModel(); + return array($model->alias => $this->Session->read($this->sessionKey)); } else { $user = $this->Session->read($this->sessionKey); if (isset($user[$key])) { @@ -817,6 +819,7 @@ class AuthComponent extends Object { } else { $conditions = $this->userScope; } + $model =& $this->getModel(); if (empty($user)) { $user = $this->user(); if (empty($user)) { @@ -827,51 +830,47 @@ class AuthComponent extends Object { return null; } $user = $user->read(); - $user = $user[$this->userModel]; - } elseif (is_array($user) && isset($user[$this->userModel])) { - $user = $user[$this->userModel]; + $user = $user[$model->alias]; + } elseif (is_array($user) && isset($user[$model->alias])) { + $user = $user[$model->alias]; } - if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$this->userModel . '.' . $this->fields['username']]))) { - + if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$model->alias . '.' . $this->fields['username']]))) { if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) { if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') { return false; } $find = array( - $this->userModel.'.'.$this->fields['username'] => $user[$this->fields['username']], - $this->userModel.'.'.$this->fields['password'] => $user[$this->fields['password']] + $model->alias.'.'.$this->fields['username'] => $user[$this->fields['username']], + $model->alias.'.'.$this->fields['password'] => $user[$this->fields['password']] ); - } elseif (isset($user[$this->userModel . '.' . $this->fields['username']]) && !empty($user[$this->userModel . '.' . $this->fields['username']])) { - if (trim($user[$this->userModel . '.' . $this->fields['username']]) == '=' || trim($user[$this->userModel . '.' . $this->fields['password']]) == '=') { + } elseif (isset($user[$model->alias . '.' . $this->fields['username']]) && !empty($user[$model->alias . '.' . $this->fields['username']])) { + if (trim($user[$model->alias . '.' . $this->fields['username']]) == '=' || trim($user[$model->alias . '.' . $this->fields['password']]) == '=') { return false; } $find = array( - $this->userModel.'.'.$this->fields['username'] => $user[$this->userModel . '.' . $this->fields['username']], - $this->userModel.'.'.$this->fields['password'] => $user[$this->userModel . '.' . $this->fields['password']] + $model->alias.'.'.$this->fields['username'] => $user[$model->alias . '.' . $this->fields['username']], + $model->alias.'.'.$this->fields['password'] => $user[$model->alias . '.' . $this->fields['password']] ); } else { return false; } - $model =& $this->getModel(); $data = $model->find(array_merge($find, $conditions), null, null, 0); - if (empty($data) || empty($data[$this->userModel])) { + if (empty($data) || empty($data[$model->alias])) { return null; } } elseif (!empty($user) && is_string($user)) { - $model =& $this->getModel(); $data = $model->find(array_merge(array($model->escapeField() => $user), $conditions)); - - if (empty($data) || empty($data[$this->userModel])) { + if (empty($data) || empty($data[$model->alias])) { return null; } } if (!empty($data)) { - if (!empty($data[$this->userModel][$this->fields['password']])) { - unset($data[$this->userModel][$this->fields['password']]); + if (!empty($data[$model->alias][$this->fields['password']])) { + unset($data[$model->alias][$this->fields['password']]); } - return $data[$this->userModel]; + return $data[$model->alias]; } return null; } @@ -888,9 +887,10 @@ class AuthComponent extends Object { return $this->authenticate->hashPasswords($data); } - if (is_array($data) && isset($data[$this->userModel])) { - if (isset($data[$this->userModel][$this->fields['username']]) && isset($data[$this->userModel][$this->fields['password']])) { - $data[$this->userModel][$this->fields['password']] = $this->password($data[$this->userModel][$this->fields['password']]); + $model =& $this->getModel(); + if (is_array($data) && isset($data[$model->alias])) { + if (isset($data[$model->alias][$this->fields['username']]) && isset($data[$model->alias][$this->fields['password']])) { + $data[$model->alias][$this->fields['password']] = $this->password($data[$model->alias][$this->fields['password']]); } } return $data; diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index cc6ba4b3a..34ddb2955 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -272,6 +272,7 @@ class AuthTestController extends Controller { * @return void */ function beforeFilter() { + $this->Auth->userModel = 'AuthUser'; } /** @@ -495,6 +496,8 @@ class AuthTest extends CakeTestCase { $this->Controller =& new AuthTestController(); $this->Controller->Component->init($this->Controller); + $this->Controller->Component->initialize($this->Controller); + $this->Controller->beforeFilter(); ClassRegistry::addObject('view', new View($this->Controller)); @@ -1260,6 +1263,53 @@ class AuthTest extends CakeTestCase { Configure::write('Routing.admin', $admin); } +/** + * testPluginModel method + * + * @access public + * @return void + */ + function testPluginModel() { + // Adding plugins + Cache::delete('object_map', '_cake_core_'); + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), + 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS) + ), true); + App::objects('plugin', null, false); + + $PluginModel =& ClassRegistry::init('TestPlugin.TestPluginAuthUser'); + $user['id'] = 1; + $user['username'] = 'gwoo'; + $user['password'] = Security::hash(Configure::read('Security.salt') . 'cake'); + $PluginModel->save($user, false); + + $authUser = $PluginModel->find(); + + $this->Controller->data['TestPluginAuthUser']['username'] = $authUser['TestPluginAuthUser']['username']; + $this->Controller->data['TestPluginAuthUser']['password'] = 'cake'; + + $this->Controller->params = Router::parse('auth_test/login'); + $this->Controller->params['url']['url'] = 'auth_test/login'; + + $this->Controller->Auth->initialize($this->Controller); + + $this->Controller->Auth->loginAction = 'auth_test/login'; + $this->Controller->Auth->userModel = 'TestPlugin.TestPluginAuthUser'; + + $this->Controller->Auth->startup($this->Controller); + $user = $this->Controller->Auth->user(); + $expected = array('TestPluginAuthUser' => array( + 'id' => 1, 'username' => 'gwoo', 'created' => '2007-03-17 01:16:23', 'updated' => date('Y-m-d H:i:s') + )); + $this->assertEqual($user, $expected); + + // Reverting changes + Cache::delete('object_map', '_cake_core_'); + App::build(); + App::objects('plugin', null, false); + } + /** * testAjaxLogin method * diff --git a/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php new file mode 100644 index 000000000..23822ba27 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/models/test_plugin_auth_user.php @@ -0,0 +1,52 @@ + Date: Thu, 13 Aug 2009 12:18:46 -0300 Subject: [PATCH 17/49] Refactoring to use flashLayout variable when setting flash messages --- cake/libs/controller/components/auth.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index ce4e0ab42..19d930545 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -84,6 +84,14 @@ class AuthComponent extends Object { */ var $ajaxLogin = null; +/** + * The name of the layout element used on Session::setFlash + * + * @var string + * @access public + */ + var $flashLayout = 'default'; + /** * The name of the model that represents users which will be authenticated. Defaults to 'User'. * @@ -358,13 +366,13 @@ class AuthComponent extends Object { } } - $this->Session->setFlash($this->loginError, 'default', array(), 'auth'); + $this->Session->setFlash($this->loginError, $this->flashLayout, array(), 'auth'); $controller->data[$model->alias][$this->fields['password']] = null; return false; } else { if (!$this->user()) { if (!$this->RequestHandler->isAjax()) { - $this->Session->setFlash($this->authError, 'default', array(), 'auth'); + $this->Session->setFlash($this->authError, $this->flashLayout, array(), 'auth'); if (!empty($controller->params['url']) && count($controller->params['url']) >= 2) { $query = $controller->params['url']; unset($query['url'], $query['ext']); @@ -428,7 +436,7 @@ class AuthComponent extends Object { return true; } - $this->Session->setFlash($this->authError, 'default', array(), 'auth'); + $this->Session->setFlash($this->authError, $this->flashLayout, array(), 'auth'); $controller->redirect($controller->referer(), null, true); return false; } From c84b4cf36d270048c5577eb5cb65d626768b4283 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 13 Aug 2009 13:08:30 -0300 Subject: [PATCH 18/49] Changing AuthComponent::deny to accepts same param as AuthComponent::allow, tests added --- cake/libs/controller/components/auth.php | 7 +++++-- .../cases/libs/controller/components/auth.test.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 19d930545..0ed374f6b 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -591,7 +591,7 @@ class AuthComponent extends Object { * Takes a list of actions in the current controller for which authentication is not required, or * no parameters to allow all actions. * - * @param string $action Controller action name + * @param mixed $action Controller action name or array of actions * @param string $action Controller action name * @param string ... etc. * @return void @@ -612,7 +612,7 @@ class AuthComponent extends Object { /** * Removes items from the list of allowed actions. * - * @param string $action Controller action name + * @param mixed $action Controller action name or array of actions * @param string $action Controller action name * @param string ... etc. * @return void @@ -621,6 +621,9 @@ class AuthComponent extends Object { */ function deny() { $args = func_get_args(); + if (isset($args[0]) && is_array($args[0])) { + $args = $args[0]; + } foreach ($args as $arg) { $i = array_search($arg, $this->allowedActions); if (is_int($i)) { diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 34ddb2955..e6b75a5cf 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -777,7 +777,7 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->allow('*'); - $this->Controller->Auth->deny('add'); + $this->Controller->Auth->deny('add', 'camelcase'); $this->Controller->params['action'] = 'delete'; $this->assertTrue($this->Controller->Auth->startup($this->Controller)); @@ -787,6 +787,15 @@ class AuthTest extends CakeTestCase { $this->Controller->params['action'] = 'Add'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->params['action'] = 'camelCase'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + + $this->Controller->Auth->allow('*'); + $this->Controller->Auth->deny(array('add', 'camelcase')); + + $this->Controller->params['action'] = 'camelCase'; + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); } /** From dc4cfc59ebd93db82d2868d5b5d4dac56546ae64 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Aug 2009 18:06:38 -0400 Subject: [PATCH 19/49] Updating fileheader. --- cake/console/libs/schema.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index ef94fd8e1..cf83c5c93 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -8,20 +8,17 @@ * PHP versions 4 and 5 * * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package cake * @subpackage cake.cake.console.libs * @since CakePHP(tm) v 1.2.0.5550 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ App::import('Core', 'File', false); From a7499be154143271b3fcb91ef276fcdd6f889832 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Aug 2009 20:06:27 -0400 Subject: [PATCH 20/49] Adding missing & operators. Adding tests for run update. Adding -f param to schema run update to allow for testing and forcing of table comparison. Skips model checks and uses tables only instead. --- cake/console/libs/schema.php | 12 ++- cake/libs/model/cake_schema.php | 1 + cake/tests/cases/console/libs/schema.test.php | 85 +++++++++++++++++++ 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index cf83c5c93..5245a3171 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -287,7 +287,7 @@ class SchemaShell extends Shell { * * @access private */ - function __create($Schema, $table = null) { + function __create(&$Schema, $table = null) { $db =& ConnectionManager::getDataSource($this->Schema->connection); $drop = $create = array(); @@ -331,11 +331,15 @@ class SchemaShell extends Shell { * * @access private */ - function __update($Schema, $table = null) { + function __update(&$Schema, $table = null) { $db =& ConnectionManager::getDataSource($this->Schema->connection); $this->out(__('Comparing Database to Schema...', true)); - $Old = $this->Schema->read(); + $options = array(); + if (isset($this->params['f'])) { + $options['models'] = false; + } + $Old = $this->Schema->read($options); $compare = $this->Schema->compare($Old, $Schema); $contents = array(); @@ -369,7 +373,7 @@ class SchemaShell extends Shell { * * @access private */ - function __run($contents, $event, $Schema) { + function __run($contents, $event, &$Schema) { if (empty($contents)) { $this->err(__('Sql could not be run', true)); return; diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 865dcc517..c2e06a7db 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -186,6 +186,7 @@ class CakeSchema extends Object { * - 'connection' - the db connection to use * - 'name' - name of the schema * - 'models' - a list of models to use, or false to ignore models + * * @param array $options schema object properties * @return array Array indexed by name and tables * @access public diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 5b7ae176d..c82ea2f4b 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -47,6 +47,67 @@ Mock::generatePartial( Mock::generate('CakeSchema', 'MockSchemaCakeSchema'); +/** + * Test for Schema database management + * + * @package cake + * @subpackage cake.tests.cases.libs + */ +class SchemaShellTestSchema extends CakeSchema { + +/** + * name property + * + * @var string 'MyApp' + * @access public + */ + var $name = 'SchemaShellTest'; + +/** + * connection property + * + * @var string 'test_suite' + * @access public + */ + var $connection = 'test_suite'; + +/** + * comments property + * + * @var array + * @access public + */ + var $comments = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), + 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0), + 'user_id' => array('type' => 'integer', 'null' => false), + 'title' => array('type' => 'string', 'null' => false, 'length' => 100), + 'comment' => array('type' => 'text', 'null' => false, 'default' => null), + 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), + ); + +/** + * posts property + * + * @var array + * @access public + */ + var $articles = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''), + 'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'), + 'body' => array('type' => 'text', 'null' => true, 'default' => null), + 'summary' => array('type' => 'text', 'null' => true), + 'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), + ); +} + /** * SchemaShellTest class * @@ -279,5 +340,29 @@ class SchemaShellTest extends CakeTestCase { $this->assertFalse(in_array('aros_acos', $sources)); } +/** + * test run update with a table arg. + * + * @return void + **/ + function testRunUpdateWithTable() { + $this->Shell->params = array( + 'name' => 'SchemaShellTest', + 'connection' => 'test_suite', + 'f' => true + ); + $this->Shell->args = array('update', 'articles'); + $this->Shell->startup(); + $this->Shell->setReturnValue('in', 'y'); + $this->Shell->run(); + + $article =& new Model(array('name' => 'Article', 'ds' => 'test_suite')); + $fields = $article->schema(); + $this->assertTrue(isset($fields['summary'])); + + $this->_fixtures['core.article']->drop($this->db); + $this->_fixtures['core.article']->create($this->db); + } + } ?> \ No newline at end of file From 34b6e18e8dbb7fb62808bff3002eb586809a5d05 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 16 Aug 2009 21:32:10 -0400 Subject: [PATCH 21/49] Adding help() for TestTask. --- cake/console/libs/tasks/fixture.php | 2 +- cake/console/libs/tasks/test.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index de374dedc..8b4ef2da9e 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -419,7 +419,7 @@ class FixtureTask extends Shell { $this->out('Parameters:'); $this->out("\t-count When using generated data, the number of records to include in the fixture(s)."); $this->out("\t-connection Which database configuration to use for baking."); - $this->out("\t-plugin lowercased_underscored name of plugin to bake fixtures for."); + $this->out("\t-plugin CamelCased name of plugin to bake fixtures for."); $this->out(""); $this->_stop(); } diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index 1b53260c1..0ab4c329d 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -414,5 +414,30 @@ class TestTask extends Shell { } return $path . Inflector::underscore($className) . '.test.php'; } + +/** + * Show help file. + * + * @return void + **/ + function help() { + $this->hr(); + $this->out("Usage: cake bake test "); + $this->hr(); + $this->out('Commands:'); + $this->out(""); + $this->out("test model post\n\tbakes a test case for the post model."); + $this->out(""); + $this->out("test controller comments\n\tbakes a test case for the comments controller."); + $this->out(""); + $this->out('Arguments:'); + $this->out("\t Can be any of the following 'controller', 'model', 'helper',\n\t'component', 'behavior'."); + $this->out("\t Any existing class for the chosen type."); + $this->out(""); + $this->out("Parameters:"); + $this->out("\t-plugin CamelCased name of plugin to bake tests for."); + $this->out(""); + $this->_stop(); + } } ?> \ No newline at end of file From ce8dd039da6168a3817d2e9c4e5c62633e9fd478 Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 18 Aug 2009 10:14:39 +0200 Subject: [PATCH 22/49] If there are is more than one theme, the test will hang waiting for the user to select the theme to use --- cake/tests/cases/console/libs/tasks/view.test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index dc850b29c..4358200a5 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -33,13 +33,11 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } - require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'view.php'; require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php'; require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php'; require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php'; - Mock::generatePartial( 'ShellDispatcher', 'TestViewTaskMockShellDispatcher', array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') @@ -120,6 +118,8 @@ class ViewTaskTest extends CakeTestCase { /** * startTest method * + * Ensure that the default theme is used + * * @return void * @access public */ @@ -132,6 +132,7 @@ class ViewTaskTest extends CakeTestCase { $this->Task->Controller =& new ViewTaskMockControllerTask(); $this->Task->Project =& new ViewTaskMockProjectTask(); $this->Task->path = TMP; + $this->Task->Template->params['theme'] = 'default'; } /** From f9e0ddfac63a9e43f105fddc11508d6c5398844b Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Aug 2009 11:53:52 -0400 Subject: [PATCH 23/49] Removing _with use. --- cake/libs/model/cake_schema.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index c2e06a7db..a60b7d3a6 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -239,8 +239,6 @@ class CakeSchema extends Object { foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) { if (isset($assocData['with'])) { $class = $assocData['with']; - } elseif ($assocData['_with']) { - $class = $assocData['_with']; } if (is_object($Object->$class)) { $table = $db->fullTableName($Object->$class, false); From 7c4dfed2999fb2d39c2843a6576c1822e1426900 Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 18 Aug 2009 10:29:54 +0200 Subject: [PATCH 24/49] Updating view and controller tasks to use (_singluar|_plural)HumanName functions Modifying the test case to expect humanized forms --- cake/console/libs/tasks/controller.php | 6 +++--- cake/console/libs/tasks/view.php | 10 ++++------ cake/tests/cases/console/libs/tasks/view.test.php | 12 ++++++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 103a1d210..da2ddd148 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -92,7 +92,7 @@ class ControllerTask extends Shell { $actions= $this->bakeActions($controller, $admin); } } - + if (!empty($this->args[2]) && $this->args[2] == 'admin') { $admin = $this->Project->getAdmin(); if ($admin) { @@ -294,8 +294,8 @@ class ControllerTask extends Shell { $controllerPath = $this->_controllerPath($controllerName); $pluralName = $this->_pluralName($currentModelName); $singularName = Inflector::variable($currentModelName); - $singularHumanName = Inflector::humanize($currentModelName); - $pluralHumanName = Inflector::humanize($controllerName); + $singularHumanName = $this->_singularHumanName($currentModelName); + $pluralHumanName = $this->_pluralName($controllerName); $this->Template->set(compact('admin', 'controllerPath', 'pluralName', 'singularName', 'singularHumanName', 'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName')); diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index b79dc0b4b..c3ed75498 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -284,9 +284,7 @@ class ViewTask extends Shell { $primaryKey = $modelObj->primaryKey; $displayField = $modelObj->displayField; $singularVar = Inflector::variable($modelClass); - $pluralVar = Inflector::variable($this->controllerName); - $singularHumanName = Inflector::humanize($modelClass); - $pluralHumanName = Inflector::humanize($this->controllerName); + $singularHumanName = $this->_singularHumanName($modelClass); $schema = $modelObj->schema(); $fields = array_keys($schema); $associations = $this->__associations($modelObj); @@ -294,13 +292,13 @@ class ViewTask extends Shell { $primaryKey = null; $displayField = null; $singularVar = Inflector::variable(Inflector::singularize($this->controllerName)); - $pluralVar = Inflector::variable($this->controllerName); - $singularHumanName = Inflector::humanize(Inflector::singularize($this->controllerName)); - $pluralHumanName = Inflector::humanize($this->controllerName); + $singularHumanName = $this->_singularHumanName($this->controllerName); $fields = array(); $schema = array(); $associations = array(); } + $pluralVar = Inflector::variable($this->controllerName); + $pluralHumanName = $this->_pluralHumanName($this->controllerName); return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields','associations'); diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 4358200a5..4ce888cd3 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -260,11 +260,11 @@ class ViewTaskTest extends CakeTestCase { $this->Task->expectAt(0, 'createFile', array( TMP . 'view_task_comments' . DS . 'view.ctp', - new PatternExpectation('/ViewTaskComments/') + new PatternExpectation('/View Task Comments/') )); $this->Task->expectAt(1, 'createFile', array( TMP . 'view_task_comments' . DS . 'edit.ctp', - new PatternExpectation('/Edit ViewTaskComment/') + new PatternExpectation('/Edit View Task Comment/') )); $this->Task->expectAt(2, 'createFile', array( TMP . 'view_task_comments' . DS . 'index.ctp', @@ -389,11 +389,11 @@ class ViewTaskTest extends CakeTestCase { )); $this->Task->expectAt(2, 'createFile', array( TMP . 'view_task_comments' . DS . 'add.ctp', - new PatternExpectation('/Add ViewTaskComment/') + new PatternExpectation('/Add View Task Comment/') )); $this->Task->expectAt(3, 'createFile', array( TMP . 'view_task_comments' . DS . 'edit.ctp', - new PatternExpectation('/Edit ViewTaskComment/') + new PatternExpectation('/Edit View Task Comment/') )); $this->Task->execute(); @@ -426,11 +426,11 @@ class ViewTaskTest extends CakeTestCase { )); $this->Task->expectAt(2, 'createFile', array( TMP . 'view_task_comments' . DS . 'admin_add.ctp', - new PatternExpectation('/Add ViewTaskComment/') + new PatternExpectation('/Add View Task Comment/') )); $this->Task->expectAt(3, 'createFile', array( TMP . 'view_task_comments' . DS . 'admin_edit.ctp', - new PatternExpectation('/Edit ViewTaskComment/') + new PatternExpectation('/Edit View Task Comment/') )); $this->Task->execute(); From ae715ef882a1623a3c4fcfb005335d1e597bc8f2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 Aug 2009 01:07:21 -0400 Subject: [PATCH 25/49] Adding in fallback for sql & schema dirs. Starting to add plugin support for schema shell. tests added. --- cake/console/libs/schema.php | 28 ++++++++++------ cake/libs/model/cake_schema.php | 6 +++- cake/tests/cases/console/libs/schema.test.php | 32 +++++++++++++++++-- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 5245a3171..5629c3ae7 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -58,18 +58,12 @@ class SchemaShell extends Shell { * @access public */ function startup() { - $name = null; + $name = $file = $path = $connection = null; if (!empty($this->params['name'])) { $name = $this->params['name']; $this->params['file'] = Inflector::underscore($name); } - - $path = null; - if (!empty($this->params['path'])) { - $path = $this->params['path']; - } - - $file = null; + $path = $this->_getPath(); if (empty($this->params['file'])) { $this->params['file'] = 'schema.php'; } @@ -78,7 +72,6 @@ class SchemaShell extends Shell { } $file = $this->params['file']; - $connection = null; if (!empty($this->params['connection'])) { $connection = $this->params['connection']; } @@ -86,6 +79,23 @@ class SchemaShell extends Shell { $this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection')); } +/** + * Get the correct path for the params. Uses path, and plugin to find the correct path. + * path param takes precedence over any plugins specified. + * + * @return mixed string to correct path or null. + **/ + function _getPath() { + if (!empty($this->params['path'])) { + return $this->params['path']; + } + if (!empty($this->params['plugin'])) { + $pluginPath = $this->_pluginPath($this->params['plugin']); + return $pluginPath . 'config' . DS . 'schema' . DS; + } + return null; + } + /** * Override main * diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index a60b7d3a6..33641c4b8 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -90,7 +90,11 @@ class CakeSchema extends Object { } if (empty($options['path'])) { - $this->path = CONFIGS . 'schema'; + if (is_dir(CONFIGS . 'schema')) { + $this->path = CONFIGS . 'schema'; + } else { + $this->path = CONFIGS . 'sql'; + } } $options = array_merge(get_object_vars($this), $options); diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index c82ea2f4b..7524a4584 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -160,7 +160,7 @@ class SchemaShellTest extends CakeTestCase { $this->assertEqual($this->Shell->Schema->file, 'test_schema.php'); $this->assertEqual($this->Shell->Schema->connection, 'default'); $this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'schema'); - + unset($this->Shell->Schema); $this->Shell->params = array( 'file' => 'other_file.php', @@ -311,7 +311,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->startup(); $this->Shell->setReturnValue('in', 'y'); $this->Shell->run(); - + $db =& ConnectionManager::getDataSource('test_suite'); $sources = $db->listSources(); $this->assertTrue(in_array('i18n', $sources)); @@ -364,5 +364,33 @@ class SchemaShellTest extends CakeTestCase { $this->_fixtures['core.article']->create($this->db); } +/** + * test that the plugin param creates the correct path in the schema object. + * + * @return void + **/ + function testPluginParam() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + )); + $this->Shell->params = array( + 'plugin' => 'TestPlugin', + 'connection' => 'test_suite' + ); + $this->Shell->startup(); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema' . DS; + $this->assertEqual($this->Shell->Schema->path, $expected); + + unset($this->Shell->Schema); + $this->Shell->params = array( + 'plugin' => 'TestPlugin', + 'connection' => 'test_suite', + 'path' => '/some/path' + ); + $this->Shell->startup(); + $expected = '/some/path'; + $this->assertEqual($this->Shell->Schema->path, $expected); + } + } ?> \ No newline at end of file From 98c2801d007742c9ccd2295921672238aa7a8c70 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Aug 2009 22:24:44 -0400 Subject: [PATCH 26/49] Applying patch to clarify Schema error message. Fixed #5337 --- cake/console/libs/schema.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 5629c3ae7..42c06c9d6 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -117,7 +117,8 @@ class SchemaShell extends Shell { $this->out($File->read()); $this->_stop(); } else { - $this->err(__('Schema could not be found', true)); + $file = $this->Schema->path . DS . $this->params['file']; + $this->err(sprintf(__('Schema file (%s) could not be found.', true), $file)); $this->_stop(); } } From 30f8709bb40fb3033c081519f0a5da47ddaeddfd Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Aug 2009 22:46:00 -0400 Subject: [PATCH 27/49] Removing use of low() in core classes and functions. Refs #6525 --- cake/basics.php | 2 +- cake/console/libs/api.php | 4 ++-- cake/console/libs/tasks/db_config.php | 12 ++++++------ cake/console/libs/tasks/model.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 01133de7e..35bd8ba78 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -496,7 +496,7 @@ if (!function_exists('file_put_contents')) { $expires = strtotime($expires, $now); } - switch (low($target)) { + switch (strtolower($target)) { case 'cache': $filename = CACHE . $path; break; diff --git a/cake/console/libs/api.php b/cake/console/libs/api.php index 6513b7e91..e44f096b1 100644 --- a/cake/console/libs/api.php +++ b/cake/console/libs/api.php @@ -173,8 +173,8 @@ class ApiShell extends Shell { foreach ($commands as $cmd) { $this->out("{$cmd}\n\n"); } - } elseif (isset($commands[low($this->args[1])])) { - $this->out($commands[low($this->args[1])] . "\n\n"); + } elseif (isset($commands[strtolower($this->args[1])])) { + $this->out($commands[strtolower($this->args[1])] . "\n\n"); } else { $this->out("Command '" . $this->args[1] . "' not found"); } diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index befedb4c1..aa15518ce 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -108,7 +108,7 @@ class DbConfigTask extends Shell { $driver = $this->in('Driver:', array('db2', 'firebird', 'mssql', 'mysql', 'mysqli', 'odbc', 'oracle', 'postgres', 'sqlite', 'sybase'), 'mysql'); $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n'); - if (low($persistent) == 'n') { + if (strtolower($persistent) == 'n') { $persistent = 'false'; } else { $persistent = 'true'; @@ -124,7 +124,7 @@ class DbConfigTask extends Shell { $port = $this->in('Port?', null, 'n'); } - if (low($port) == 'n') { + if (strtolower($port) == 'n') { $port = null; } @@ -155,7 +155,7 @@ class DbConfigTask extends Shell { while ($prefix == '') { $prefix = $this->in('Table Prefix?', null, 'n'); } - if (low($prefix) == 'n') { + if (strtolower($prefix) == 'n') { $prefix = null; } @@ -163,7 +163,7 @@ class DbConfigTask extends Shell { while ($encoding == '') { $encoding = $this->in('Table encoding?', null, 'n'); } - if (low($encoding) == 'n') { + if (strtolower($encoding) == 'n') { $encoding = null; } @@ -173,7 +173,7 @@ class DbConfigTask extends Shell { $schema = $this->in('Table schema?', null, 'n'); } } - if (low($schema) == 'n') { + if (strtolower($schema) == 'n') { $schema = null; } @@ -185,7 +185,7 @@ class DbConfigTask extends Shell { $dbConfigs[] = $config; $doneYet = $this->in('Do you wish to add another database configuration?', null, 'n'); - if (low($doneYet == 'n')) { + if (strtolower($doneYet == 'n')) { $done = true; } } diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 6dfb2c081..e21a5f91c 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -614,7 +614,7 @@ class ModelTask extends Shell { $prompt = "{$model->name} {$type} {$associations[$type][$i]['alias']}"; $response = $this->in("{$prompt}?", array('y','n'), 'y'); - if ('n' == low($response)) { + if ('n' == strtolower($response)) { unset($associations[$type][$i]); } elseif ($type == 'hasMany') { unset($associations['hasOne'][$i]); @@ -637,7 +637,7 @@ class ModelTask extends Shell { $prompt = __('Would you like to define some additional model associations?', true); $wannaDoMoreAssoc = $this->in($prompt, array('y','n'), 'n'); $possibleKeys = $this->_generatePossibleKeys(); - while (low($wannaDoMoreAssoc) == 'y') { + while (strtolower($wannaDoMoreAssoc) == 'y') { $assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $this->out(__('What is the association type?', true)); $assocType = intval($this->inOptions($assocs, __('Enter a number',true))); From b4a1c4723de2e9e69430647a64996d6d76150555 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 Aug 2009 20:41:39 -0400 Subject: [PATCH 28/49] Making AuthComponent::deny() case insensitive like allow(). Fixes #6261 --- cake/libs/controller/components/auth.php | 4 ++-- .../libs/controller/components/auth.test.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 0ed374f6b..6c2e7062f 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -605,7 +605,7 @@ class AuthComponent extends Object { if (isset($args[0]) && is_array($args[0])) { $args = $args[0]; } - $this->allowedActions = array_merge($this->allowedActions, $args); + $this->allowedActions = array_merge($this->allowedActions, array_map($args, 'strtolower')); } } @@ -625,7 +625,7 @@ class AuthComponent extends Object { $args = $args[0]; } foreach ($args as $arg) { - $i = array_search($arg, $this->allowedActions); + $i = array_search(strtolower($arg), $this->allowedActions); if (is_int($i)) { unset($this->allowedActions[$i]); } diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index e6b75a5cf..fb613d428 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -798,6 +798,23 @@ class AuthTest extends CakeTestCase { $this->assertFalse($this->Controller->Auth->startup($this->Controller)); } +/** + * test that deny() converts camel case inputs to lowercase. + * + * @return void + **/ + function testDenyWithCamelCaseMethods() { + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->Auth->allow('*'); + $this->Controller->Auth->deny('add', 'camelCase'); + + $url = '/auth_test/camelCase'; + $this->Controller->params = Router::parse($url); + $this->Controller->params['url']['url'] = Router::normalize($url); + + $this->assertFalse($this->Controller->Auth->startup($this->Controller)); + } + /** * test that allow() and allowedActions work with camelCase method names. * From 4d7fc24850021d64f0906e84fbf30cbc091ad1db Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 31 Aug 2009 11:38:31 -0400 Subject: [PATCH 29/49] Fixing errors generated by ajaxProvider class not being loaded when checking for method implementation. --- cake/libs/view/helpers/paginator.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index a6872faa8..3030a7ec8 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -88,10 +88,13 @@ class PaginatorHelper extends AppHelper { $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; $this->helpers[] = $ajaxProvider; $this->_ajaxHelperClass = $ajaxProvider; - if (!method_exists($ajaxProvider . 'Helper', 'link')) { + + App::import('Helper', $ajaxProvider); + $classname = $ajaxProvider . 'Helper'; + if (!method_exists($classname, 'link')) { $message = sprintf( __('%s does not implement a link() method, it is incompatible with PaginatorHelper', true), - $ajaxProvider . 'Helper' + $classname ); trigger_error($message, E_USER_WARNING); } From 888d359274bc944aba572191974ea6ce11c932f1 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 2 Sep 2009 00:59:00 +0200 Subject: [PATCH 30/49] strtolower - ing bake flash messages --- .../default/actions/controller_actions.ctp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cake/console/templates/default/actions/controller_actions.ctp b/cake/console/templates/default/actions/controller_actions.ctp index 0b7f1ff27..1a4c5632d 100644 --- a/cake/console/templates/default/actions/controller_actions.ctp +++ b/cake/console/templates/default/actions/controller_actions.ctp @@ -27,10 +27,10 @@ function view($id = null) { if (!$id) { - $this->Session->setFlash(__('Invalid ', true)); + $this->Session->setFlash(__('Invalid ', true)); $this->redirect(array('action' => 'index')); - $this->flash(__('Invalid ', true), array('action' => 'index')); + $this->flash(__('Invalid ', true), array('action' => 'index')); } $this->set('', $this->->read(null, $id)); @@ -42,14 +42,14 @@ $this->->create(); if ($this->->save($this->data)) { - $this->Session->setFlash(__('The has been saved', true)); + $this->Session->setFlash(__('The has been saved', true)); $this->redirect(array('action' => 'index')); - $this->flash(__(' saved.', true), array('action' => 'index')); + $this->flash(__(' saved.', true), array('action' => 'index')); } else { - $this->Session->setFlash(__('The could not be saved. Please, try again.', true)); + $this->Session->setFlash(__('The could not be saved. Please, try again.', true)); } } @@ -74,23 +74,23 @@ function edit($id = null) { if (!$id && empty($this->data)) { - $this->Session->setFlash(__('Invalid ', true)); + $this->Session->setFlash(__('Invalid ', true)); $this->redirect(array('action' => 'index')); - $this->flash(__('Invalid ', true), array('action' => 'index')); + $this->flash(__('Invalid ', true), array('action' => 'index')); } if (!empty($this->data)) { if ($this->->save($this->data)) { - $this->Session->setFlash(__('The has been saved', true)); + $this->Session->setFlash(__('The has been saved', true)); $this->redirect(array('action' => 'index')); - $this->flash(__('The has been saved.', true), array('action' => 'index')); + $this->flash(__('The has been saved.', true), array('action' => 'index')); } else { - $this->Session->setFlash(__('The could not be saved. Please, try again.', true)); + $this->Session->setFlash(__('The could not be saved. Please, try again.', true)); } } @@ -117,24 +117,24 @@ function delete($id = null) { if (!$id) { - $this->Session->setFlash(__('Invalid id for ', true)); + $this->Session->setFlash(__('Invalid id for ', true)); $this->redirect(array('action'=>'index')); - $this->flash(__('Invalid ', true), array('action' => 'index')); + $this->flash(__('Invalid ', true), array('action' => 'index')); } if ($this->->delete($id)) { - $this->Session->setFlash(__(' deleted', true)); + $this->Session->setFlash(__(' deleted', true)); $this->redirect(array('action'=>'index')); - $this->flash(__(' deleted', true), array('action' => 'index')); + $this->flash(__(' deleted', true), array('action' => 'index')); } - $this->Session->setFlash(__(' was not deleted', true)); + $this->Session->setFlash(__(' was not deleted', true)); - $this->flash(__(' was not deleted', true), array('action' => 'index')); + $this->flash(__(' was not deleted', true), array('action' => 'index')); $this->redirect(array('action' => 'index')); } \ No newline at end of file From b8d3aae474368cf96d3a50301d20c16aa456e6d4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 6 Sep 2009 01:04:38 -0400 Subject: [PATCH 31/49] Fixing path to home page template. --- cake/console/libs/tasks/project.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index c29bd96a0..cca7560ef 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -184,7 +184,7 @@ class ProjectTask extends Shell { function createHome($dir) { $app = basename($dir); $path = $dir . 'views' . DS . 'pages' . DS; - $source = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp'; + $source = CAKE . 'console' . DS . 'templates' . DS .'default' . DS . 'views' . DS . 'home.ctp'; include($source); return $this->createFile($path.'home.ctp', $output); } From 91503f8f8a87da69740be34a877c40df8a722094 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 7 Sep 2009 18:33:16 -0400 Subject: [PATCH 32/49] Adding patch from jperras to fix issues with non 'app' APP_DIR values. --- cake/tests/cases/console/libs/schema.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 7524a4584..4f3cc7340 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -148,7 +148,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->startup(); $this->assertTrue(isset($this->Shell->Schema)); $this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema')); - $this->assertEqual($this->Shell->Schema->name, 'App'); + $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR)); $this->assertEqual($this->Shell->Schema->file, 'schema.php'); unset($this->Shell->Schema); @@ -168,7 +168,7 @@ class SchemaShellTest extends CakeTestCase { 'path' => '/test/path' ); $this->Shell->startup(); - $this->assertEqual($this->Shell->Schema->name, 'App'); + $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR)); $this->assertEqual($this->Shell->Schema->file, 'other_file.php'); $this->assertEqual($this->Shell->Schema->connection, 'test_suite'); $this->assertEqual($this->Shell->Schema->path, '/test/path'); From 090eb27be1dd49310142ee8ca6e9ca66d6230810 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 13 Sep 2009 23:42:25 -0400 Subject: [PATCH 33/49] Updating imports in AuthComponent and AuthComponent test case. --- cake/libs/controller/components/auth.php | 11 +++-------- .../libs/controller/components/auth.test.php | 15 +++++---------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 6c2e7062f..3ee6ac73c 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -1,6 +1,4 @@ - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package cake * @subpackage cake.cake.tests.cases.libs.controller.components * @since CakePHP(tm) v 1.2.0.5347 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl')); -App::import(array('controller' . DS . 'components' . DS . 'acl', 'model' . DS . 'db_acl')); +App::import('Component', array('Auth', 'Acl')); +App::import('Model', 'DbAcl'); App::import('Core', 'Xml'); /** From c94698500b91dfec455c33aa90547db9011740ac Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 14 Sep 2009 00:15:06 -0400 Subject: [PATCH 34/49] Adding test case for Auth with authorize = actions. --- .../libs/controller/components/auth.test.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 0edeaea70..891fe2021 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -24,6 +24,8 @@ App::import('Component', array('Auth', 'Acl')); App::import('Model', 'DbAcl'); App::import('Core', 'Xml'); +Mock::generate('AclComponent', 'AuthTestMockAclComponent'); + /** * TestAuthComponent class * @@ -735,7 +737,7 @@ class AuthTest extends CakeTestCase { $result = $this->Controller->Acl->Aro->save(); $this->assertTrue($result); - $this->Controller->Acl->Aco->create(array('alias'=>'Root')); + $this->Controller->Acl->Aco->create(array('alias' => 'Root')); $result = $this->Controller->Acl->Aco->save(); $this->assertTrue($result); @@ -762,6 +764,35 @@ class AuthTest extends CakeTestCase { $this->assertTrue($this->Controller->Session->check('Message.auth')); } +/** + * test authorize = 'actions' setting. + * + * @return void + **/ + function testAuthorizeActions() { + $this->AuthUser =& new AuthUser(); + $user = $this->AuthUser->find(); + $this->Controller->Session->write('Auth', $user); + $this->Controller->params['controller'] = 'auth_test'; + $this->Controller->params['action'] = 'add'; + + $this->Controller->Acl =& new AuthTestMockAclComponent(); + $this->Controller->Acl->setReturnValue('check', true); + + $this->Controller->Auth->initialize($this->Controller); + + $this->Controller->Auth->userModel = 'AuthUser'; + $this->Controller->Auth->authorize = 'actions'; + $this->Controller->Auth->actionPath = 'Root/'; + + $this->Controller->Acl->expectAt(0, 'check', array( + $user, 'Root/AuthTest/add' + )); + + $this->Controller->Auth->startup($this->Controller); + $this->assertTrue($this->Controller->Auth->isAuthorized()); + } + /** * Tests that deny always takes precedence over allow * From 4a6412fb277f33a5a639ee8d5b53e99629d0742a Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 14 Sep 2009 00:29:33 -0400 Subject: [PATCH 35/49] Adding tests for AuthComponent::action(). Adding plugin support for AuthComponent in actions mode. Refs #33 --- cake/libs/controller/components/auth.php | 7 +++-- .../libs/controller/components/auth.test.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 3ee6ac73c..e32899b01 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -772,10 +772,11 @@ class AuthComponent extends Object { * @return boolean ACO node path * @access public */ - function action($action = ':controller/:action') { + function action($action = ':plugin/:controller/:action') { + $plugin = empty($this->params['plugin']) ? null : Inflector::camelize($this->params['plugin']) . '/'; return str_replace( - array(':controller', ':action'), - array(Inflector::camelize($this->params['controller']), $this->params['action']), + array(':controller', ':action', ':plugin/'), + array(Inflector::camelize($this->params['controller']), $this->params['action'], $plugin), $this->actionPath . $action ); } diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 891fe2021..1d8390b15 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -824,6 +824,35 @@ class AuthTest extends CakeTestCase { $this->assertFalse($this->Controller->Auth->startup($this->Controller)); } +/** + * test the action() method + * + * @return void + **/ + function testActionMethod() { + $this->Controller->params['controller'] = 'auth_test'; + $this->Controller->params['action'] = 'add'; + + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->Auth->actionPath = 'ROOT/'; + + $result = $this->Controller->Auth->action(); + $this->assertEqual($result, 'ROOT/AuthTest/add'); + + $result = $this->Controller->Auth->action(':controller'); + $this->assertEqual($result, 'ROOT/AuthTest'); + + $result = $this->Controller->Auth->action(':controller'); + $this->assertEqual($result, 'ROOT/AuthTest'); + + $this->Controller->params['plugin'] = 'test_plugin'; + $this->Controller->params['controller'] = 'auth_test'; + $this->Controller->params['action'] = 'add'; + $this->Controller->Auth->initialize($this->Controller); + $result = $this->Controller->Auth->action(); + $this->assertEqual($result, 'ROOT/TestPlugin/AuthTest/add'); + } + /** * test that deny() converts camel case inputs to lowercase. * From 943524b3a5bf82799122707fd57ded303afbae31 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 18:03:42 -0400 Subject: [PATCH 36/49] Adding empty files to directories that were previously omitted. --- app/views/pages/empty | 0 app/webroot/files/empty | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/views/pages/empty create mode 100644 app/webroot/files/empty diff --git a/app/views/pages/empty b/app/views/pages/empty new file mode 100644 index 000000000..e69de29bb diff --git a/app/webroot/files/empty b/app/webroot/files/empty new file mode 100644 index 000000000..e69de29bb From 37b575496cdd8de661d1f9381429b7e787531e88 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 18:13:53 -0400 Subject: [PATCH 37/49] Fixing capitalization in ControllerTask & test cases. --- .../templates/default/actions/controller_actions.ctp | 4 ++-- .../tests/cases/console/libs/tasks/controller.test.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cake/console/templates/default/actions/controller_actions.ctp b/cake/console/templates/default/actions/controller_actions.ctp index 1a4c5632d..6590a6e4d 100644 --- a/cake/console/templates/default/actions/controller_actions.ctp +++ b/cake/console/templates/default/actions/controller_actions.ctp @@ -128,13 +128,13 @@ $this->Session->setFlash(__(' deleted', true)); $this->redirect(array('action'=>'index')); - $this->flash(__(' deleted', true), array('action' => 'index')); + $this->flash(__(' deleted', true), array('action' => 'index')); } $this->Session->setFlash(__(' was not deleted', true)); - $this->flash(__(' was not deleted', true), array('action' => 'index')); + $this->flash(__(' was not deleted', true), array('action' => 'index')); $this->redirect(array('action' => 'index')); } \ No newline at end of file diff --git a/cake/tests/cases/console/libs/tasks/controller.test.php b/cake/tests/cases/console/libs/tasks/controller.test.php index 50166804e..9ddb24591 100644 --- a/cake/tests/cases/console/libs/tasks/controller.test.php +++ b/cake/tests/cases/console/libs/tasks/controller.test.php @@ -303,16 +303,16 @@ class ControllerTaskTest extends CakeTestCase { $this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false); $this->assertTrue(strpos($result, 'function view($id = null)') !== false); - $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid Article', true))") !== false); + $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid article', true))") !== false); $this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false); $this->assertTrue(strpos($result, 'function add()') !== false); $this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false); - $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The Article has been saved', true))") !== false); + $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article has been saved', true))") !== false); $this->assertTrue(strpos($result, 'function edit($id = null)') !== false); - $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The Article could not be saved. Please, try again.', true));") !== false); + $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article could not be saved. Please, try again.', true));") !== false); $this->assertTrue(strpos($result, 'function delete($id = null)') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false); @@ -346,13 +346,13 @@ class ControllerTaskTest extends CakeTestCase { $this->assertTrue(strpos($result, "\$this->set('articles', \$this->paginate());") !== false); $this->assertTrue(strpos($result, 'function view($id = null)') !== false); - $this->assertTrue(strpos($result, "\$this->flash(__('Invalid Article', true), array('action' => 'index'))") !== false); + $this->assertTrue(strpos($result, "\$this->flash(__('Invalid article', true), array('action' => 'index'))") !== false); $this->assertTrue(strpos($result, "\$this->set('article', \$this->Article->read(null, \$id)") !== false); $this->assertTrue(strpos($result, 'function add()') !== false); $this->assertTrue(strpos($result, 'if (!empty($this->data))') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->save($this->data))') !== false); - $this->assertTrue(strpos($result, "\$this->flash(__('The Article has been saved.', true), array('action' => 'index'))") !== false); + $this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.', true), array('action' => 'index'))") !== false); $this->assertTrue(strpos($result, 'function edit($id = null)') !== false); $this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false); From a839c29eb8a51f71055034cde8f8ecf84cccc208 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 18:16:26 -0400 Subject: [PATCH 38/49] Fixing use of deprecated methods in Auth test. --- .../libs/controller/components/auth.test.php | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 1d8390b15..10a4ab023 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -498,8 +498,8 @@ class AuthTest extends CakeTestCase { ClassRegistry::addObject('view', new View($this->Controller)); - $this->Controller->Session->del('Auth'); - $this->Controller->Session->del('Message.auth'); + $this->Controller->Session->delete('Auth'); + $this->Controller->Session->delete('Message.auth'); Router::reload(); @@ -517,8 +517,8 @@ class AuthTest extends CakeTestCase { $_ENV = $this->_env; Configure::write('Acl', $this->_acl); Configure::write('Security.salt', $this->_securitySalt); - $this->Controller->Session->del('Auth'); - $this->Controller->Session->del('Message.auth'); + $this->Controller->Session->delete('Auth'); + $this->Controller->Session->delete('Message.auth'); ClassRegistry::flush(); unset($this->Controller, $this->AuthUser); } @@ -586,7 +586,7 @@ class AuthTest extends CakeTestCase { 'id' => 1, 'username' => 'mariano', 'created' => '2007-03-17 01:16:23', 'updated' => date('Y-m-d H:i:s') )); $this->assertEqual($user, $expected); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->data['AuthUser']['username'] = 'blah'; $this->Controller->data['AuthUser']['password'] = ''; @@ -595,7 +595,7 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertFalse($user); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->data['AuthUser']['username'] = 'now() or 1=1 --'; $this->Controller->data['AuthUser']['password'] = ''; @@ -604,7 +604,7 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertFalse($user); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->data['AuthUser']['username'] = 'now() or 1=1 # something'; $this->Controller->data['AuthUser']['password'] = ''; @@ -613,7 +613,7 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertFalse($user); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->Auth->userModel = 'UuidUser'; $this->Controller->Auth->login('47c36f9c-bc00-4d17-9626-4e183ca6822b'); @@ -623,7 +623,7 @@ class AuthTest extends CakeTestCase { 'id' => '47c36f9c-bc00-4d17-9626-4e183ca6822b', 'title' => 'Unique record 1', 'count' => 2, 'created' => '2008-03-13 01:16:23', 'updated' => '2008-03-13 01:18:31' )); $this->assertEqual($user, $expected); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); } /** @@ -642,7 +642,7 @@ class AuthTest extends CakeTestCase { $result = $this->Controller->Auth->startup($this->Controller); $this->assertTrue($result); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $result = $this->Controller->Auth->startup($this->Controller); $this->assertFalse($result); $this->assertTrue($this->Controller->Session->check('Message.auth')); @@ -673,7 +673,7 @@ class AuthTest extends CakeTestCase { $this->assertTrue($this->Controller->Session->check('Message.auth')); $this->assertFalse($result); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); } /** @@ -695,7 +695,7 @@ class AuthTest extends CakeTestCase { $result = $this->Controller->Auth->startup($this->Controller); $this->assertTrue($result); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->Auth->startup($this->Controller); $this->assertTrue($this->Controller->Session->check('Message.auth')); $result = $this->Controller->Auth->isAuthorized(); @@ -759,7 +759,7 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->startup($this->Controller); $this->assertTrue($this->Controller->Auth->isAuthorized()); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->Auth->startup($this->Controller); $this->assertTrue($this->Controller->Session->check('Message.auth')); } @@ -932,7 +932,7 @@ class AuthTest extends CakeTestCase { $expected = Router::normalize($this->Controller->Auth->loginRedirect); $this->assertEqual($expected, $this->Controller->Auth->redirect()); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->params['url']['url'] = 'admin/'; $this->Controller->Auth->initialize($this->Controller); @@ -943,7 +943,7 @@ class AuthTest extends CakeTestCase { $this->assertTrue($this->Controller->Session->check('Message.auth')); $this->assertEqual($expected, $this->Controller->Auth->redirect()); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); //empty referer no session $_SERVER['HTTP_REFERER'] = false; @@ -971,7 +971,7 @@ class AuthTest extends CakeTestCase { $this->assertEqual($expected, $this->Controller->testUrl); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $_SERVER['HTTP_REFERER'] = Router::url('/admin/', true); $this->Controller->Session->write('Auth', array( @@ -988,7 +988,7 @@ class AuthTest extends CakeTestCase { //Ticket #4750 //named params - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/posts/index/year:2008/month:feb'; $this->Controller->params = Router::parse($url); $this->Controller->params['url']['url'] = Router::normalize($url); @@ -1000,7 +1000,7 @@ class AuthTest extends CakeTestCase { $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); //passed args - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/posts/view/1'; $this->Controller->params = Router::parse($url); $this->Controller->params['url']['url'] = Router::normalize($url); @@ -1018,7 +1018,7 @@ class AuthTest extends CakeTestCase { 'print' => 'true', 'refer' => 'menu' ); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/posts/index/29?print=true&refer=menu'; $this->Controller->params = Dispatcher::parseParams($url); $this->Controller->Auth->initialize($this->Controller); @@ -1034,7 +1034,7 @@ class AuthTest extends CakeTestCase { 'refer' => 'menu', 'ext' => 'html' ); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/posts/index/29?print=true&refer=menu'; $this->Controller->params = Dispatcher::parseParams($url); $this->Controller->Auth->initialize($this->Controller); @@ -1047,7 +1047,7 @@ class AuthTest extends CakeTestCase { //external authed action $_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message'; - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/posts/edit/1'; $this->Controller->params = Router::parse($url); $this->Controller->params['url']['url'] = Router::normalize($url); @@ -1060,7 +1060,7 @@ class AuthTest extends CakeTestCase { //external direct login link $_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message'; - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $url = '/AuthTest/login'; $this->Controller->params = Router::parse($url); $this->Controller->params['url']['url'] = Router::normalize($url); @@ -1072,7 +1072,7 @@ class AuthTest extends CakeTestCase { $this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect')); $_SERVER['HTTP_REFERER'] = $backup; - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); } /** @@ -1082,7 +1082,7 @@ class AuthTest extends CakeTestCase { * @return void **/ function testNoRedirectOn404() { - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); $this->Controller->Auth->initialize($this->Controller); $this->Controller->params = Router::parse('auth_test/something_totally_wrong'); $result = $this->Controller->Auth->startup($this->Controller); @@ -1117,7 +1117,7 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertTrue($this->Controller->Session->check('Message.auth')); $this->assertEqual($user, false); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); } /** @@ -1142,7 +1142,7 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->startup($this->Controller); $this->assertTrue(is_array($this->Controller->Auth->user())); - $this->Controller->Session->del($this->Controller->Auth->sessionKey); + $this->Controller->Session->delete($this->Controller->Auth->sessionKey); $this->Controller->data['AuthUser']['username'] = 'nate'; $this->Controller->data['AuthUser']['password'] = 'cake1'; @@ -1154,7 +1154,7 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->startup($this->Controller); $this->assertTrue(is_null($this->Controller->Auth->user())); - $this->Controller->Session->del($this->Controller->Auth->sessionKey); + $this->Controller->Session->delete($this->Controller->Auth->sessionKey); $this->Controller->data['AuthUser']['username'] = '> n'; $this->Controller->data['AuthUser']['password'] = 'cake'; @@ -1251,7 +1251,7 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertTrue(!!$user); - $this->Controller->Session->del('Auth'); + $this->Controller->Session->delete('Auth'); Router::reload(); Router::connect('/', array('controller' => 'people', 'action' => 'login')); $url = '/'; From c1056676ec3c8a9e406106a2ecc49e32e636b878 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 18:31:49 -0400 Subject: [PATCH 39/49] Fixing failing test. --- cake/tests/cases/libs/cake_log.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/cake_log.test.php b/cake/tests/cases/libs/cake_log.test.php index ebbe01444..8c95cb70c 100644 --- a/cake/tests/cases/libs/cake_log.test.php +++ b/cake/tests/cases/libs/cake_log.test.php @@ -66,7 +66,7 @@ class CakeLogTest extends CakeTestCase { $result = file(LOGS . 'debug.log'); $this->assertEqual(count($result), 1); $this->assertPattern( - '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Debug: Notice \(8\): Undefined variable: out in \[.+ line \d{2}\]$/', + '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Notice: Notice \(8\): Undefined variable: out in \[.+ line \d{2}\]$/', $result[0] ); @unlink(LOGS . 'debug.log'); From 3c21fa32ba6d5673ad548711ee920872d18a5be2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 18:38:26 -0400 Subject: [PATCH 40/49] Changing syntax to reflect updated api's --- cake/tests/cases/libs/router.test.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 528a06b2c..419a7d336 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1088,11 +1088,12 @@ class RouterTest extends CakeTestCase { $this->assertEqual($result, $expected); Configure::write('Routing.admin', 'admin'); - $paths = Configure::read('pluginPaths'); - Configure::write('pluginPaths', array( - TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS - )); - Configure::write('__objects.plugin', array('test_plugin')); + $paths = App::path('plugins'); + App::build(array( + 'plugins' => array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS + ) + ), false); Router::reload(); Router::setRequestInfo(array( @@ -1107,7 +1108,7 @@ class RouterTest extends CakeTestCase { $expected = '/admin/test_plugin'; $this->assertEqual($result, $expected); - Configure::write('pluginPaths', $paths); + App::build(array('plugins' => $paths)); } /** From 89bf3440da02b93d8e2f1804a548438f5fd24f6b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Sep 2009 19:02:05 -0400 Subject: [PATCH 41/49] Fixing failing test. --- cake/tests/cases/libs/router.test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 419a7d336..e71038fe3 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1093,7 +1093,8 @@ class RouterTest extends CakeTestCase { 'plugins' => array( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS ) - ), false); + ), true); + App::objects('plugin', null, false); Router::reload(); Router::setRequestInfo(array( From 2b0d13733edc09632e7075c243bca77331503583 Mon Sep 17 00:00:00 2001 From: jperras Date: Mon, 21 Sep 2009 12:09:06 -0400 Subject: [PATCH 42/49] Fixing parameter ordering error of array_map in AuthComponent::allow(). Adding test. --- cake/libs/controller/components/auth.php | 2 +- .../cases/libs/controller/components/auth.test.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 8bbdb0497..0a69661ca 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -600,7 +600,7 @@ class AuthComponent extends Object { if (isset($args[0]) && is_array($args[0])) { $args = $args[0]; } - $this->allowedActions = array_merge($this->allowedActions, array_map($args, 'strtolower')); + $this->allowedActions = array_merge($this->allowedActions, array_map('strtolower', $args)); } } diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 10a4ab023..45fac1dc6 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -844,7 +844,7 @@ class AuthTest extends CakeTestCase { $result = $this->Controller->Auth->action(':controller'); $this->assertEqual($result, 'ROOT/AuthTest'); - + $this->Controller->params['plugin'] = 'test_plugin'; $this->Controller->params['controller'] = 'auth_test'; $this->Controller->params['action'] = 'add'; @@ -899,6 +899,17 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->allowedActions = array('delete', 'add'); $result = $this->Controller->Auth->startup($this->Controller); $this->assertFalse($result, 'startup() should return false, as action is not allowed. %s'); + + } + + function testAllowedActionsSetWithAllowMethod() { + $url = '/auth_test/action_name'; + $this->Controller->params = Router::parse($url); + $this->Controller->params['url']['url'] = Router::normalize($url); + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->Auth->allow('action_name', 'anotherAction'); + $this->assertEqual($this->Controller->Auth->allowedActions, array('action_name', 'anotheraction')); + } /** From 32198c58d0df142907c23a1aba8b11df5d81b8ae Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 22 Sep 2009 18:49:30 -0400 Subject: [PATCH 43/49] Removing date validation suggestion for datetime fields. Fixes #106 --- cake/console/libs/tasks/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index e21a5f91c..dc959b392 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -405,7 +405,7 @@ class ModelTask extends Shell { $guess = $methods['numeric']; } elseif ($metaData['type'] == 'boolean') { $guess = $methods['boolean']; - } elseif ($metaData['type'] == 'datetime' || $metaData['type'] == 'date') { + } elseif ($metaData['type'] == 'date') { $guess = $methods['date']; } elseif ($metaData['type'] == 'time') { $guess = $methods['time']; From 6dd144b3cfda85ca5583225914f8a020b78bce1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Wed, 23 Sep 2009 10:46:18 -0430 Subject: [PATCH 44/49] Adding getTemplate to view task Signed-off-by: Mark Story --- cake/console/libs/tasks/view.php | 47 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index c3ed75498..5647613ec 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -370,28 +370,12 @@ class ViewTask extends Shell { /** * Builds content from template and variables * - * @param string $template file to use + * @param string $action name to generate content to * @param array $vars passed for use in templates * @return string content from template * @access public */ - function getContent($template = null, $vars = null) { - if (!$template) { - $template = $this->template; - } - $action = $template; - - $adminRoute = Configure::read('Routing.admin'); - if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) { - $template = str_replace($adminRoute . '_', '', $template); - } - if (in_array($template, array('add', 'edit'))) { - $action = $template; - $template = 'form'; - } elseif (preg_match('@(_add|_edit)$@', $template)) { - $action = $template; - $template = str_replace(array('_add', '_edit'), '_form', $template); - } + function getContent($action, $vars = null) { if (!$vars) { $vars = $this->__loadController(); } @@ -399,13 +383,38 @@ class ViewTask extends Shell { $this->Template->set('action', $action); $this->Template->set('plugin', $this->plugin); $this->Template->set($vars); - $output = $this->Template->generate('views', $template); + $output = $this->Template->generate('views', $this->getTemplate($action)); if (!empty($output)) { return $output; } return false; } + +/** + * Gets the template name based on the action name + * + * @param string $action name + * @return string template name + * @access public + */ + function getTemplate($action) { + if (!empty($this->template) && $action != $this->template) { + return $this->template; + } + $template = $action; + $adminRoute = Configure::read('Routing.admin'); + if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) { + $template = str_replace($adminRoute . '_', '', $template); + } + if (in_array($template, array('add', 'edit'))) { + $template = 'form'; + } elseif (preg_match('@(_add|_edit)$@', $template)) { + $template = str_replace(array('_add', '_edit'), '_form', $template); + } + return $template; + } + /** * Displays help contents From c330934b93df9d565dc6403c3e982a47da54e6a6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 23 Sep 2009 13:27:47 -0400 Subject: [PATCH 45/49] Adding test cases for view task. --- cake/console/libs/tasks/view.php | 3 +-- .../cases/console/libs/tasks/view.test.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 5647613ec..909b4d082 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -390,7 +390,7 @@ class ViewTask extends Shell { } return false; } - + /** * Gets the template name based on the action name * @@ -414,7 +414,6 @@ class ViewTask extends Shell { } return $template; } - /** * Displays help contents diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 4ce888cd3..6c4b42fdb 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -399,6 +399,24 @@ class ViewTaskTest extends CakeTestCase { $this->Task->execute(); } +/** + * test `cake bake view posts index list` + * + * @return void + **/ + function testExecuteWithAlternateTemplates() { + $this->Task->connection = 'test_suite'; + $this->Task->args = array('ViewTaskComments', 'index', 'list'); + $this->Task->params = array(); + + $this->Task->expectCallCount('createFile', 1); + $this->Task->expectAt(0, 'createFile', array( + TMP . 'view_task_comments' . DS . 'list.ctp', + new PatternExpectation('/ViewTaskComment/') + )); + $this->Task->execute(); + } + /** * test execute into interactive() with admin methods. * From de4737323f9650be3d07af0191cb9f61ea8bf1c2 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 22 Sep 2009 02:30:52 +0530 Subject: [PATCH 46/49] Updated Html and Javascript helpers to suffix asset urls with timestamp even when the app is run off a subfolder on the domain Signed-off-by: Mark Story --- cake/libs/view/helpers/html.php | 21 ++++++++----------- cake/libs/view/helpers/javascript.php | 12 ++++------- .../cases/libs/view/helpers/html.test.php | 14 +++++++++++-- .../libs/view/helpers/javascript.test.php | 4 ++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 6be580f89..331b1ad8d 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -374,14 +374,8 @@ class HtmlHelper extends AppHelper { } } - $path = $this->webroot($path); - - $url = $path; - $timestampEnabled = ( - (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || - Configure::read('Asset.timestamp') === 'force' - ); - if (strpos($path, '?') === false && $timestampEnabled) { + $url = $this->webroot($path); + if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); } @@ -607,12 +601,15 @@ class HtmlHelper extends AppHelper { function image($path, $options = array()) { if (is_array($path)) { $path = $this->url($path); - } elseif ($path[0] === '/') { - $path = $this->webroot($path); } elseif (strpos($path, '://') === false) { - $path = $this->webroot(IMAGES_URL . $path); + if ($path[0] !== '/') { + $path = IMAGES_URL . $path; + } + if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') { - $path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . $path)); + $path = $this->webroot($path) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); + } else { + $path = $this->webroot($path); } } diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index 3460f1c07..b46fc14a4 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -271,14 +271,10 @@ class JavascriptHelper extends AppHelper { } } - $url = $this->webroot($url); - $timestampEnabled = ( - (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || - Configure::read('Asset.timestamp') === 'force' - ); - - if (strpos($url, '?') === false && $timestampEnabled) { - $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); + if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { + $url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); + } else { + $url = $this->webroot($url); } if (Configure::read('Asset.filter.js')) { diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index 18c998b30..0a5b2f1f2 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -332,6 +332,16 @@ class HtmlHelperTest extends CakeTestCase { 'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/', 'alt' => '' ))); + + $webroot = $this->Html->webroot; + $this->Html->webroot = '/testing/'; + $result = $this->Html->image('cake.power.gif'); + $this->assertTags($result, array( + 'img' => array( + 'src' => 'preg:/\/testing\/themed\/default\/img\/cake\.power\.gif\?\d+/', + 'alt' => '' + ))); + $this->Html->webroot = $webroot; } /** @@ -420,14 +430,14 @@ class HtmlHelperTest extends CakeTestCase { $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/'; $result = $this->Html->css('cake.generic'); - $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?/'; + $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); $this->Html->webroot = $webroot; $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/longer/'; $result = $this->Html->css('cake.generic'); - $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?/'; + $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); $this->Html->webroot = $webroot; } diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index eb64fec96..0ceea78f0 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -278,11 +278,11 @@ class JavascriptTest extends CakeTestCase { $this->Javascript->webroot = '/testing/'; $result = $this->Javascript->link('__cake_js_test'); - $this->assertPattern('/^]+src="\/testing\/js\/__cake_js_test\.js\?"[^<>]*>/', $result); + $this->assertPattern('/^]+src="\/testing\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result); $this->Javascript->webroot = '/testing/longer/'; $result = $this->Javascript->link('__cake_js_test'); - $this->assertPattern('/^]+src="\/testing\/longer\/js\/__cake_js_test\.js\?"[^<>]*>/', $result); + $this->assertPattern('/^]+src="\/testing\/longer\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result); $this->Javascript->webroot = $webroot; Configure::write('debug', $debug); From 26d2237df02db6a7b51a12d112cfe82272fd5357 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 22 Sep 2009 19:04:40 -0400 Subject: [PATCH 47/49] Making conditions easier to read. Adding additional test for image timestamping. Refs #108 --- cake/libs/view/helpers/html.php | 7 +++++-- cake/libs/view/helpers/javascript.php | 6 +++++- cake/tests/cases/libs/view/helpers/html.test.php | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 331b1ad8d..353a78b8b 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -373,9 +373,12 @@ class HtmlHelper extends AppHelper { $path .= '.css'; } } - + $timestampEnabled = ( + (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || + Configure::read('Asset.timestamp') === 'force' + ); $url = $this->webroot($path); - if (strpos($path, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { + if (strpos($path, '?') === false && $timestampEnabled) { $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); } diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index b46fc14a4..ef4b0ab79 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -270,8 +270,12 @@ class JavascriptHelper extends AppHelper { $url .= '.js'; } } + $timestampEnabled = ( + (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || + Configure::read('Asset.timestamp') === 'force' + ); - if (strpos($url, '?') === false && ((Configure::read('Asset.timestamp') === true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force')) { + if (strpos($url, '?') === false && $timestampEnabled) { $url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); } else { $url = $this->webroot($url); diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index 0a5b2f1f2..831cb048b 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -308,6 +308,15 @@ class HtmlHelperTest extends CakeTestCase { $result = $this->Html->image('cake.icon.gif'); $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => ''))); + + $webroot = $this->Html->webroot; + $this->Html->webroot = '/testing/longer/'; + $result = $this->Html->image('cake.icon.gif'); + $expected = array( + 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.gif\?[0-9]+/', 'alt' => '') + ); + $this->assertTags($result, $expected); + $this->Html->webroot = $webroot; } /** From ee514f3fc6fce7bf4a4fef76af6104b85283a208 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 23 Sep 2009 23:45:11 -0400 Subject: [PATCH 48/49] Adding Helper::assetTimestamp() Refactor's repeated code from Html and Javascript Helpers. Test cases added. --- cake/libs/view/helper.php | 19 ++++++++++++ cake/tests/cases/libs/view/helper.test.php | 35 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index fedb9586f..fd4a610f3 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -224,6 +224,25 @@ class Helper extends Overloadable { return $webPath; } +/** + * Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in + * Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force' + * a timestamp will be added. + * + * @param string $path The file path to timestamp, the path must be inside WWW_ROOT + * @return string Path with a timestamp added, or not. + **/ + function assetTimestamp($path) { + $timestampEnabled = ( + (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || + Configure::read('Asset.timestamp') === 'force' + ); + if (strpos($path, '?') === false && $timestampEnabled) { + $path .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); + } + return $path; + } + /** * Used to remove harmful tags from content * diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index 6b314dece..9bf9d37c9 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -411,6 +411,41 @@ class HelperTest extends CakeTestCase { $this->assertEqual($result, "/posts/index/page:1?one=value&two=value&three=purple"); } +/** + * test assetTimestamp application + * + * @return void + **/ + function testAssetTimestamp() { + $_timestamp = Configure::read('Asset.timestamp'); + $_debug = Configure::read('debug'); + + Configure::write('Asset.timestamp', false); + $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css'); + $this->assertEqual($result, CSS_URL . 'cake.generic.css'); + + Configure::write('Asset.timestamp', true); + Configure::write('debug', 0); + $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css'); + $this->assertEqual($result, CSS_URL . 'cake.generic.css'); + + Configure::write('Asset.timestamp', true); + Configure::write('debug', 2); + $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css'); + $this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result); + + Configure::write('Asset.timestamp', 'force'); + Configure::write('debug', 0); + $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css'); + $this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result); + + $result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam'); + $this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam'); + + Configure::write('debug', $_debug); + Configure::write('Asset.timestamp', $_timestamp); + } + /** * testFieldsWithSameName method * From 7f49f7f455f1f818f92b11ff40bba8f817185177 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 24 Sep 2009 00:16:19 -0400 Subject: [PATCH 49/49] Updating HtmlHelper and JavascriptHelper to use Helper::assetTimestamp --- cake/libs/view/helpers/html.php | 33 ++++----------------------- cake/libs/view/helpers/javascript.php | 11 +-------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 353a78b8b..ec06ee016 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -373,14 +373,7 @@ class HtmlHelper extends AppHelper { $path .= '.css'; } } - $timestampEnabled = ( - (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || - Configure::read('Asset.timestamp') === 'force' - ); - $url = $this->webroot($path); - if (strpos($path, '?') === false && $timestampEnabled) { - $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); - } + $url = $this->webroot($this->assetTimestamp($path)); if (Configure::read('Asset.filter.css')) { $url = str_replace(CSS_URL, 'ccss/', $url); @@ -449,21 +442,10 @@ class HtmlHelper extends AppHelper { if ($url[0] !== '/') { $url = JS_URL . $url; } - $url = $this->webroot($url); - if (strpos($url, '?') === false) { - if (strpos($url, '.js') === false) { - $url .= '.js'; - } - } - - $timestampEnabled = ( - (Configure::read('Asset.timestamp') === true && Configure::read('debug') > 0) || - Configure::read('Asset.timestamp') === 'force' - ); - - if (strpos($url, '?') === false && $timestampEnabled) { - $url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); + if (strpos($url, '?') === false && strpos($url, '.js') === false) { + $url .= '.js'; } + $url = $this->webroot($this->assetTimestamp($url)); if (Configure::read('Asset.filter.js')) { $url = str_replace(JS_URL, 'cjs/', $url); @@ -608,12 +590,7 @@ class HtmlHelper extends AppHelper { if ($path[0] !== '/') { $path = IMAGES_URL . $path; } - - if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') { - $path = $this->webroot($path) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path)); - } else { - $path = $this->webroot($path); - } + $path = $this->webroot($this->assetTimestamp($path)); } if (!isset($options['alt'])) { diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index ef4b0ab79..b378bbf0a 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -270,16 +270,7 @@ class JavascriptHelper extends AppHelper { $url .= '.js'; } } - $timestampEnabled = ( - (Configure::read('Asset.timestamp') === true && Configure::read() > 0) || - Configure::read('Asset.timestamp') === 'force' - ); - - if (strpos($url, '?') === false && $timestampEnabled) { - $url = $this->webroot($url) . '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $url)); - } else { - $url = $this->webroot($url); - } + $url = $this->webroot($this->assetTimestamp($url)); if (Configure::read('Asset.filter.js')) { $url = str_replace(JS_URL, 'cjs/', $url);