2017-05-02 06:19:55 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-06-17 10:19:45 +05:30
|
|
|
"testing"
|
2017-05-02 06:19:55 +05:30
|
|
|
|
2017-05-07 20:10:31 +05:30
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-06-17 10:19:45 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
2017-05-02 06:19:55 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
type HtmlDoc struct {
|
2017-05-07 20:10:31 +05:30
|
|
|
doc *goquery.Document
|
2017-05-02 06:19:55 +05:30
|
|
|
}
|
|
|
|
|
2017-06-17 10:19:45 +05:30
|
|
|
func NewHtmlParser(t *testing.T, content []byte) *HtmlDoc {
|
2017-05-07 20:10:31 +05:30
|
|
|
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
|
2017-06-17 10:19:45 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
return &HtmlDoc{doc: doc}
|
2017-05-02 06:19:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (doc *HtmlDoc) GetInputValueById(id string) string {
|
2017-05-07 20:10:31 +05:30
|
|
|
text, _ := doc.doc.Find("#" + id).Attr("value")
|
|
|
|
return text
|
2017-05-02 06:19:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (doc *HtmlDoc) GetInputValueByName(name string) string {
|
2017-05-07 20:10:31 +05:30
|
|
|
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
|
|
|
return text
|
2017-05-02 06:19:55 +05:30
|
|
|
}
|
2017-06-17 10:19:45 +05:30
|
|
|
|
|
|
|
func (doc *HtmlDoc) GetCSRF() string {
|
|
|
|
return doc.GetInputValueByName("_csrf")
|
|
|
|
}
|