ViewTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Services;
  4. use PHPUnit\Framework\TestCase;
  5. use App\Services\View;
  6. use App\Models\User;
  7. final class ViewTest extends TestCase
  8. {
  9. private View $view;
  10. private User $user;
  11. protected function setUp(): void
  12. {
  13. $this->view = new View();
  14. $this->user = new User();
  15. }
  16. /**
  17. * @covers App\Services\View::getTheme
  18. */
  19. public function testGetTheme(): void
  20. {
  21. $this->user->isLogin = true;
  22. $this->user->theme = 'tabler';
  23. $theme = $this->view->getTheme($this->user);
  24. $this->assertEquals('tabler', $theme);
  25. $_ENV['theme'] = 'not-tabler';
  26. $this->user->isLogin = false;
  27. $theme = $this->view->getTheme($this->user);
  28. $this->assertEquals('not-tabler', $theme);
  29. }
  30. /**
  31. * @covers App\Services\View::getConfig
  32. */
  33. public function testGetConfig(): void
  34. {
  35. $_ENV['appName'] = 'Test App';
  36. $_ENV['baseUrl'] = 'http://localhost';
  37. $_ENV['jump_delay'] = 3;
  38. $_ENV['enable_kill'] = true;
  39. $_ENV['enable_change_email'] = true;
  40. $_ENV['enable_r2_client_download'] = true;
  41. $_ENV['jsdelivr_url'] = 'https://cdn.jsdelivr.net';
  42. $config = $this->view->getConfig();
  43. $this->assertIsArray($config);
  44. $this->assertArrayHasKey('appName', $config);
  45. $this->assertArrayHasKey('baseUrl', $config);
  46. $this->assertArrayHasKey('jump_delay', $config);
  47. $this->assertArrayHasKey('enable_kill', $config);
  48. $this->assertArrayHasKey('enable_change_email', $config);
  49. $this->assertArrayHasKey('enable_r2_client_download', $config);
  50. $this->assertArrayHasKey('jsdelivr_url', $config);
  51. $this->assertEquals('Test App', $config['appName']);
  52. $this->assertEquals('http://localhost', $config['baseUrl']);
  53. $this->assertEquals(3, $config['jump_delay']);
  54. $this->assertTrue($config['enable_kill']);
  55. $this->assertTrue($config['enable_change_email']);
  56. $this->assertTrue($config['enable_r2_client_download']);
  57. $this->assertEquals('https://cdn.jsdelivr.net', $config['jsdelivr_url']);
  58. }
  59. }