Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

setting_test.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }