Remove support for fallback in Redirect helper

This commit is contained in:
Yassine Guedidi 2023-12-28 21:16:32 +01:00
parent ffec47bd88
commit f4493f7472
4 changed files with 14 additions and 31 deletions

View file

@ -45,11 +45,6 @@ parameters:
count: 1 count: 1
path: tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php path: tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php
-
message: "#^Call to method generate\\(\\) on an unknown class PHPUnit_Framework_MockObject_MockObject\\.$#"
count: 2
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
- -
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#" message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
count: 1 count: 1

View file

@ -104,7 +104,7 @@ class TagController extends AbstractController
$this->entityManager->flush(); $this->entityManager->flush();
} }
$redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true);
return $this->redirect($redirectUrl); return $this->redirect($redirectUrl);
} }
@ -185,7 +185,7 @@ class TagController extends AbstractController
$form = $this->createForm(RenameTagType::class, new Tag()); $form = $this->createForm(RenameTagType::class, new Tag());
$form->handleRequest($request); $form->handleRequest($request);
$redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$newTag = new Tag(); $newTag = new Tag();
@ -257,7 +257,7 @@ class TagController extends AbstractController
$this->entityManager->flush(); $this->entityManager->flush();
} }
return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true)); return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), true));
} }
/** /**
@ -279,7 +279,7 @@ class TagController extends AbstractController
$this->entityManager->remove($tag); $this->entityManager->remove($tag);
$this->entityManager->flush(); $this->entityManager->flush();
} }
$redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true);
return $this->redirect($redirectUrl); return $this->redirect($redirectUrl);
} }

View file

@ -23,12 +23,11 @@ class Redirect
/** /**
* @param string $url URL to redirect * @param string $url URL to redirect
* @param string $fallback Fallback URL if $url is null
* @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read * @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read
* *
* @return string * @return string
*/ */
public function to($url, $fallback = '', $ignoreActionMarkAsRead = false) public function to($url, $ignoreActionMarkAsRead = false)
{ {
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
@ -45,10 +44,6 @@ class Redirect
return $url; return $url;
} }
if ('' === $fallback) {
return $this->router->generate('homepage'); return $this->router->generate('homepage');
} }
return $fallback;
}
} }

View file

@ -33,7 +33,7 @@ class RedirectTest extends TestCase
$this->routerMock->expects($this->any()) $this->routerMock->expects($this->any())
->method('generate') ->method('generate')
->with('homepage') ->with('homepage')
->willReturn('homepage'); ->willReturn('/');
$this->user = new User(); $this->user = new User();
$this->user->setName('youpi'); $this->user->setName('youpi');
@ -59,18 +59,11 @@ class RedirectTest extends TestCase
$this->redirect = new Redirect($this->routerMock, $tokenStorage); $this->redirect = new Redirect($this->routerMock, $tokenStorage);
} }
public function testRedirectToNullWithFallback() public function testRedirectToNull()
{
$redirectUrl = $this->redirect->to(null, 'fallback');
$this->assertSame('fallback', $redirectUrl);
}
public function testRedirectToNullWithoutFallback()
{ {
$redirectUrl = $this->redirect->to(null); $redirectUrl = $this->redirect->to(null);
$this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); $this->assertSame('/', $redirectUrl);
} }
public function testRedirectToValidUrl() public function testRedirectToValidUrl()
@ -94,24 +87,24 @@ class RedirectTest extends TestCase
$redirectUrl = $this->redirect->to('/unread/list'); $redirectUrl = $this->redirect->to('/unread/list');
$this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); $this->assertSame('/', $redirectUrl);
} }
public function testUserForRedirectWithIgnoreActionMarkAsRead() public function testUserForRedirectWithIgnoreActionMarkAsRead()
{ {
$this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); $this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
$redirectUrl = $this->redirect->to('/unread/list', '', true); $redirectUrl = $this->redirect->to('/unread/list', true);
$this->assertSame('/unread/list', $redirectUrl); $this->assertSame('/unread/list', $redirectUrl);
} }
public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() public function testUserForRedirectNullWithIgnoreActionMarkAsRead()
{ {
$this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); $this->user->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
$redirectUrl = $this->redirect->to(null, 'fallback', true); $redirectUrl = $this->redirect->to(null, true);
$this->assertSame('fallback', $redirectUrl); $this->assertSame('/', $redirectUrl);
} }
} }