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
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\\.$#"
count: 1

View file

@ -104,7 +104,7 @@ class TagController extends AbstractController
$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);
}
@ -185,7 +185,7 @@ class TagController extends AbstractController
$form = $this->createForm(RenameTagType::class, new Tag());
$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()) {
$newTag = new Tag();
@ -257,7 +257,7 @@ class TagController extends AbstractController
$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->flush();
}
$redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true);
$redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), true);
return $this->redirect($redirectUrl);
}

View file

@ -23,12 +23,11 @@ class 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
*
* @return string
*/
public function to($url, $fallback = '', $ignoreActionMarkAsRead = false)
public function to($url, $ignoreActionMarkAsRead = false)
{
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
@ -45,10 +44,6 @@ class Redirect
return $url;
}
if ('' === $fallback) {
return $this->router->generate('homepage');
}
return $fallback;
return $this->router->generate('homepage');
}
}

View file

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