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->assertEquals('FOSSBilling', $data['author']); } }