test: add form config validator and HTTP integration test

test-config: static YAML validator for post-form.md — checks that the
add-page-by-form action name, pageconfig/pagefrontmatter blocks, and all
required fields are correctly wired. Fast, no server needed. Catches the
class of bug that caused silent post failures.

test-post: end-to-end HTTP test — logs in, submits the form, verifies an
entry.md was created on disk, then cleans up. Requires GRAV_TEST_USER and
GRAV_TEST_PASS in .env (see .env.example).

  make test-config   # fast, no credentials needed
  make test-post     # full e2e, needs .env credentials
  make test          # both

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 19:57:49 +02:00
parent 706d1dee21
commit fb28f09e0c
4 changed files with 192 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Validates that post-form.md is wired correctly for the add-page-by-form plugin.
# Fast, no server needed. Catches the class of bug that caused silent post failures.
set -euo pipefail
FORM="user/pages/02.post/post-form.md"
PASS=0
FAIL=0
ERRORS=()
ok() { echo "$1"; PASS=$((PASS+1)); }
fail() { echo "$1"; FAIL=$((FAIL+1)); ERRORS+=("$1"); }
check_grep() {
local desc="$1"; local pattern="$2"
if grep -q "$pattern" "$FORM"; then ok "$desc"; else fail "$desc"; fi
}
echo ""
echo "Form config validator — $FORM"
echo "────────────────────────────────────────"
# Plugin trigger: must use add_page or addpage — NOT add-page-by-form
grep -q "add_page:\|addpage:" "$FORM" && ok "Process action is 'add_page' (plugin trigger)" \
|| fail "Process action must be 'add_page: true' — 'add-page-by-form' is not handled by the plugin"
# Config must be in frontmatter, not in the process block
check_grep "pageconfig block exists in frontmatter" "^pageconfig:"
check_grep "parent set to /tracker" "parent: '/tracker'"
check_grep "slug_field set (determines entry folder name)" "slug_field:"
check_grep "pagefrontmatter block exists in frontmatter" "^pagefrontmatter:"
check_grep "template: entry (creates entry.md filename)" "template: entry"
# Form name must stay 'new-entry' — cache-on-save plugin checks this exact string
check_grep "form name is 'new-entry' (required by cache-on-save plugin)" "name: new-entry"
# Required form fields
check_grep "title field present" "name: title"
check_grep "date field present" "name: date"
check_grep "content field present" "name: content"
check_grep "lat field present" "name: lat"
check_grep "lng field present" "name: lng"
check_grep "location_city field present" "name: location_city"
check_grep "location_country field present" "name: location_country"
echo "────────────────────────────────────────"
echo " $PASS passed, $FAIL failed"
if [ ${#ERRORS[@]} -gt 0 ]; then
echo ""
echo "Failed checks:"
for e in "${ERRORS[@]}"; do echo "$e"; done
echo ""
exit 1
fi
echo ""