diff --git a/Controller/ThemeController.php b/Controller/ThemeController.php
index 99cf585..b80a9e7 100644
--- a/Controller/ThemeController.php
+++ b/Controller/ThemeController.php
@@ -12,11 +12,11 @@
namespace Liip\ThemeBundle\Controller;
use Liip\ThemeBundle\ActiveTheme;
-use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Component\Routing\RouterInterface;
/**
* Theme controller.
@@ -42,24 +42,31 @@ class ThemeController
protected $cookieOptions;
/**
- * @var ContainerInterface
+ * @var RouterInterface
*/
- protected $container;
+ protected $router;
+
+ /**
+ * @var string
+ */
+ protected $defaultRoute;
/**
* Theme controller construct.
*
- * @param ActiveTheme $activeTheme active theme instance
- * @param array $themes Available themes
- * @param array|null $cookieOptions The options of the cookie we look for the theme to set
- * @param ContainerInterface $container
+ * @param ActiveTheme $activeTheme active theme instance
+ * @param array $themes Available themes
+ * @param array|null $cookieOptions The options of the cookie we look for the theme to set
+ * @param RouterInterface $router
+ * @param string $defaultRoute
*/
- public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions = null, ContainerInterface $container)
+ public function __construct(ActiveTheme $activeTheme, array $themes, array $cookieOptions = null, RouterInterface $router, $defaultRoute = '/')
{
$this->activeTheme = $activeTheme;
$this->themes = $themes;
$this->cookieOptions = $cookieOptions;
- $this->container = $container;
+ $this->router = $router;
+ $this->defaultRoute = $defaultRoute;
}
/**
@@ -81,7 +88,7 @@ public function switchAction(Request $request)
$this->activeTheme->setName($theme);
- $url = $request->headers->get('Referer', $this->container->get('router')->generate($this->container->getParameter('liip_theme.redirect_fallback')));
+ $url = $request->headers->get('Referer', $this->router->generate($this->defaultRoute));
$response = new RedirectResponse($url);
if (!empty($this->cookieOptions)) {
diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml
index 8812a4e..f50cbcb 100755
--- a/Resources/config/controller.xml
+++ b/Resources/config/controller.xml
@@ -9,7 +9,8 @@
%liip_theme.themes%
%liip_theme.cookie%
-
+
+ %liip_theme.redirect_fallback%
diff --git a/Tests/UseCaseTest.php b/Tests/UseCaseTest.php
index 2fee13d..0eba32e 100644
--- a/Tests/UseCaseTest.php
+++ b/Tests/UseCaseTest.php
@@ -16,6 +16,8 @@
use Liip\ThemeBundle\EventListener\ThemeRequestListener;
use Liip\ThemeBundle\Controller\ThemeController;
use Liip\ThemeBundle\ActiveTheme;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\Router;
/**
* Bundle Functional tests.
@@ -133,9 +135,13 @@ public function testThemeAction($config, $assertion, $hasAlreadyACookie = true)
$request = $this->getMockRequest('cookie');
}
+ $router = $this->getMockBuilder(Router::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
$controller = false;
if ($config['load_controllers']) {
- $controller = new ThemeController($activeTheme, $config['themes'], $config['cookie']);
+ $controller = new ThemeController($activeTheme, $config['themes'], $config['cookie'], $router, $config['redirect_fallback']);
}
$listener = new ThemeRequestListener($activeTheme, $config['cookie'], $device);
@@ -178,6 +184,7 @@ public function dataProvider()
// all-in Controller wins over Cookie and Autodetection
array(
'themes' => array('default', 'controller', 'cookie', 'autodetect'),
+ 'redirect_fallback' => 'homepage',
'active_theme' => 'default',
'autodetect_theme' => true,
'load_controllers' => true,
@@ -194,6 +201,7 @@ public function dataProvider()
array(
array(
'themes' => array('default', 'controller', 'cookie', 'autodetect'),
+ 'redirect_fallback' => 'homepage',
'active_theme' => 'default',
'autodetect_theme' => true,
'load_controllers' => true,
@@ -210,6 +218,7 @@ public function dataProvider()
array(
array(
'themes' => array('default', 'controller', 'cookie', 'autodetect'),
+ 'redirect_fallback' => 'homepage',
'active_theme' => 'default',
'autodetect_theme' => true,
'load_controllers' => false,
@@ -226,6 +235,7 @@ public function dataProvider()
array(
array(
'themes' => array('default', 'controller', 'cookie', 'autodetect'),
+ 'redirect_fallback' => 'homepage',
'active_theme' => 'default',
'autodetect_theme' => false,
'load_controllers' => true,
@@ -242,6 +252,7 @@ public function dataProvider()
array(
array(
'themes' => array('default', 'controller', 'cookie', 'autodetect'),
+ 'redirect_fallback' => 'homepage',
'active_theme' => 'default',
'autodetect_theme' => false,
'load_controllers' => true,