From 4265dbcc33a7e34761f8aec0bcb9afa7575fe256 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Oct 2013 23:07:03 -0400 Subject: [PATCH] Use App.base when there are no requests to generate URL's Setting App.fullBaseUrl to a non-host value causes issues generating URL's in a web context. However, not including the base path generates incorrect URL's in a CLI context. This change allows the use of App.base to populate the base path which is used as a fallback when there are no requests, or when the base path is empty. Refs #2931 --- lib/Cake/Routing/Router.php | 3 +++ lib/Cake/Test/Case/Routing/RouterTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index dba1d6bad..26f6f82c9 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -803,6 +803,9 @@ class Router { $params = $request->params; $path = array('base' => $request->base, 'here' => $request->here); } + if (empty($path['base'])) { + $path['base'] = Configure::read('App.base'); + } $base = $path['base']; $extension = $output = $q = $frag = null; diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 0508deb9f..23896fde4 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -80,6 +80,18 @@ class RouterTest extends CakeTestCase { $this->assertEquals('https://example.com', Configure::read('App.fullBaseUrl')); } +/** + * Test that Router uses App.base to build URL's when there are no stored + * request objects. + * + * @return void + */ + public function testBaseUrlWithBasePath() { + Configure::write('App.base', '/cakephp'); + Router::fullBaseUrl('http://example.com'); + $this->assertEquals('http://example.com/cakephp/tasks', Router::url('/tasks', true)); + } + /** * testRouteDefaultParams method *