Files
FOSSBilling/tests/Modules/Theme/AdminTest.php
T
Adam DaleyandCopilot Autofix powered by AI 95ce4405cc Fix for 1 code quality finding in Theme legacy tests (#3523)
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>
2026-05-11 20:23:18 +01:00

61 lines
2.3 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->assertValidThemePayload($data);
}
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->assertValidThemePayload($data);
}
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.');
}
private function assertValidThemePayload(array $data): void
{
$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->assertSame('FOSSBilling', $data['author']);
}
}