From bb92a47ddbd8191544f6ce8457a3c98041a60f91 Mon Sep 17 00:00:00 2001 From: Phally Date: Wed, 28 Oct 2009 19:14:50 +0100 Subject: [PATCH 1/7] Added support for numeric values in expectation of assertTags(). Signed-off-by: Mark Story --- cake/tests/cases/libs/cake_test_case.test.php | 51 +++++++++++++++++++ cake/tests/lib/cake_test_case.php | 3 ++ 2 files changed, 54 insertions(+) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 5260420a8..3f46159a9 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -164,6 +164,57 @@ class CakeTestCaseTest extends CakeTestCase { } /** + * testNumericValuesInExpectationForAssertTags + * + * @access public + * @return void + */ + + function testNumericValuesInExpectationForAssertTags() { + $value = 220985; + + $input = '

' . $value . '

'; + $pattern = array( + 'p' => array(), + 'strong' => array(), + $value, + '/strong', + '/p' + ); + $this->assertTrue($this->Case->assertTags($input, $pattern)); + + $input = '

' . $value . '

' . $value . '

'; + $pattern = array( + array('p' => array()), + array('strong' => array()), + $value, + '/strong', + '/p', + array('p' => array()), + array('strong' => array()), + $value, + '/strong', + '/p', + ); + $this->assertTrue($this->Case->assertTags($input, $pattern)); + + $input = '

' . $value . '

' . $value . '

'; + $pattern = array( + array('p' => array()), + array('strong' => array()), + $value, + '/strong', + '/p', + array('p' => array('id' => $value)), + array('strong' => array()), + $value, + '/strong', + '/p', + ); + $this->assertTrue($this->Case->assertTags($input, $pattern)); + } + + /** * testBadAssertTags * * @access public diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 8e4dd0c7f..3983e84e3 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -586,6 +586,9 @@ class CakeTestCase extends UnitTestCase { } $i = 0; foreach ($normalized as $tags) { + if (!is_array($tags)) { + $tags = (string)$tags; + } $i++; if (is_string($tags) && $tags{0} == '<') { $tags = array(substr($tags, 1) => array()); From 324b479b1c8016e6d8ba636513860b3326c38ee2 Mon Sep 17 00:00:00 2001 From: Phally Date: Wed, 4 Nov 2009 20:51:39 +0100 Subject: [PATCH 2/7] Refactored test case. Signed-off-by: Mark Story --- cake/tests/cases/libs/cake_test_case.test.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 3f46159a9..b54eb10ef 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -175,8 +175,8 @@ class CakeTestCaseTest extends CakeTestCase { $input = '

' . $value . '

'; $pattern = array( - 'p' => array(), - 'strong' => array(), + '

' . $value . '

'; $pattern = array( - array('p' => array()), - array('strong' => array()), + ' array()), - array('strong' => array()), + '

' . $value . '

'; $pattern = array( - array('p' => array()), - array('strong' => array()), + ' array('id' => $value)), - array('strong' => array()), + 'p' => array('id' => $value), + ' Date: Wed, 2 Dec 2009 11:37:43 -0500 Subject: [PATCH 3/7] Removing whitespace. --- cake/tests/cases/libs/cake_test_case.test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index b54eb10ef..a9c472f28 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -169,7 +169,6 @@ class CakeTestCaseTest extends CakeTestCase { * @access public * @return void */ - function testNumericValuesInExpectationForAssertTags() { $value = 220985; @@ -182,7 +181,7 @@ class CakeTestCaseTest extends CakeTestCase { '/p' ); $this->assertTrue($this->Case->assertTags($input, $pattern)); - + $input = '

' . $value . '

' . $value . '

'; $pattern = array( 'assertTrue($this->Case->assertTags($input, $pattern)); - + $input = '

' . $value . '

' . $value . '

