You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setting_test.go 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestSettingShowUserEmailExplore(t *testing.T) {
  12. prepareTestEnv(t)
  13. showUserEmail := setting.UI.ShowUserEmail
  14. setting.UI.ShowUserEmail = true
  15. session := loginUser(t, "user2")
  16. req := NewRequest(t, "GET", "/explore/users")
  17. resp := session.MakeRequest(t, req, http.StatusOK)
  18. htmlDoc := NewHTMLParser(t, resp.Body)
  19. assert.Contains(t,
  20. htmlDoc.doc.Find(".ui.user.list").Text(),
  21. "user2@example.com",
  22. )
  23. setting.UI.ShowUserEmail = false
  24. req = NewRequest(t, "GET", "/explore/users")
  25. resp = session.MakeRequest(t, req, http.StatusOK)
  26. htmlDoc = NewHTMLParser(t, resp.Body)
  27. assert.NotContains(t,
  28. htmlDoc.doc.Find(".ui.user.list").Text(),
  29. "user2@example.com",
  30. )
  31. setting.UI.ShowUserEmail = showUserEmail
  32. }
  33. func TestSettingShowUserEmailProfile(t *testing.T) {
  34. prepareTestEnv(t)
  35. showUserEmail := setting.UI.ShowUserEmail
  36. setting.UI.ShowUserEmail = true
  37. session := loginUser(t, "user2")
  38. req := NewRequest(t, "GET", "/user2")
  39. resp := session.MakeRequest(t, req, http.StatusOK)
  40. htmlDoc := NewHTMLParser(t, resp.Body)
  41. assert.Contains(t,
  42. htmlDoc.doc.Find(".user.profile").Text(),
  43. "user2@example.com",
  44. )
  45. setting.UI.ShowUserEmail = false
  46. req = NewRequest(t, "GET", "/user2")
  47. resp = session.MakeRequest(t, req, http.StatusOK)
  48. htmlDoc = NewHTMLParser(t, resp.Body)
  49. assert.NotContains(t,
  50. htmlDoc.doc.Find(".user.profile").Text(),
  51. "user2@example.com",
  52. )
  53. setting.UI.ShowUserEmail = showUserEmail
  54. }
  55. func TestSettingLandingPage(t *testing.T) {
  56. prepareTestEnv(t)
  57. landingPage := setting.LandingPageURL
  58. setting.LandingPageURL = setting.LandingPageHome
  59. req := NewRequest(t, "GET", "/")
  60. MakeRequest(t, req, http.StatusOK)
  61. setting.LandingPageURL = setting.LandingPageExplore
  62. req = NewRequest(t, "GET", "/")
  63. resp := MakeRequest(t, req, http.StatusFound)
  64. assert.Equal(t, "/explore", resp.Header().Get("Location"))
  65. setting.LandingPageURL = setting.LandingPageOrganizations
  66. req = NewRequest(t, "GET", "/")
  67. resp = MakeRequest(t, req, http.StatusFound)
  68. assert.Equal(t, "/explore/organizations", resp.Header().Get("Location"))
  69. setting.LandingPageURL = landingPage
  70. }