Skip to content
This repository
Browse code

Adding tests for array_diff_key() in php4. Increasing test compatibil…

…ity with php4

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8281 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 72d90f2ce82a2c1c4ca33d141e07f8d80026adc6 1 parent 57552c2
Mark Story authored August 03, 2009
2  cake/basics.php
@@ -810,7 +810,7 @@ function array_diff_key() {
810 810
 
811 811
 			foreach ($args[0] as $valueKey => $valueData) {
812 812
 				for ($i = 1; $i < $argc; $i++) {
813  
-					if (isset($args[$i][$valueKey])) {
  813
+					if (array_key_exists($valueKey, $args[$i])) {
814 814
 						continue 2;
815 815
 					}
816 816
 				}
34  cake/tests/cases/basics.test.php
@@ -55,6 +55,36 @@ function tearDown() {
55 55
 		Configure::write('Config.language', $this->_language);
56 56
 	}
57 57
 /**
  58
+ * test the array_diff_key compatibility function.
  59
+ *
  60
+ * @return void
  61
+ **/
  62
+	function testArrayDiffKey() {
  63
+		$one = array('one' => 1, 'two' => 2, 'three' => 3);
  64
+		$two = array('one' => 'one', 'two' => 'two');
  65
+		$result = array_diff_key($one, $two);
  66
+		$expected = array('three' => 3);
  67
+		$this->assertEqual($result, $expected);
  68
+
  69
+		$one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3);
  70
+		$two = array('two' => 'two');
  71
+		$result = array_diff_key($one, $two);
  72
+		$expected = array('one' => array('value', 'value-two'), 'three' => 3);
  73
+		$this->assertEqual($result, $expected);
  74
+
  75
+		$one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0);
  76
+		$two = array('two' => 'two');
  77
+		$result = array_diff_key($one, $two);
  78
+		$expected = array('one' => null, 'three' => '', 'four' => 0);
  79
+		$this->assertEqual($result, $expected);
  80
+
  81
+		$one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
  82
+		$two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
  83
+		$result = array_diff_key($one, $two);
  84
+		$this->assertEqual($result, array());
  85
+
  86
+	}
  87
+/**
58 88
  * testHttpBase method
59 89
  *
60 90
  * @return void
@@ -110,10 +140,10 @@ function testEnv() {
110 140
 
111 141
 		$_SERVER['HTTPS'] = 'off';
112 142
 		$this->assertFalse(env('HTTPS'));
113  
-		
  143
+
114 144
 		$_SERVER['HTTPS'] = false;
115 145
 		$this->assertFalse(env('HTTPS'));
116  
-		
  146
+
117 147
 		$_SERVER['HTTPS'] = '';
118 148
 		$this->assertFalse(env('HTTPS'));
119 149
 
2  cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -291,7 +291,7 @@ function testSortDir() {
291 291
 
292 292
 		$this->assertEqual($result, $expected);
293 293
 
294  
-		unset($this->paginator->params['paging']['article']['options']);
  294
+		unset($this->Paginator->params['paging']['Article']['options']);
295 295
 		$this->Paginator->params['paging']['Article']['options']['direction'] = 'desc';
296 296
 		$result = $this->Paginator->sortDir();
297 297
 		$expected = 'desc';

0 notes on commit 72d90f2

Please sign in to comment.
Something went wrong with that request. Please try again.