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

html_helper.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. "bytes"
  7. "testing"
  8. "github.com/PuerkitoBio/goquery"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. // HTMLDoc struct
  12. type HTMLDoc struct {
  13. doc *goquery.Document
  14. }
  15. // NewHTMLParser parse html file
  16. func NewHTMLParser(t testing.TB, content []byte) *HTMLDoc {
  17. doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
  18. assert.NoError(t, err)
  19. return &HTMLDoc{doc: doc}
  20. }
  21. // GetInputValueByID for get input value by id
  22. func (doc *HTMLDoc) GetInputValueByID(id string) string {
  23. text, _ := doc.doc.Find("#" + id).Attr("value")
  24. return text
  25. }
  26. // GetInputValueByName for get input value by name
  27. func (doc *HTMLDoc) GetInputValueByName(name string) string {
  28. text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
  29. return text
  30. }
  31. // GetCSRF for get CSRC token value from input
  32. func (doc *HTMLDoc) GetCSRF() string {
  33. return doc.GetInputValueByName("_csrf")
  34. }