Skip to content
This repository
Browse code

Fixing RequestHandler::beforeRedirect() and issues with array urls, w…

…here incompatibilities between standard url arrays and requestAction url arrays caused incorrect results. Tests added. Fixes #276
  • Loading branch information...
commit 4b269e3170a5e4724e7bd05d83537905cab27f4e 1 parent 7daad4a
Mark Story authored February 02, 2010
3  cake/libs/controller/components/request_handler.php
@@ -230,6 +230,9 @@ function beforeRedirect(&$controller, $url) {
230 230
 		foreach ($_POST as $key => $val) {
231 231
 			unset($_POST[$key]);
232 232
 		}
  233
+		if (is_array($url)) {
  234
+			$url = Router::url($url + array('base' => false));
  235
+		}
233 236
 		echo $this->requestAction($url, array('return'));
234 237
 		$this->_stop();
235 238
 	}
39  cake/tests/cases/libs/controller/components/request_handler.test.php
@@ -70,6 +70,15 @@ function destination() {
70 70
 		$this->viewPath = 'posts';
71 71
 		$this->render('index');
72 72
 	}
  73
+/**
  74
+ * test method for ajax redirection + parameter parsing
  75
+ *
  76
+ * @return void
  77
+ */
  78
+	function param_method($one = null, $two = null) {
  79
+		echo "one: $one two: $two";
  80
+		$this->autoRender = false;
  81
+	}
73 82
 }
74 83
 /**
75 84
  * RequestHandlerTestDisabledController class
@@ -541,5 +550,35 @@ function testAjaxRedirectAsRequestAction() {
541 550
 		Configure::write('viewPaths', $_paths);
542 551
 		unset($_SERVER['HTTP_X_REQUESTED_WITH']);
543 552
 	}
  553
+
  554
+/**
  555
+ * test that the beforeRedirect callback properly converts
  556
+ * array urls into their correct string ones, and adds base => false so
  557
+ * the correct urls are generated.
  558
+ *
  559
+ * @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
  560
+ * @return void
  561
+ */
  562
+	function testBeforeRedirectCallbackWithArrayUrl() {
  563
+		$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  564
+		App::build(array(
  565
+			'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
  566
+		), true);
  567
+		Router::setRequestInfo(array(
  568
+			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0),
  569
+			array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
  570
+		));
  571
+
  572
+		$RequestHandler =& new NoStopRequestHandler();
  573
+
  574
+		ob_start();
  575
+		$RequestHandler->beforeRedirect(
  576
+			$this->Controller,
  577
+			array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
  578
+		);
  579
+		$result = ob_get_clean();
  580
+		$this->assertEqual($result, 'one: first two: second');
  581
+		App::build();
  582
+	}
544 583
 }
545 584
 ?>

0 notes on commit 4b269e3

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