From 72d90f2ce82a2c1c4ca33d141e07f8d80026adc6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 3 Aug 2009 19:24:38 +0000 Subject: [PATCH 1/2] 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 @@ if (!function_exists('file_put_contents')) { 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 @@ class BasicsTest extends CakeTestCase { 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 @@ class BasicsTest extends CakeTestCase { $_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 @@ class PaginatorHelperTest extends CakeTestCase { $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 2/2] 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 @@ class SecurityComponent extends Object { 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 @@ class SecurityComponentTest extends CakeTestCase { * @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 = <<