mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 20:27:07 +09:00
Apply suggested fix to tests/Modules/Theme/AdminTest.php from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
66 lines
2.7 KiB
PHP
66 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ThemeTests;
|
|
|
|
use APIHelper\Request;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class AdminTest extends TestCase
|
|
{
|
|
public function testGetCurrentClientTheme(): void
|
|
{
|
|
$result = Request::makeRequest('admin/theme/get_current');
|
|
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
|
|
$data = $result->getResult();
|
|
$this->assertIsArray($data);
|
|
|
|
$this->assertArrayHasKey('name', $data);
|
|
$this->assertArrayHasKey('version', $data);
|
|
$this->assertArrayHasKey('author', $data);
|
|
|
|
$this->assertIsString($data['name']);
|
|
$this->assertNotSame('', trim($data['name']), 'Theme name should not be empty.');
|
|
$this->assertIsString($data['version']);
|
|
$this->assertNotSame('', trim($data['version']), 'Theme version should not be empty.');
|
|
$this->assertIsString($data['author']);
|
|
|
|
$this->assertEquals('FOSSBilling', $data['author']);
|
|
}
|
|
|
|
public function testGetCurrentAdminTheme(): void
|
|
{
|
|
$result = Request::makeRequest('admin/theme/get_current', ['client' => false]);
|
|
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
|
|
$data = $result->getResult();
|
|
$this->assertIsArray($data);
|
|
|
|
$this->assertArrayHasKey('name', $data);
|
|
$this->assertArrayHasKey('version', $data);
|
|
$this->assertArrayHasKey('author', $data);
|
|
|
|
$this->assertIsString($data['name']);
|
|
$this->assertNotSame('', trim($data['name']), 'Theme name should not be empty.');
|
|
$this->assertIsString($data['version']);
|
|
$this->assertNotSame('', trim($data['version']), 'Theme version should not be empty.');
|
|
$this->assertIsString($data['author']);
|
|
|
|
$this->assertEquals('FOSSBilling', $data['author']);
|
|
}
|
|
|
|
public function testInvalidThemeActionReturnsError(): void
|
|
{
|
|
$result = Request::makeRequest('admin/theme/non_existing_action');
|
|
$this->assertSame(404, $result->getStatusCode(), 'Invalid theme action should return HTTP 404.');
|
|
$this->assertFalse($result->wasSuccessful(), 'Invalid theme action should not be successful.');
|
|
// API not-found actions/endpoints are mapped to error code 740 (see src/library/Api/Handler.php).
|
|
$expectedNotFoundErrorCode = 740;
|
|
$this->assertSame($expectedNotFoundErrorCode, $result->getErrorCode(), 'Invalid theme action should return the API not-found error code.');
|
|
|
|
$errorMessage = $result->getErrorMessage();
|
|
$this->assertIsString($errorMessage, 'Error message should be a string.');
|
|
$this->assertNotSame('', trim($errorMessage), 'Error message should not be empty.');
|
|
}
|
|
}
|