test(15-04): complete PHPUnit map, migrations, FormatHTML, and search-gate tests

Named JOURNAL-001/002 fillable, FormatHTML unsafe tags, rollback/remigrate, RSS/categories/tags/media, and TestSearchGateOff with zero Typesense HTTP.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-06 19:18:53 +02:00
parent c5b44b6a5d
commit d09edde080
12 changed files with 833 additions and 80 deletions

View File

@@ -4,13 +4,10 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"io"
"mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"sync/atomic"
"testing"
"time"
@@ -96,48 +93,6 @@ func TestJournal006MediaUpload(t *testing.T) {
}
}
func TestSearchGateOff(t *testing.T) {
var hits atomic.Int64
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hits.Add(1)
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(w, `{}`)
}))
t.Cleanup(srv.Close)
u, err := url.Parse(srv.URL)
if err != nil {
t.Fatal(err)
}
env := newPostsEnv(t,
"SUMMER_SEARCH__DRIVER=typesense",
"SUMMER_SEARCH__TYPESENSE__API_KEY=test-only-typesense-key",
"SUMMER_SEARCH__TYPESENSE__HOST="+u.Hostname(),
"SUMMER_SEARCH__TYPESENSE__PORT="+u.Port(),
"SUMMER_SEARCH__TYPESENSE__PROTOCOL="+u.Scheme,
)
past := time.Now().UTC().Add(-time.Hour)
post := models.Post{
Title: "Published searchable",
Slug: "published-searchable",
Content: "hello search gate",
Published: true,
PublishedAt: &past,
}
if err := env.gdb.Create(&post).Error; err != nil {
t.Fatal(err)
}
if hits.Load() != 0 {
t.Fatalf("Typesense HTTP hits = %d, want 0", hits.Load())
}
if post.ShouldBeSearchable() {
t.Fatal("ShouldBeSearchable true with default search_use_typesense")
}
draft := models.Post{Title: "Draft", Slug: "draft-search", Content: "x", Published: false}
if draft.ShouldBeSearchable() {
t.Fatal("unpublished ShouldBeSearchable must be false")
}
}
func TestJournalRSS(t *testing.T) {
env := newPostsEnv(t)
title := "Acme Journal"
@@ -207,6 +162,16 @@ func TestJournalRSS(t *testing.T) {
t.Fatal("rss_include_content false still emitted content:encoded")
}
if err := env.gdb.Model(&models.Settings{}).Where("id = 1").Updates(map[string]any{
"rss_include_content": true,
}).Error; err != nil {
t.Fatal(err)
}
withContent := env.call(t, http.MethodGet, "/_journal/api/v1/rss", "", nil)
if !strings.Contains(withContent.Body.String(), "content:encoded") {
t.Fatalf("rss_include_content true missing content:encoded: %s", withContent.Body.String())
}
if err := env.gdb.Model(&models.Settings{}).Where("id = 1").Update("rss_enabled", false).Error; err != nil {
t.Fatal(err)
}