mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 15:35:59 +01:00
Merge branch 'master' into group-description
This commit is contained in:
@@ -3,76 +3,81 @@ package gitbucket.core.view
|
||||
import java.util.Date
|
||||
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.{SystemSettingsService, RequestCache}
|
||||
import gitbucket.core.service.{RequestCache, SystemSettingsService}
|
||||
import gitbucket.core.controller.Context
|
||||
import org.specs2.mutable._
|
||||
import org.specs2.mock.Mockito
|
||||
import SystemSettingsService.SystemSettings
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import play.twirl.api.Html
|
||||
import javax.servlet.http.{HttpServletRequest, HttpSession}
|
||||
|
||||
class AvatarImageProviderSpec extends Specification with Mockito {
|
||||
import play.twirl.api.Html
|
||||
import org.scalatest.FunSpec
|
||||
import org.scalatest.mock.MockitoSugar
|
||||
import org.mockito.Mockito._
|
||||
|
||||
|
||||
class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
|
||||
val request = mock[HttpServletRequest]
|
||||
request.getRequestURL returns new StringBuffer("http://localhost:8080/path.html")
|
||||
request.getRequestURI returns "/path.html"
|
||||
request.getContextPath returns ""
|
||||
val session = mock[HttpSession]
|
||||
when(request.getRequestURL).thenReturn(new StringBuffer("http://localhost:8080/path.html"))
|
||||
when(request.getRequestURI).thenReturn("/path.html")
|
||||
when(request.getContextPath).thenReturn("")
|
||||
when(request.getSession).thenReturn(session)
|
||||
|
||||
"getAvatarImageHtml" should {
|
||||
"show Gravatar image for no image account if gravatar integration is enabled" in {
|
||||
describe("getAvatarImageHtml") {
|
||||
it("should show Gravatar image for no image account if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
|
||||
|
||||
provider.toHtml("user", 32).toString mustEqual
|
||||
"<img src=\"https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=32&d=retro&r=g\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />"
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=32&d=retro&r=g\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />")
|
||||
}
|
||||
|
||||
"show uploaded image even if gravatar integration is enabled" in {
|
||||
it("should show uploaded image even if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))))
|
||||
|
||||
provider.toHtml("user", 32).toString mustEqual
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />"
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />")
|
||||
}
|
||||
|
||||
"show local image for no image account if gravatar integration is disabled" in {
|
||||
it("should show local image for no image account if gravatar integration is disabled") {
|
||||
implicit val context = Context(createSystemSettings(false), None, request)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
|
||||
|
||||
provider.toHtml("user", 32).toString mustEqual
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />"
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />")
|
||||
}
|
||||
|
||||
"show Gravatar image for specified mail address if gravatar integration is enabled" in {
|
||||
it("should show Gravatar image for specified mail address if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
|
||||
"<img src=\"https://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20&d=retro&r=g\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20&d=retro&r=g\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
}
|
||||
|
||||
"show unknown image for unknown user if gravatar integration is enabled" in {
|
||||
it("should show unknown image for unknown user if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20).toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
assert(provider.toHtml("user", 20).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
}
|
||||
|
||||
"show unknown image for specified mail address if gravatar integration is disabled" in {
|
||||
it("should show unknown image for specified mail address if gravatar integration is disabled") {
|
||||
implicit val context = Context(createSystemSettings(false), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
}
|
||||
|
||||
"add tooltip if it's enabled" in {
|
||||
it("should add tooltip if it's enabled") {
|
||||
implicit val context = Context(createSystemSettings(false), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>"
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com", true).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +108,9 @@ class AvatarImageProviderSpec extends Specification with Mockito {
|
||||
notification = false,
|
||||
activityLogLimit = None,
|
||||
ssh = false,
|
||||
sshHost = None,
|
||||
sshPort = None,
|
||||
useSMTP = false,
|
||||
smtp = None,
|
||||
ldapAuthentication = false,
|
||||
ldap = None)
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import org.specs2.mutable._
|
||||
|
||||
class GitBucketHtmlSerializerSpec extends Specification {
|
||||
|
||||
import GitBucketHtmlSerializer._
|
||||
|
||||
"generateAnchorName" should {
|
||||
"convert whitespace characters to hyphens" in {
|
||||
val before = "foo bar baz"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "foo-bar-baz"
|
||||
}
|
||||
|
||||
"normalize characters with diacritics" in {
|
||||
val before = "Dónde estará mi vida"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "do%cc%81nde-estara%cc%81-mi-vida"
|
||||
}
|
||||
|
||||
"omit special characters" in {
|
||||
val before = "foo!bar@baz>9000"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "foo%21bar%40baz%3e9000"
|
||||
}
|
||||
}
|
||||
|
||||
"escapeTaskList" should {
|
||||
"convert '- [ ] ' to '* task: :'" in {
|
||||
val before = "- [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual "* task: : aaaa"
|
||||
}
|
||||
|
||||
"convert ' - [ ] ' to ' * task: :'" in {
|
||||
val before = " - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task: : aaaa"
|
||||
}
|
||||
|
||||
"convert only first '- [ ] '" in {
|
||||
val before = " - [ ] aaaa - [ ] bbb"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task: : aaaa - [ ] bbb"
|
||||
}
|
||||
|
||||
"convert '- [x] ' to '* task:x:'" in {
|
||||
val before = " - [x] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task:x: aaaa"
|
||||
}
|
||||
|
||||
"convert multi lines" in {
|
||||
val before = """
|
||||
tasks
|
||||
- [x] aaaa
|
||||
- [ ] bbb
|
||||
"""
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual """
|
||||
tasks
|
||||
* task:x: aaaa
|
||||
* task: : bbb
|
||||
"""
|
||||
}
|
||||
|
||||
"no convert if inserted before '- [ ] '" in {
|
||||
val before = " a - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " a - [ ] aaaa"
|
||||
}
|
||||
|
||||
"no convert '- [] '" in {
|
||||
val before = " - [] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " - [] aaaa"
|
||||
}
|
||||
|
||||
"no convert '- [ ]a'" in {
|
||||
val before = " - [ ]a aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " - [ ]a aaaa"
|
||||
}
|
||||
|
||||
"no convert '-[ ] '" in {
|
||||
val before = " -[ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " -[ ] aaaa"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
65
src/test/scala/gitbucket/core/view/HelpersSpec.scala
Normal file
65
src/test/scala/gitbucket/core/view/HelpersSpec.scala
Normal file
@@ -0,0 +1,65 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import org.scalatest.FunSpec
|
||||
import org.scalatest.mock.MockitoSugar
|
||||
|
||||
class HelpersSpec extends FunSpec with MockitoSugar {
|
||||
|
||||
private implicit val context = mock[Context]
|
||||
private val repository = mock[RepositoryInfo]
|
||||
|
||||
import helpers._
|
||||
|
||||
describe("detect and render links") {
|
||||
|
||||
it("should pass identical string when no link is present") {
|
||||
val before = "Description"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == before)
|
||||
}
|
||||
|
||||
it("should convert a single link") {
|
||||
val before = "http://example.com"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """<a href="http://example.com">http://example.com</a>""")
|
||||
}
|
||||
|
||||
it("should convert a single link within trailing text") {
|
||||
val before = "Example Project. http://example.com"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """Example Project. <a href="http://example.com">http://example.com</a>""")
|
||||
}
|
||||
|
||||
it("should convert a mulitple links within text") {
|
||||
val before = "Example Project. http://example.com. (See also https://github.com/)"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """Example Project. <a href="http://example.com">http://example.com</a>. (See also <a href="https://github.com/">https://github.com/</a>)""")
|
||||
}
|
||||
|
||||
it("should properly escape html metacharacters") {
|
||||
val before = "<>&"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """<>&""")
|
||||
}
|
||||
|
||||
it("should escape html metacharacters adjacent to a link") {
|
||||
val before = "<http://example.com>"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """<<a href="http://example.com">http://example.com</a>>""")
|
||||
}
|
||||
|
||||
it("should stop link recognition at a metacharacter") {
|
||||
val before = "http://exa<mple.com"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """<a href="http://exa">http://exa</a><mple.com""")
|
||||
}
|
||||
|
||||
it("should make sure there are no double quotes in the href attribute") {
|
||||
val before = "http://exa\"mple.com"
|
||||
val after = detectAndRenderLinks(before, repository)
|
||||
assert(after == """<a href="http://exa"mple.com">http://exa"mple.com</a>""")
|
||||
}
|
||||
}
|
||||
}
|
||||
93
src/test/scala/gitbucket/core/view/MarkdownSpec.scala
Normal file
93
src/test/scala/gitbucket/core/view/MarkdownSpec.scala
Normal file
@@ -0,0 +1,93 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class MarkdownSpec extends FunSpec {
|
||||
|
||||
import Markdown._
|
||||
|
||||
describe("generateAnchorName") {
|
||||
it("should convert whitespace characters to hyphens") {
|
||||
val before = "foo bar baz"
|
||||
val after = generateAnchorName(before)
|
||||
assert(after == "foo-bar-baz")
|
||||
}
|
||||
|
||||
it("should normalize characters with diacritics") {
|
||||
val before = "Dónde estará mi vida"
|
||||
val after = generateAnchorName(before)
|
||||
assert(after == "do%cc%81nde-estara%cc%81-mi-vida")
|
||||
}
|
||||
|
||||
it("should omit special characters") {
|
||||
val before = "foo!bar@baz>9000"
|
||||
val after = generateAnchorName(before)
|
||||
assert(after == "foo%21bar%40baz%3e9000")
|
||||
}
|
||||
}
|
||||
|
||||
describe("escapeTaskList") {
|
||||
it("should convert '- [ ] ' to '* task: :'") {
|
||||
val before = "- [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == "* task: : aaaa")
|
||||
}
|
||||
|
||||
it("should convert ' - [ ] ' to ' * task: :'") {
|
||||
val before = " - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " * task: : aaaa")
|
||||
}
|
||||
|
||||
it("should convert only first '- [ ] '") {
|
||||
val before = " - [ ] aaaa - [ ] bbb"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " * task: : aaaa - [ ] bbb")
|
||||
}
|
||||
|
||||
it("should convert '- [x] ' to '* task:x:'") {
|
||||
val before = " - [x] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " * task:x: aaaa")
|
||||
}
|
||||
|
||||
it("should convert multi lines") {
|
||||
val before = """
|
||||
tasks
|
||||
- [x] aaaa
|
||||
- [ ] bbb
|
||||
"""
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == """
|
||||
tasks
|
||||
* task:x: aaaa
|
||||
* task: : bbb
|
||||
""")
|
||||
}
|
||||
|
||||
it("should not convert if inserted before '- [ ] '") {
|
||||
val before = " a - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " a - [ ] aaaa")
|
||||
}
|
||||
|
||||
it("should not convert '- [] '") {
|
||||
val before = " - [] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " - [] aaaa")
|
||||
}
|
||||
|
||||
it("should not convert '- [ ]a'") {
|
||||
val before = " - [ ]a aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " - [ ]a aaaa")
|
||||
}
|
||||
|
||||
it("should not convert '-[ ] '") {
|
||||
val before = " -[ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
assert(after == " -[ ] aaaa")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import gitbucket.core.util.ControlUtil
|
||||
import org.specs2.mutable._
|
||||
import ControlUtil._
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class PaginationSpec extends Specification {
|
||||
class PaginationSpec extends FunSpec {
|
||||
|
||||
"max" should {
|
||||
"return max page number" in {
|
||||
describe("max") {
|
||||
it("should return max page number") {
|
||||
val pagination = Pagination(1, 100, 10, 6)
|
||||
pagination.max mustEqual 10
|
||||
assert(pagination.max == 10)
|
||||
}
|
||||
}
|
||||
|
||||
"omitLeft and omitRight" should {
|
||||
"return true if pagination links at their side will be omitted" in {
|
||||
describe("omitLeft and omitRight") {
|
||||
it("should return true if pagination links at their side will be omitted") {
|
||||
defining(Pagination(1, 100, 10, 6)){ pagination =>
|
||||
pagination.omitLeft mustEqual false
|
||||
pagination.omitRight mustEqual true
|
||||
assert(pagination.omitLeft == false)
|
||||
assert(pagination.omitRight == true)
|
||||
}
|
||||
defining(Pagination(9, 100, 10, 6)){ pagination =>
|
||||
pagination.omitLeft mustEqual true
|
||||
pagination.omitRight mustEqual false
|
||||
assert(pagination.omitLeft == true)
|
||||
assert(pagination.omitRight == false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"visibleFor" should {
|
||||
"return true for visible pagination links" in {
|
||||
describe("visibleFor") {
|
||||
it("should return true for visible pagination links") {
|
||||
defining(Pagination(1, 100, 10, 6)){ pagination =>
|
||||
pagination.visibleFor(1) mustEqual true
|
||||
pagination.visibleFor(2) mustEqual true
|
||||
pagination.visibleFor(3) mustEqual true
|
||||
pagination.visibleFor(4) mustEqual true
|
||||
pagination.visibleFor(5) mustEqual true
|
||||
pagination.visibleFor(6) mustEqual false
|
||||
pagination.visibleFor(7) mustEqual false
|
||||
pagination.visibleFor(8) mustEqual false
|
||||
pagination.visibleFor(9) mustEqual false
|
||||
pagination.visibleFor(10) mustEqual true
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == true)
|
||||
assert(pagination.visibleFor(3) == true)
|
||||
assert(pagination.visibleFor(4) == true)
|
||||
assert(pagination.visibleFor(5) == true)
|
||||
assert(pagination.visibleFor(6) == false)
|
||||
assert(pagination.visibleFor(7) == false)
|
||||
assert(pagination.visibleFor(8) == false)
|
||||
assert(pagination.visibleFor(9) == false)
|
||||
assert(pagination.visibleFor(10) == true)
|
||||
}
|
||||
defining(Pagination(5, 100, 10, 6)){ pagination =>
|
||||
pagination.visibleFor(1) mustEqual true
|
||||
pagination.visibleFor(2) mustEqual false
|
||||
pagination.visibleFor(3) mustEqual false
|
||||
pagination.visibleFor(4) mustEqual true
|
||||
pagination.visibleFor(5) mustEqual true
|
||||
pagination.visibleFor(6) mustEqual true
|
||||
pagination.visibleFor(7) mustEqual false
|
||||
pagination.visibleFor(8) mustEqual false
|
||||
pagination.visibleFor(9) mustEqual false
|
||||
pagination.visibleFor(10) mustEqual true
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == false)
|
||||
assert(pagination.visibleFor(3) == false)
|
||||
assert(pagination.visibleFor(4) == true)
|
||||
assert(pagination.visibleFor(5) == true)
|
||||
assert(pagination.visibleFor(6) == true)
|
||||
assert(pagination.visibleFor(7) == false)
|
||||
assert(pagination.visibleFor(8) == false)
|
||||
assert(pagination.visibleFor(9) == false)
|
||||
assert(pagination.visibleFor(10) == true)
|
||||
}
|
||||
defining(Pagination(8, 100, 10, 6)){ pagination =>
|
||||
pagination.visibleFor(1) mustEqual true
|
||||
pagination.visibleFor(2) mustEqual false
|
||||
pagination.visibleFor(3) mustEqual false
|
||||
pagination.visibleFor(4) mustEqual false
|
||||
pagination.visibleFor(5) mustEqual false
|
||||
pagination.visibleFor(6) mustEqual true
|
||||
pagination.visibleFor(7) mustEqual true
|
||||
pagination.visibleFor(8) mustEqual true
|
||||
pagination.visibleFor(9) mustEqual true
|
||||
pagination.visibleFor(10) mustEqual true
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == false)
|
||||
assert(pagination.visibleFor(3) == false)
|
||||
assert(pagination.visibleFor(4) == false)
|
||||
assert(pagination.visibleFor(5) == false)
|
||||
assert(pagination.visibleFor(6) == true)
|
||||
assert(pagination.visibleFor(7) == true)
|
||||
assert(pagination.visibleFor(8) == true)
|
||||
assert(pagination.visibleFor(9) == true)
|
||||
assert(pagination.visibleFor(10) == true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user