From 29dd4ddf034861646747b42872823727e518027a Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 17:38:40 +0000 Subject: [PATCH 1/7] Fixing issues in Scaffold Test case with PHP4. Cleaning up code formatting in Scaffold. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8276 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/scaffold.php | 4 ++-- .../cases/libs/controller/scaffold.test.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 1dce13e34..84549c938 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -167,7 +167,7 @@ function __construct(&$controller, $params) { $associations = $this->__associations(); $this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', - 'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations')); + 'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations')); if ($this->controller->view && $this->controller->view !== 'Theme') { $this->controller->view = 'scaffold'; @@ -378,7 +378,7 @@ function __scaffoldError() { * @access private */ function __scaffold($params) { - $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); + $db =& ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); $admin = Configure::read('Routing.admin'); if (isset($db)) { diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index d0813a419..d7dfa7ea3 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -228,21 +228,21 @@ class ScaffoldViewTest extends CakeTestCase { */ var $fixtures = array('core.article', 'core.user', 'core.comment'); /** - * setUp method + * startTest method * * @access public * @return void */ - function setUp() { + function startTest() { $this->Controller =& new ScaffoldMockController(); } /** - * tearDown method + * endTest method * * @access public * @return void */ - function tearDown() { + function endTest() { unset($this->Controller); } /** @@ -452,7 +452,6 @@ function testEditScaffold() { $this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); $this->assertPattern('/
  • ]*>Delete<\/a>\s*<\/li>/', $result); } - /** * Test Admin Index Scaffolding. * @@ -562,21 +561,21 @@ class ScaffoldTest extends CakeTestCase { */ var $fixtures = array('core.article', 'core.user', 'core.comment'); /** - * setUp method + * startTest method * * @access public * @return void */ - function setUp() { + function startTest() { $this->Controller =& new ScaffoldMockController(); } /** - * tearDown method + * endTest method * * @access public * @return void */ - function tearDown() { + function endTest() { unset($this->Controller); } /** @@ -611,7 +610,6 @@ function testScaffoldParams() { $result = $Scaffold->getParams(); $this->assertEqual($result['action'], 'admin_edit'); } - /** * test that the proper names and variable values are set by Scaffold * @@ -639,7 +637,7 @@ function testScaffoldVariableSetting() { $this->Controller->base = '/'; $this->Controller->constructClasses(); $Scaffold =& new TestScaffoldMock($this->Controller, $params); - $result = $this->Controller->viewVars; + $result = $Scaffold->controller->viewVars; $this->assertEqual($result['singularHumanName'], 'Scaffold Mock'); $this->assertEqual($result['pluralHumanName'], 'Scaffold Mock'); From 401796e1a965982d086c1c33d72554dbad8d3f99 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 17:55:16 +0000 Subject: [PATCH 2/7] Adding missing reference operators in Controller::paginate(). git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8277 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index e559cac78..6a582bfce 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -947,17 +947,17 @@ function paginate($object = null, $scope = array(), $whitelist = array()) { } if ($assoc && isset($this->{$object}->{$assoc})) { - $object = $this->{$object}->{$assoc}; + $object =& $this->{$object}->{$assoc}; } elseif ($assoc && isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$assoc})) { - $object = $this->{$this->modelClass}->{$assoc}; + $object =& $this->{$this->modelClass}->{$assoc}; } elseif (isset($this->{$object})) { - $object = $this->{$object}; + $object =& $this->{$object}; } elseif (isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object})) { - $object = $this->{$this->modelClass}->{$object}; + $object =& $this->{$this->modelClass}->{$object}; } } elseif (empty($object) || $object === null) { if (isset($this->{$this->modelClass})) { - $object = $this->{$this->modelClass}; + $object =& $this->{$this->modelClass}; } else { $className = null; $name = $this->uses[0]; @@ -965,9 +965,9 @@ function paginate($object = null, $scope = array(), $whitelist = array()) { list($name, $className) = explode('.', $this->uses[0]); } if ($className) { - $object = $this->{$className}; + $object =& $this->{$className}; } else { - $object = $this->{$name}; + $object =& $this->{$name}; } } } From bab62df0d8e5f1ea388146abb11a10094b88dcb5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 18:12:42 +0000 Subject: [PATCH 3/7] Fixing fails caused by PHP4 and all lowercase classnames. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8278 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/behavior.test.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cake/tests/cases/libs/model/behavior.test.php b/cake/tests/cases/libs/model/behavior.test.php index 3485b850f..78c2fa1f6 100644 --- a/cake/tests/cases/libs/model/behavior.test.php +++ b/cake/tests/cases/libs/model/behavior.test.php @@ -265,8 +265,8 @@ function onError(&$model) { * @return void */ function beforeTest(&$model) { - $model->beforeTestResult[] = get_class($this); - return get_class($this); + $model->beforeTestResult[] = strtolower(get_class($this)); + return strtolower(get_class($this)); } /** * testMethod method @@ -983,24 +983,24 @@ function testBehaviorMethodDispatchingWithData() { * @return void */ function testBehaviorTrigger() { - $Apple = new Apple(); + $Apple =& new Apple(); $Apple->Behaviors->attach('Test'); $Apple->Behaviors->attach('Test2'); $Apple->Behaviors->attach('Test3'); $Apple->beforeTestResult = array(); $Apple->Behaviors->trigger($Apple, 'beforeTest'); - $expected = array('TestBehavior', 'Test2Behavior', 'Test3Behavior'); + $expected = array('testbehavior', 'test2behavior', 'test3behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => 'Test2Behavior')); - $expected = array('TestBehavior', 'Test2Behavior'); + $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => 'test2behavior')); + $expected = array('testbehavior', 'test2behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => array('Test2Behavior', 'Test3Behavior'))); - $expected = array('TestBehavior', 'Test2Behavior'); + $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => array('test2behavior', 'test3behavior'))); + $expected = array('testbehavior', 'test2behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); } /** From 303b488bc1ebfce81318d5d619ea621a1eb68ecc Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 18:13:46 +0000 Subject: [PATCH 4/7] fixing doc block indentation. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8279 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/behavior.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/behavior.test.php b/cake/tests/cases/libs/model/behavior.test.php index 78c2fa1f6..727316a22 100644 --- a/cake/tests/cases/libs/model/behavior.test.php +++ b/cake/tests/cases/libs/model/behavior.test.php @@ -257,7 +257,7 @@ function onError(&$model) { } echo "onError trigger success"; } - /** +/** * beforeTest method * * @param mixed $model From 57552c25fc99165b1f4d96da5c6201ee158eadd6 Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 3 Aug 2009 18:14:12 +0000 Subject: [PATCH 5/7] updating some tests for php4 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8280 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/console/libs/acl.test.php | 2 +- cake/tests/cases/console/libs/api.test.php | 4 ++-- cake/tests/cases/console/libs/shell.test.php | 14 ++++++++++---- cake/tests/cases/console/libs/tasks/test.test.php | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index df4e337d8..f27a69436 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -86,7 +86,7 @@ function endCase() { function startTest() { $this->Dispatcher =& new TestAclShellMockShellDispatcher(); $this->Task =& new MockAclShell($this->Dispatcher); - $this->Task->Dispatch = new $this->Dispatcher; + $this->Task->Dispatch =& $this->Dispatcher; $this->Task->params['datasource'] = 'test_suite'; } diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php index dbaa34fa6..b5568fce7 100644 --- a/cake/tests/cases/console/libs/api.test.php +++ b/cake/tests/cases/console/libs/api.test.php @@ -64,7 +64,7 @@ class ApiShellTest extends CakeTestCase { function startTest() { $this->Dispatcher =& new ApiShellMockShellDispatcher(); $this->Shell =& new MockApiShell($this->Dispatcher); - $this->Shell->Dispatch = new $this->Dispatcher; + $this->Shell->Dispatch =& $this->Dispatcher; } /** * tearDown method @@ -107,7 +107,7 @@ function testMethodNameDetection () { ) ); $this->Shell->expectAt(1, 'out', $expected); - + $this->Shell->args = array('controller'); $this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS; $this->Shell->main(); diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index bfd15a95b..b832088e5 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -37,10 +37,9 @@ ob_end_clean(); } -Mock::generatePartial( - 'ShellDispatcher', 'TestShellMockShellDispatcher', - array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') - ); +Mock::generatePartial('ShellDispatcher', 'TestShellMockShellDispatcher', array( + 'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment' +)); /** * TestShell class * @@ -48,6 +47,13 @@ * @subpackage cake.tests.cases.console.libs */ class TestShell extends Shell { +/** + * Fixtures used in this test case + * + * @var name + * @access public + */ + var $name = 'TestShell'; } /** * TestAppleTask class diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index c8835cfcb..548f29606 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -65,7 +65,7 @@ class TestTaskTest extends CakeTestCase { function setUp() { $this->Dispatcher =& new TestTestTaskMockShellDispatcher(); $this->Task =& new MockTestTask($this->Dispatcher); - $this->Task->Dispatch = new $this->Dispatcher; + $this->Task->Dispatch =& $this->Dispatcher; } /** * tearDown method From 72d90f2ce82a2c1c4ca33d141e07f8d80026adc6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 19:24:38 +0000 Subject: [PATCH 6/7] Adding tests for array_diff_key() in php4. Increasing test compatibility with php4 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8281 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 2 +- cake/tests/cases/basics.test.php | 34 +++++++++++++++++-- .../libs/view/helpers/paginator.test.php | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 1c1dd61d1..d82fa49d0 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -810,7 +810,7 @@ function array_diff_key() { foreach ($args[0] as $valueKey => $valueData) { for ($i = 1; $i < $argc; $i++) { - if (isset($args[$i][$valueKey])) { + if (array_key_exists($valueKey, $args[$i])) { continue 2; } } diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index a320bc075..7baeeb60f 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -54,6 +54,36 @@ function tearDown() { Configure::write('localePaths', $this->_localePaths); Configure::write('Config.language', $this->_language); } +/** + * test the array_diff_key compatibility function. + * + * @return void + **/ + function testArrayDiffKey() { + $one = array('one' => 1, 'two' => 2, 'three' => 3); + $two = array('one' => 'one', 'two' => 'two'); + $result = array_diff_key($one, $two); + $expected = array('three' => 3); + $this->assertEqual($result, $expected); + + $one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3); + $two = array('two' => 'two'); + $result = array_diff_key($one, $two); + $expected = array('one' => array('value', 'value-two'), 'three' => 3); + $this->assertEqual($result, $expected); + + $one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0); + $two = array('two' => 'two'); + $result = array_diff_key($one, $two); + $expected = array('one' => null, 'three' => '', 'four' => 0); + $this->assertEqual($result, $expected); + + $one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true); + $two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true); + $result = array_diff_key($one, $two); + $this->assertEqual($result, array()); + + } /** * testHttpBase method * @@ -110,10 +140,10 @@ function testEnv() { $_SERVER['HTTPS'] = 'off'; $this->assertFalse(env('HTTPS')); - + $_SERVER['HTTPS'] = false; $this->assertFalse(env('HTTPS')); - + $_SERVER['HTTPS'] = ''; $this->assertFalse(env('HTTPS')); diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index d3145596c..3b8817ab8 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -291,7 +291,7 @@ function testSortDir() { $this->assertEqual($result, $expected); - unset($this->paginator->params['paging']['article']['options']); + unset($this->Paginator->params['paging']['Article']['options']); $this->Paginator->params['paging']['Article']['options']['direction'] = 'desc'; $result = $this->Paginator->sortDir(); $expected = 'desc'; From d41a28c975a4bad5f52dddef3f67796084e3b2b5 Mon Sep 17 00:00:00 2001 From: jperras Date: Mon, 3 Aug 2009 19:40:02 +0000 Subject: [PATCH 7/7] Fixing PHP4 compatibility issues for SecurityComponent. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8282 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/security.php | 2 +- .../cases/libs/controller/components/security.test.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index 077883c3b..96d140256 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -323,7 +323,7 @@ function loginRequest($options = array()) { if (strtolower($options['type']) == 'digest') { $out[] = 'qop="auth"'; - $out[] = 'nonce="' . uniqid() . '"'; + $out[] = 'nonce="' . uniqid("") . '"'; $out[] = 'opaque="' . md5($options['realm']).'"'; } diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index 0ef3dc24c..f744f2dce 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -363,6 +363,14 @@ function testRequireLogin() { * @return void */ function testDigestAuth() { + $skip = $this->skipIf((version_compare(PHP_VERSION, '5.1') == -1) XOR (!function_exists('apache_request_headers')), + "%s Cannot run Digest Auth test for PHP versions < 5.1" + ); + + if ($skip) { + return; + } + $this->Controller->action = 'posted'; $_SERVER['PHP_AUTH_DIGEST'] = $digest = <<