mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-03 23:24:07 +01:00
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* sysPass
|
|
*
|
|
* @author nuxsmin
|
|
* @link https://syspass.org
|
|
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
|
*
|
|
* This file is part of sysPass.
|
|
*
|
|
* sysPass 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.
|
|
*
|
|
* sysPass 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 sysPass. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SP\Tests\Core\Bootstrap;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
use SP\Core\Bootstrap\RouteContext;
|
|
|
|
/**
|
|
* Class RouteContextTest
|
|
*/
|
|
#[Group('unitary')]
|
|
class RouteContextTest extends TestCase
|
|
{
|
|
public static function wrongRouteProvider(): array
|
|
{
|
|
return [
|
|
['testController_1'],
|
|
['testController/action_1']
|
|
];
|
|
}
|
|
|
|
public function testGetRouteContextData()
|
|
{
|
|
$route = 'testController/testAction/param1/param2';
|
|
|
|
$out = RouteContext::getRouteContextData($route);
|
|
|
|
$this->assertEquals('testController', $out->controller);
|
|
$this->assertEquals('testAction', $out->actionName);
|
|
$this->assertEquals('testActionAction', $out->methodName);
|
|
$this->assertEquals('param1', $out->methodParams[0]);
|
|
$this->assertEquals('param2', $out->methodParams[1]);
|
|
}
|
|
|
|
public function testGetRouteContextDataWithNoaction()
|
|
{
|
|
$route = 'testController';
|
|
|
|
$out = RouteContext::getRouteContextData($route);
|
|
|
|
$this->assertEquals('testController', $out->controller);
|
|
$this->assertEquals('index', $out->actionName);
|
|
$this->assertEquals('indexAction', $out->methodName);
|
|
$this->assertCount(0, $out->methodParams);
|
|
}
|
|
|
|
public function testGetRouteContextDataWithActionAndNoParam()
|
|
{
|
|
$route = 'testController/testAction';
|
|
|
|
$out = RouteContext::getRouteContextData($route);
|
|
|
|
$this->assertEquals('testController', $out->controller);
|
|
$this->assertEquals('testAction', $out->actionName);
|
|
$this->assertEquals('testActionAction', $out->methodName);
|
|
$this->assertCount(0, $out->methodParams);
|
|
}
|
|
|
|
#[DataProvider('wrongRouteProvider')]
|
|
public function testGetRouteContextDataWithException(string $route)
|
|
{
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectExceptionMessage('Invalid route');
|
|
|
|
RouteContext::getRouteContextData($route);
|
|
}
|
|
}
|