friendica-github/tests/Unit/Util/BasePathTest.php

89 lines
1.9 KiB
PHP
Raw Normal View History

2024-12-22 18:47:57 +00:00
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
2024-12-22 18:48:46 +00:00
declare(strict_types = 1);
2024-12-22 18:47:57 +00:00
namespace Friendica\Test\Unit\Util;
use Friendica\Util\BasePath;
use PHPUnit\Framework\TestCase;
class BasePathTest extends TestCase
{
public static function getDataPaths(): array
{
2024-12-23 14:51:58 +00:00
$basePath = dirname(__DIR__, 3);
$configPath = $basePath . DIRECTORY_SEPARATOR . 'config';
2024-12-22 18:47:57 +00:00
return [
'fullPath' => [
'server' => [],
2024-12-23 14:51:58 +00:00
'baseDir' => $configPath,
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
],
'relative' => [
'server' => [],
'baseDir' => 'config',
2024-12-23 14:51:58 +00:00
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
],
'document_root' => [
'server' => [
2024-12-23 14:51:58 +00:00
'DOCUMENT_ROOT' => $configPath,
2024-12-22 18:47:57 +00:00
],
'baseDir' => '/noooop',
2024-12-23 14:51:58 +00:00
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
],
'pwd' => [
'server' => [
2024-12-23 14:51:58 +00:00
'PWD' => $configPath,
2024-12-22 18:47:57 +00:00
],
'baseDir' => '/noooop',
2024-12-23 14:51:58 +00:00
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
],
'no_overwrite' => [
'server' => [
2024-12-23 14:51:58 +00:00
'DOCUMENT_ROOT' => $basePath,
'PWD' => $basePath,
2024-12-22 18:47:57 +00:00
],
'baseDir' => 'config',
2024-12-23 14:51:58 +00:00
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
],
'no_overwrite_if_invalid' => [
'server' => [
'DOCUMENT_ROOT' => '/nopopop',
2024-12-23 14:51:58 +00:00
'PWD' => $configPath,
2024-12-22 18:47:57 +00:00
],
'baseDir' => '/noatgawe22fafa',
2024-12-23 14:51:58 +00:00
'expected' => $configPath,
2024-12-22 18:47:57 +00:00
]
];
}
/**
* Test the basepath determination
* @dataProvider getDataPaths
*/
public function testDetermineBasePath(array $server, string $baseDir, string $expected): void
{
$basepath = new BasePath($baseDir, $server);
self::assertEquals($expected, $basepath->getPath());
}
/**
* Test the basepath determination with a complete wrong path
*/
public function testFailedBasePath(): void
{
$basepath = new BasePath('/now23452sgfgas', []);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('\'/now23452sgfgas\' is not a valid basepath');
$basepath->getPath();
}
}