func TestListPage(t *testing.T) {
	r := httptest.NewRequest("GET", "/pages", nil)
	w := httptest.NewRecorder()
	err := resource.AddUserSessionCookie(w, r, 1)
	if err != nil {
		t.Fatalf("pageactions: error setting session %s", err)
	}
	err = HandleIndex(w, r)
	if err != nil || w.Code != http.StatusOK {
		t.Fatalf("pageactions: error handling HandleIndex %s", err)
	}
	pattern := "data-table-head"
	if !strings.Contains(w.Body.String(), pattern) {
		t.Fatalf("pageactions: unexpected response for HandleIndex expected:%s got:%s", pattern, w.Body.String())
	}
}
Test GET /pages
package pageactions
import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strings"
	"testing"
	"github.com/fragmenta/mux"
	"github.com/fragmenta/query"
	"github.com/fragmenta/fragmenta-cms/src/lib/resource"
	"github.com/fragmenta/fragmenta-cms/src/pages"
)
var names = []string{"foo", "bar"}
func TestSetup(t *testing.T) {
	err := resource.SetupTestDatabase(3)
	if err != nil {
		fmt.Printf("pages: Setup db failed %s", err)
	}
	resource.SetupAuthorisation()
	resource.SetupView(3)
	router := mux.New()
	mux.SetDefault(router)
	router.Add("/pages", nil)
	router.Add("/pages/create", nil)
	router.Add("/pages/create", nil).Post()
	router.Add("/pages/login", nil)
	router.Add("/pages/login", nil).Post()
	router.Add("/pages/login", nil).Post()
	router.Add("/pages/logout", nil).Post()
	router.Add("/pages/{id:\\d+}/update", nil)
	router.Add("/pages/{id:\\d+}/update", nil).Post()
	router.Add("/pages/{id:\\d+}/destroy", nil).Post()
	router.Add("/pages/{id:\\d+}", nil)
	query.ExecSQL("delete from pages;")
	query.ExecSQL("ALTER SEQUENCE pages_id_seq RESTART WITH 1;")
}
func TestShowCreatePage(t *testing.T) {
	r := httptest.NewRequest("GET", "/pages/create", nil)
	w := httptest.NewRecorder()
	err := resource.AddUserSessionCookie(w, r, 1)
	if err != nil {
		t.Fatalf("pageactions: error setting session %s", err)
	}
	err = HandleCreateShow(w, r)
	if err != nil || w.Code != http.StatusOK {
		t.Fatalf("pageactions: error handling HandleCreateShow %s", err)
	}
	pattern := "resource-update-form"
	if !strings.Contains(w.Body.String(), pattern) {
		t.Fatalf("pageactions: unexpected response for HandleCreateShow expected:%s got:%s", pattern, w.Body.String())
	}
}
func TestCreatePage(t *testing.T) {
	form := url.Values{}
	form.Add("name", names[0])
	form.Add("url", "/foo")
	body := strings.NewReader(form.Encode())
	r := httptest.NewRequest("POST", "/pages/create", body)
	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	w := httptest.NewRecorder()
	err := resource.AddUserSessionCookie(w, r, 1)
	if err != nil {
		t.Fatalf("pageactions: error setting session %s", err)
	}
	err = HandleCreate(w, r)
	if err != nil {
		t.Fatalf("pageactions: error handling HandleCreate %s", err)
	}
	if w.Code != http.StatusFound {
		t.Fatalf("pageactions: unexpected response code for HandleCreate expected:%d got:%d", http.StatusFound, w.Code)
	}
	allPage, err := pages.FindAll(pages.Query().Order("id desc"))
	if err != nil || len(allPage) == 0 {
		t.Fatalf("pageactions: error finding created page %s", err)
	}
	newPage := allPage[0]
	if newPage.ID != 1 || newPage.Name != names[0] {
		t.Fatalf("pageactions: error with created page values: %v %s", newPage.ID, newPage.Name)
	}
}