|
|
@@ -17,6 +17,7 @@
|
|
|
*/
|
|
|
|
|
|
App::uses('Dispatcher', 'Routing');
|
|
|
+App::uses('DispatcherFilter', 'Routing');
|
|
|
|
|
|
if (!class_exists('AppController', false)) {
|
|
|
require_once CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS . 'AppController.php';
|
|
|
@@ -497,6 +498,39 @@ class TimesheetsController extends Controller {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * TestFilterDispatcher class
|
|
|
+ *
|
|
|
+ * @package Cake.Test.Case.Routing
|
|
|
+ */
|
|
|
+class TestFilterDispatcher extends DispatcherFilter {
|
|
|
+
|
|
|
+ public $priority = 10;
|
|
|
+
|
|
|
+/**
|
|
|
+ * TestFilterDispatcher::beforeDispatch()
|
|
|
+ *
|
|
|
+ * @param mixed $event
|
|
|
+ * @return CakeResponse|boolean
|
|
|
+ */
|
|
|
+ public function beforeDispatch(CakeEvent $event) {
|
|
|
+ $event->stopPropagation();
|
|
|
+ $response = $event->data['request'];
|
|
|
+ $response->addParams(array('settings' => $this->settings));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * TestFilterDispatcher::afterDispatch()
|
|
|
+ *
|
|
|
+ * @param mixed $event
|
|
|
+ * @return mixed boolean to stop the event dispatching or null to continue
|
|
|
+ */
|
|
|
+ public function afterDispatch(CakeEvent $event) {
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* DispatcherTest class
|
|
|
*
|
|
|
* @package Cake.Test.Case.Routing
|
|
|
@@ -1226,6 +1260,23 @@ class DispatcherTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Tests that it is possible to attach filter with config classes to the dispatch cycle
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testDispatcherFilterSettings() {
|
|
|
+ Configure::write('Dispatcher.filters', array(
|
|
|
+ 'TestFilterDispatcher' => array('service' => 'google.com')
|
|
|
+ ));
|
|
|
+ $Dispatcher = new Dispatcher();
|
|
|
+ $url = new CakeRequest('some_pages/index');
|
|
|
+ $response = $this->getMock('CakeResponse');
|
|
|
+ $Dispatcher->dispatch($url, $response, array('return' => 1));
|
|
|
+ $settings = $url->param('settings');
|
|
|
+ $this->assertEquals($settings, array('service' => 'google.com'));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* Tests that attaching an inexistent class as filter will throw an exception
|
|
|
*
|
|
|
* @expectedException MissingDispatcherFilterException
|
|
|
@@ -1673,4 +1724,4 @@ class DispatcherTest extends CakeTestCase {
|
|
|
}
|
|
|
return $filename;
|
|
|
}
|
|
|
-}
|
|
|
+}
|