OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
109
tests/Unit/app/Core/ApplicationUrlTest.php
Normal file
109
tests/Unit/app/Core/ApplicationUrlTest.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\App\Core;
|
||||
|
||||
use Leantime\Core\Application;
|
||||
use Leantime\Core\Bootstrap\LoadConfig;
|
||||
use Leantime\Core\Bootstrap\SetRequestForConsole;
|
||||
use Leantime\Core\Configuration\Environment;
|
||||
|
||||
class ApplicationUrlTest extends \Unit\TestCase
|
||||
{
|
||||
protected $app;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->bootstrapApplication();
|
||||
|
||||
}
|
||||
|
||||
protected function bootstrapApplication()
|
||||
{
|
||||
|
||||
$this->app = new Application(APP_ROOT);
|
||||
|
||||
$this->app->bootstrapWith([LoadConfig::class, SetRequestForConsole::class]);
|
||||
$this->app->boot();
|
||||
|
||||
$this->config = $this->app['config'];
|
||||
}
|
||||
|
||||
public function test_base_url_is_set_correctly_from_config(): void
|
||||
{
|
||||
// BASE_URL constant is set from LEAN_APP_URL in the environment.
|
||||
// Verify the config matches whatever BASE_URL was resolved to.
|
||||
$this->assertEquals(BASE_URL, $this->config->get('app.url'));
|
||||
|
||||
// Test with LEAN_APP_URL set to a known value
|
||||
putenv('LEAN_APP_URL=https://example.com');
|
||||
$_ENV['LEAN_APP_URL'] = 'https://example.com';
|
||||
|
||||
// Reinitialize application to test new environment
|
||||
$this->bootstrapApplication();
|
||||
|
||||
$this->assertEquals('https://example.com', $this->config->get('app.url'));
|
||||
$this->assertEquals('https://example.com', $this->config->get('appUrl'));
|
||||
}
|
||||
|
||||
public function test_base_url_handles_trailing_slash(): void
|
||||
{
|
||||
|
||||
$_ENV['LEAN_APP_URL'] = 'https://example.com/';
|
||||
|
||||
$this->bootstrapApplication();
|
||||
|
||||
$this->assertEquals('https://example.com', $this->config->get('app.url'));
|
||||
$this->assertEquals('https://example.com', $this->config->get('appUrl'));
|
||||
}
|
||||
|
||||
public function test_base_url_handles_subdirectory(): void
|
||||
{
|
||||
|
||||
$_ENV['LEAN_APP_URL'] = 'https://example.com/leantime';
|
||||
|
||||
$this->bootstrapApplication();
|
||||
|
||||
$this->assertEquals('https://example.com/leantime', $this->config->get('app.url'));
|
||||
$this->assertEquals('https://example.com/leantime', $this->config->get('appUrl'));
|
||||
}
|
||||
|
||||
public function test_base_url_handles_port(): void
|
||||
{
|
||||
|
||||
$_ENV['LEAN_APP_URL'] = 'https://example.com:8443';
|
||||
|
||||
$this->bootstrapApplication();
|
||||
|
||||
$this->assertEquals('https://example.com:8443', $this->config->get('app.url'));
|
||||
$this->assertEquals('https://example.com:8443', $this->config->get('appUrl'));
|
||||
}
|
||||
|
||||
public function test_base_url_handles_reverse_proxy(): void
|
||||
{
|
||||
// Simulate reverse proxy headers
|
||||
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
|
||||
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'example.com';
|
||||
|
||||
$_ENV['LEAN_APP_URL'] = 'https://example.com';
|
||||
|
||||
$this->bootstrapApplication();
|
||||
|
||||
$this->assertEquals('https://example.com', $this->config->get('app.url'));
|
||||
$this->assertEquals('https://example.com', $this->config->get('appUrl'));
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
// Clean up environment
|
||||
putenv('LEAN_APP_URL');
|
||||
unset($_SERVER['HTTP_X_FORWARDED_PROTO']);
|
||||
unset($_SERVER['HTTP_X_FORWARDED_HOST']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user