'; $pattern = array( 'assertTrue($this->Case->assertTags($input, $pattern)); } - + /** * testBadAssertTags * From 16f6d4d40834e21162c3c549a465262465f3ed90 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 2 Dec 2009 17:56:52 -0500 Subject: [PATCH 4/7] Making the various SecurityComponent::requireXX methods accept a single array or a list of strings as their arguments. Unifies the use of these functions with AuthComponent. Fixes #354 --- cake/libs/controller/components/security.php | 3 +++ .../libs/controller/components/security.test.php | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index 9b64930a6..e9937663a 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -429,6 +429,9 @@ class SecurityComponent extends Object { * @access protected */ function _requireMethod($method, $actions = array()) { + if (isset($actions[0]) && is_array($actions[0])) { + $actions = $actions[0]; + } $this->{'require' . $method} = (empty($actions)) ? array('*'): $actions; } diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index a704dd183..d0973e23b 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -190,7 +190,7 @@ class SecurityComponentTest extends CakeTestCase { function testRequirePostFail() { $_SERVER['REQUEST_METHOD'] = 'GET'; $this->Controller->action = 'posted'; - $this->Controller->Security->requirePost('posted'); + $this->Controller->Security->requirePost(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); } @@ -219,7 +219,7 @@ class SecurityComponentTest extends CakeTestCase { $_SERVER['HTTPS'] = 'off'; $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; - $this->Controller->Security->requireSecure('posted'); + $this->Controller->Security->requireSecure(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); } @@ -249,7 +249,7 @@ class SecurityComponentTest extends CakeTestCase { $_SERVER['REQUEST_METHOD'] = 'AUTH'; $this->Controller->action = 'posted'; $this->Controller->data = array('username' => 'willy', 'password' => 'somePass'); - $this->Controller->Security->requireAuth('posted'); + $this->Controller->Security->requireAuth(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); @@ -321,7 +321,7 @@ class SecurityComponentTest extends CakeTestCase { function testRequireGetFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'getted'; - $this->Controller->Security->requireGet('getted'); + $this->Controller->Security->requireGet(array('getted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); } @@ -360,7 +360,7 @@ class SecurityComponentTest extends CakeTestCase { $this->Controller->action = 'posted'; $this->Controller->Security->requireLogin( - 'posted', + array('posted'), array('type' => 'basic', 'users' => array('admin' => 'password')) ); $_SERVER['PHP_AUTH_USER'] = 'admin2'; @@ -437,7 +437,7 @@ DIGEST; function testRequirePutFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'putted'; - $this->Controller->Security->requirePut('putted'); + $this->Controller->Security->requirePut(array('putted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); } @@ -479,7 +479,7 @@ DIGEST; function testRequireDeleteFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'deleted'; - $this->Controller->Security->requireDelete('deleted'); + $this->Controller->Security->requireDelete(array('deleted', 'other_method')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); } From 0806545f35e01c2223734fed2087005a00ed0ccc Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 2 Dec 2009 20:57:14 -0500 Subject: [PATCH 5/7] Adding passthrough to localized Validation class for Validation::ssn. Tests added. Fixes #378 --- cake/libs/validation.php | 4 +++- cake/tests/cases/libs/validation.test.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 73a90fe33..c6fde1e76 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -782,11 +782,13 @@ class Validation extends Object { $_this->regex = '/\\A\\b[0-9]{9}\\b\\z/i'; break; case 'us': - default: $_this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i'; break; } } + if (empty($_this->regex)) { + return $_this->_pass('ssn', $check, $country); + } return $_this->_check(); } diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 5e76b9b76..f1af0ce8b 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -58,10 +58,18 @@ class TestNlValidation { function postal($check) { return true; } +/** + * ssn function for testing ssn pass through + * + * @return void + */ + function ssn($check) { + return true; + } } /** - * TestNlValidation class + * TestDeValidation class * * Used to test pass through of Validation * @@ -2041,9 +2049,10 @@ class ValidationTest extends CakeTestCase { * * @return void */ - function testPhoneAndPostalPass() { + function testPhonePostalSsnPass() { $this->assertTrue(Validation::postal('text', null, 'testNl')); $this->assertTrue(Validation::phone('text', null, 'testDe')); + $this->assertTrue(Validation::ssn('text', null, 'testNl')); } /** From 3b74c93582d1931e30bf10d45cc8f572763ba560 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 Dec 2009 09:55:49 -0500 Subject: [PATCH 6/7] Changing how helpers are extracted, fixes issues with view variables not overwriting local helper variables. Fixes #381 --- cake/libs/view/view.php | 11 +++++++---- cake/tests/cases/libs/view/view.test.php | 17 +++++++++++++++++ .../test_app/views/posts/helper_overwrite.ctp | 4 ++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 cake/tests/test_app/views/posts/helper_overwrite.ctp diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 854bcc1e5..701e21044 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -686,13 +686,16 @@ class View extends Object { for ($i = count($helpers) - 1; $i >= 0; $i--) { $name = $helperNames[$i]; + $helper =& $loadedHelpers[$helpers[$i]]; - ${$name} =& $loadedHelpers[$helpers[$i]]; - $this->loaded[$helperNames[$i]] =& ${$name}; - $this->{$helpers[$i]} =& ${$name}; + if (!isset($___dataForView[$name])) { + ${$name} =& $helper; + } + $this->loaded[$helperNames[$i]] =& $helper; + $this->{$helpers[$i]} =& $helper; } $this->_triggerHelpers('beforeRender'); - unset($name, $loadedHelpers, $helpers, $i, $helperNames); + unset($name, $loadedHelpers, $helpers, $i, $helperNames, $helper); } extract($___dataForView, EXTR_SKIP); diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 6f52101f2..c0b7e99eb 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -719,6 +719,23 @@ class ViewTest extends CakeTestCase { Configure::write('Cache.check', $_check); } +/** + * test that view vars can replace the local helper variables + * and not overwrite the $this->Helper references + * + * @return void + */ + function testViewVarOverwritingLocalHelperVar() { + $Controller = new ViewPostsController(); + $Controller->helpers = array('Html'); + $Controller->set('html', 'I am some test html'); + $View = new View($Controller); + $result = $View->render('helper_overwrite', false); + + $this->assertPattern('/I am some test html/', $result); + $this->assertPattern('/Test link/', $result); + } + /** * testGetViewFileName method * diff --git a/cake/tests/test_app/views/posts/helper_overwrite.ctp b/cake/tests/test_app/views/posts/helper_overwrite.ctp new file mode 100644 index 000000000..a3b6928fb --- /dev/null +++ b/cake/tests/test_app/views/posts/helper_overwrite.ctp @@ -0,0 +1,4 @@ +Html->link('Test link', '#'); +?> \ No newline at end of file From 9cd78889916cb34e92d1c7a92f3433ebb23dfb85 Mon Sep 17 00:00:00 2001 From: AD7six Date: Thu, 3 Dec 2009 21:33:56 +0100 Subject: [PATCH 7/7] removing reference to unused variable __bare --- cake/libs/controller/components/session.php | 21 ------------------- .../controller/components/session.test.php | 20 ------------------ 2 files changed, 41 deletions(-) diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index bcf0dc6f3..cc4820c4b 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -48,14 +48,6 @@ class SessionComponent extends CakeSession { */ var $__started = false; -/** - * Used to determine if request are from an Ajax request - * - * @var boolean - * @access private - */ - var $__bare = 0; - /** * Class constructor * @@ -69,19 +61,6 @@ class SessionComponent extends CakeSession { } } -/** - * Initializes the component, gets a reference to Controller::$param['bare']. - * - * @param object $controller A reference to the controller - * @return void - * @access public - */ - function initialize(&$controller) { - if (isset($controller->params['bare'])) { - $this->__bare = $controller->params['bare']; - } - } - /** * Startup method. * diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index ce33e280d..445e8fd03 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -136,26 +136,6 @@ class SessionComponentTest extends CakeTestCase { $this->assertEqual($result, $expected); } -/** - * testSessionInitialize method - * - * @access public - * @return void - */ - function testSessionInitialize() { - $Session =& new SessionComponent(); - - $this->assertEqual($Session->__bare, 0); - - $Session->initialize(new SessionTestController()); - $this->assertEqual($Session->__bare, 0); - - $sessionController =& new SessionTestController(); - $sessionController->params['bare'] = 1; - $Session->initialize($sessionController); - $this->assertEqual($Session->__bare, 1); - } - /** * testSessionActivate method *