Skip to content

Commit

Permalink
bug #6183 handling case when referrer in query string is present but …
Browse files Browse the repository at this point in the history
…empty (oleg-andreyev)

This PR was merged into the 4.x branch.

Discussion
----------

handling case when referrer in query string is present but empty

fixes #6154

Commits
-------

791dcae handling case when referrer in query string is present but empty
  • Loading branch information
javiereguiluz committed Mar 4, 2024
2 parents d3c0896 + 791dcae commit 92816bb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Context/AdminContext.php
Expand Up @@ -65,7 +65,9 @@ public function getRequest(): Request

public function getReferrer(): ?string
{
return $this->request->query->get(EA::REFERRER);
$referrer = $this->request->query->get(EA::REFERRER);

return '' !== $referrer ? $referrer : null;
}

public function getI18n(): I18nDto
Expand Down
43 changes: 43 additions & 0 deletions tests/Context/AdminContextTest.php
@@ -0,0 +1,43 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Context;

use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Factory\MenuFactoryInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\AssetsDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\DashboardDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\I18nDto;
use EasyCorp\Bundle\EasyAdminBundle\Registry\CrudControllerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Registry\TemplateRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;

class AdminContextTest extends TestCase
{
public function testGetReferrerEmptyString()
{
$request = $this->createMock(Request::class);
$request->query = new InputBag();
$request->query->set(EA::REFERRER, '');

$target = new AdminContext(
$request,
null,
new I18nDto('en', 'ltr', 'en', []),
new CrudControllerRegistry([], [], [], []),
new DashboardDto(),
$this->createMock(DashboardControllerInterface::class),
new AssetsDto(),
null,
null,
null,
$this->createMock(MenuFactoryInterface::class),
TemplateRegistry::new(),
);

self::assertNull($target->getReferrer());
}
}

0 comments on commit 92816bb

Please sign in to comment.