ViewTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use App\Models\User;
  3. use App\Services\View;
  4. beforeEach(function () {
  5. $this->originalEnv = $_ENV;
  6. $this->view = new View();
  7. $this->user = new User();
  8. });
  9. afterEach(function () {
  10. $_ENV = $this->originalEnv;
  11. });
  12. describe('View::getTheme', function () {
  13. it('returns user theme when user is logged in', function () {
  14. $this->user->isLogin = true;
  15. $this->user->theme = 'tabler';
  16. $theme = $this->view->getTheme($this->user);
  17. expect($theme)->toBe('tabler');
  18. });
  19. it('returns default theme when user is not logged in', function () {
  20. $_ENV['theme'] = 'not-tabler';
  21. $this->user->isLogin = false;
  22. $theme = $this->view->getTheme($this->user);
  23. expect($theme)->toBe('not-tabler');
  24. });
  25. });
  26. describe('View::getConfig', function () {
  27. it('returns complete configuration array', function () {
  28. $_ENV['appName'] = 'Test App';
  29. $_ENV['baseUrl'] = 'http://localhost';
  30. $_ENV['jump_delay'] = 1000;
  31. $_ENV['enable_kill'] = true;
  32. $_ENV['enable_change_email'] = true;
  33. $_ENV['enable_r2_client_download'] = true;
  34. $_ENV['jsdelivr_url'] = 'https://cdn.jsdelivr.net';
  35. $_ENV['locale'] = 'en_US';
  36. $config = $this->view->getConfig();
  37. expect($config)
  38. ->toBeArray()
  39. ->toHaveKeys([
  40. 'appName', 'baseUrl', 'jump_delay', 'enable_kill',
  41. 'enable_change_email', 'enable_r2_client_download', 'jsdelivr_url', 'locale'
  42. ])
  43. ->and($config['appName'])->toBe('Test App')
  44. ->and($config['baseUrl'])->toBe('http://localhost')
  45. ->and($config['jump_delay'])->toBe(1000)
  46. ->and($config['enable_kill'])->toBeTrue()
  47. ->and($config['enable_change_email'])->toBeTrue()
  48. ->and($config['enable_r2_client_download'])->toBeTrue()
  49. ->and($config['jsdelivr_url'])->toBe('https://cdn.jsdelivr.net')
  50. ->and($config['locale'])->toBe('en_US');
  51. });
  52. });