Extracts the redirection to database and table pages to the HomeController for an actual redirection instead of an implicit one. Removes the Application::getRequest() method as the ServerRequest object should be an immutable object. Adds a Routing::$route static variable to be used at the places that the ServerRequest object is not available. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpMyAdmin\Tests\Controllers;
|
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
|
use PhpMyAdmin\Config;
|
|
use PhpMyAdmin\Controllers\HomeController;
|
|
use PhpMyAdmin\DatabaseInterface;
|
|
use PhpMyAdmin\Http\Factory\ResponseFactory;
|
|
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
|
|
use PhpMyAdmin\ResponseRenderer;
|
|
use PhpMyAdmin\Template;
|
|
use PhpMyAdmin\Tests\AbstractTestCase;
|
|
use PhpMyAdmin\Theme\ThemeManager;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
#[CoversClass(HomeController::class)]
|
|
final class HomeControllerTest extends AbstractTestCase
|
|
{
|
|
public function testRedirectToDatabasePage(): void
|
|
{
|
|
$request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/')
|
|
->withQueryParams(['db' => 'test_db']);
|
|
$controller = new HomeController(
|
|
$this->createStub(ResponseRenderer::class),
|
|
$this->createStub(Template::class),
|
|
$this->createStub(Config::class),
|
|
$this->createStub(ThemeManager::class),
|
|
$this->createStub(DatabaseInterface::class),
|
|
ResponseFactory::create(),
|
|
);
|
|
$response = $controller($request);
|
|
$this->assertNotNull($response);
|
|
$this->assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
|
|
$this->assertSame('./index.php?route=/database/structure&db=test_db', $response->getHeaderLine('Location'));
|
|
$this->assertSame('', (string) $response->getBody());
|
|
}
|
|
|
|
public function testRedirectToTablePage(): void
|
|
{
|
|
$request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/')
|
|
->withQueryParams(['db' => 'test_db', 'table' => 'test_table']);
|
|
$controller = new HomeController(
|
|
$this->createStub(ResponseRenderer::class),
|
|
$this->createStub(Template::class),
|
|
$this->createStub(Config::class),
|
|
$this->createStub(ThemeManager::class),
|
|
$this->createStub(DatabaseInterface::class),
|
|
ResponseFactory::create(),
|
|
);
|
|
$response = $controller($request);
|
|
$this->assertNotNull($response);
|
|
$this->assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
|
|
$this->assertSame('./index.php?route=/sql&db=test_db&table=test_table', $response->getHeaderLine('Location'));
|
|
$this->assertSame('', (string) $response->getBody());
|
|
}
|
|
}
|