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

@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"time"
@@ -185,10 +186,29 @@ func TestJournalPublicCategories(t *testing.T) {
t.Fatalf("categories row missing %s: %s", key, rec.Body.String())
}
}
empty := models.Category{Name: "Empty nest", Slug: "empty-nest"}
if err := env.gdb.Create(&empty).Error; err != nil {
t.Fatal(err)
}
hidden := env.call(t, http.MethodGet, "/_journal/api/v1/categories", "", nil)
if strings.Contains(hidden.Body.String(), "empty-nest") {
t.Fatalf("empty category listed without include_empty: %s", hidden.Body.String())
}
shown := env.call(t, http.MethodGet, "/_journal/api/v1/categories?include_empty=1", "", nil)
if shown.Code != http.StatusOK {
t.Fatalf("include_empty = %d: %s", shown.Code, shown.Body.String())
}
if !strings.Contains(shown.Body.String(), "empty-nest") {
t.Fatalf("include_empty=1 omitted empty category: %s", shown.Body.String())
}
}
func TestJournalPublicTags(t *testing.T) {
env := newPostsEnv(t)
if err := env.gdb.Create(&models.Tag{Name: "Zebra", Slug: "zebra-tag"}).Error; err != nil {
t.Fatal(err)
}
tag := models.Tag{Name: "Field notes", Slug: "field-notes"}
if err := env.gdb.Create(&tag).Error; err != nil {
t.Fatal(err)
@@ -221,6 +241,26 @@ func TestJournalPublicTags(t *testing.T) {
t.Fatalf("tags row missing %s: %s", key, rec.Body.String())
}
}
names := make([]string, 0, len(body.Data))
for _, item := range body.Data {
names = append(names, fmt.Sprint(item["name"]))
}
joined := strings.Join(names, ",")
if !strings.Contains(joined, "Field notes") || !strings.Contains(joined, "Zebra") {
t.Fatalf("tags missing expected names: %s", rec.Body.String())
}
fieldIdx, zebraIdx := -1, -1
for i, name := range names {
if name == "Field notes" {
fieldIdx = i
}
if name == "Zebra" {
zebraIdx = i
}
}
if fieldIdx < 0 || zebraIdx < 0 || fieldIdx > zebraIdx {
t.Fatalf("tags not ordered by name: %v", names)
}
}
func TestJournalFeaturedImageUnauthenticated(t *testing.T) {