ViewTest.php 2.1 KB

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