Files
sysPass/tests/SP/Core/Bootstrap/UriContextTest.php
Rubén D 7076741399 chore(tests): UT for UriContext
Signed-off-by: Rubén D <nuxsmin@syspass.org>
2023-11-26 22:32:28 +01:00

88 lines
2.7 KiB
PHP

<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2023, 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/>.
*/
namespace SP\Tests\Core\Bootstrap;
use PHPUnit\Framework\MockObject\Exception;
use SP\Core\Bootstrap\UriContext;
use SP\Http\RequestInterface;
use SP\Tests\UnitaryTestCase;
/**
* Class UriContextTest
*
* @group unitary
*/
class UriContextTest extends UnitaryTestCase
{
/**
* @throws Exception
*/
public function testConstruct()
{
$request = $this->createMock(RequestInterface::class);
$request->expects(self::exactly(2))
->method('getServer')
->with(...$this->withConsecutive(['SCRIPT_FILENAME'], ['REQUEST_URI']))
->willReturn('/some/path/to/test.php', '/syspass/test.php');
$domainName = self::$faker->domainName;
$request->expects(self::once())
->method('getHttpHost')
->willReturn($domainName);
$uriContext = new UriContext($request);
$this->assertEquals('/test.php', $uriContext->getSubUri());
$this->assertEquals('/syspass', $uriContext->getWebRoot());
$this->assertEquals($domainName . '/syspass', $uriContext->getWebUri());
}
/**
* @throws Exception
*/
public function testConstructWithoutWebRoot()
{
$request = $this->createMock(RequestInterface::class);
$request->expects(self::exactly(2))
->method('getServer')
->with(...$this->withConsecutive(['SCRIPT_FILENAME'], ['REQUEST_URI']))
->willReturn('/some/path/to/test.php', 'test.php');
$domainName = self::$faker->domainName;
$request->expects(self::once())
->method('getHttpHost')
->willReturn($domainName);
$uriContext = new UriContext($request);
$this->assertEquals('/test.php', $uriContext->getSubUri());
$this->assertEquals('', $uriContext->getWebRoot());
$this->assertEquals($domainName, $uriContext->getWebUri());
}
}