70 lines
2.5 KiB
PHP
70 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Test\Unit\Model;
|
|
|
|
use MageSail\Magesail\Model\AdminPathDetector;
|
|
use Magento\Framework\App\DeploymentConfig;
|
|
use Magento\Framework\App\Request\Http;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AdminPathDetectorTest extends TestCase
|
|
{
|
|
public function testGetConfiguredAdminFrontNameUsesDeploymentConfig(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$config->setTestValue('backend/frontName', 'custom');
|
|
$detector = new AdminPathDetector($config);
|
|
self::assertSame('custom', $detector->getConfiguredAdminFrontName());
|
|
}
|
|
|
|
public function testGetConfiguredAdminFrontNameDefaultsToAdmin(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$detector = new AdminPathDetector($config);
|
|
self::assertSame('admin', $detector->getConfiguredAdminFrontName());
|
|
}
|
|
|
|
public function testIsAdminPathTrueWhenPathInfoContainsFrontName(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$config->setTestValue('backend/frontName', 'admin');
|
|
$detector = new AdminPathDetector($config);
|
|
$request = new Http();
|
|
$request->setPathInfo('/admin/sales/order');
|
|
self::assertTrue($detector->isAdminPath($request));
|
|
}
|
|
|
|
public function testIsAdminPathSkipsIndexPhpAndPubSegments(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$config->setTestValue('backend/frontName', 'admin');
|
|
$detector = new AdminPathDetector($config);
|
|
$request = new Http();
|
|
$request->setPathInfo('/pub/index.php/admin/dashboard');
|
|
self::assertTrue($detector->isAdminPath($request));
|
|
}
|
|
|
|
public function testIsAdminPathFalseForFrontendPath(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$config->setTestValue('backend/frontName', 'admin');
|
|
$detector = new AdminPathDetector($config);
|
|
$request = new Http();
|
|
$request->setPathInfo('/catalog/product/view');
|
|
self::assertFalse($detector->isAdminPath($request));
|
|
}
|
|
|
|
public function testGetAdminFrontNameIfPresentInPathUsesRequestUriWhenPathInfoEmpty(): void
|
|
{
|
|
$config = new DeploymentConfig();
|
|
$config->setTestValue('backend/frontName', 'backend');
|
|
$detector = new AdminPathDetector($config);
|
|
$request = new Http();
|
|
$request->setPathInfo('');
|
|
$request->setRequestUri('/backend/index/index');
|
|
self::assertSame('backend', $detector->getAdminFrontNameIfPresentInPath($request));
|
|
}
|
|
}
|