-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6481fc9
commit 5a6b43a
Showing
22 changed files
with
168 additions
and
447 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
phpunit/functional/Glpi/Http/RedirectLegacyRouteListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2024 Teclib' and contributors. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace tests\units\Glpi\Http; | ||
|
||
use Glpi\Http\RedirectLegacyRouteListener; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
final class RedirectLegacyRouteListenerTest extends TestCase | ||
{ | ||
public static function provideLegacyUrl(): iterable | ||
{ | ||
foreach (['', '/glpi', '/support/glpi'] as $root_doc) { | ||
yield [ | ||
'root_doc' => $root_doc, | ||
'path' => $root_doc . '/front/helpdesk.public.php', | ||
'expected' => $root_doc . '/Helpdesk', | ||
]; | ||
|
||
yield [ | ||
'root_doc' => $root_doc, | ||
'path' => $root_doc . '/front/not.redirected.php', | ||
'expected' => null, | ||
]; | ||
} | ||
} | ||
|
||
#[DataProvider('provideLegacyUrl')] | ||
public function testRedirection(string $root_doc, string $path, ?string $expected): void | ||
{ | ||
$request = new Request(); | ||
$request->server->set('SCRIPT_FILENAME', $root_doc . '/index.php'); | ||
$request->server->set('SCRIPT_NAME', $root_doc . '/index.php'); | ||
$request->server->set('REQUEST_URI', $path); | ||
|
||
$event = new RequestEvent($this->createMock(KernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST); | ||
|
||
$listener = new RedirectLegacyRouteListener(); | ||
$listener->onKernelRequest($event); | ||
|
||
if ($expected === null) { | ||
$this->assertNull($event->getResponse()); | ||
} else { | ||
$this->assertInstanceOf(RedirectResponse::class, $event->getResponse()); | ||
$this->assertEquals($expected, $event->getResponse()->getTargetUrl()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.