THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

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.

104 lines
2.6KB

  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. "user4@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. "user4@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. // Should contain since this user owns the profile page
  50. assert.Contains(t,
  51. htmlDoc.doc.Find(".user.profile").Text(),
  52. "user2@example.com",
  53. )
  54. setting.UI.ShowUserEmail = showUserEmail
  55. session = loginUser(t, "user4")
  56. req = NewRequest(t, "GET", "/user2")
  57. resp = session.MakeRequest(t, req, http.StatusOK)
  58. htmlDoc = NewHTMLParser(t, resp.Body)
  59. assert.NotContains(t,
  60. htmlDoc.doc.Find(".user.profile").Text(),
  61. "user2@example.com",
  62. )
  63. }
  64. func TestSettingLandingPage(t *testing.T) {
  65. prepareTestEnv(t)
  66. landingPage := setting.LandingPageURL
  67. setting.LandingPageURL = setting.LandingPageHome
  68. req := NewRequest(t, "GET", "/")
  69. MakeRequest(t, req, http.StatusOK)
  70. setting.LandingPageURL = setting.LandingPageExplore
  71. req = NewRequest(t, "GET", "/")
  72. resp := MakeRequest(t, req, http.StatusFound)
  73. assert.Equal(t, "/explore", resp.Header().Get("Location"))
  74. setting.LandingPageURL = setting.LandingPageOrganizations
  75. req = NewRequest(t, "GET", "/")
  76. resp = MakeRequest(t, req, http.StatusFound)
  77. assert.Equal(t, "/explore/organizations", resp.Header().Get("Location"))
  78. setting.LandingPageURL = landingPage
  79. }