- POST /_journal/api/v1/images/alt {dry_run, changes} sets alt on the
matching img of default or translated content through the tokenizer,
all or nothing (422), with a RecordSaved per changed post
- MCP journal_get_settings, journal_update_settings, journal_fix_headings
(manage_settings) and journal_set_image_alt (access_posts, destructive)
- journal:fix-headings help names its output and the refusal
23 lines
1.1 KiB
Go
23 lines
1.1 KiB
Go
package classes
|
|
|
|
import "testing"
|
|
|
|
// TestSetImageAlt pins the alt rewrite: only the matching img tag is
|
|
// rewritten from its token, the alt is escaped, a missing alt is added and
|
|
// every other byte is kept (T-33-04).
|
|
func TestSetImageAlt(t *testing.T) {
|
|
const doc = `<p class="a">x & y</p><img src="https://cdn.example.test/a.jpg?x=1&y=2"><img src="b.jpg" alt="old"/>`
|
|
out, n, old := SetImageAlt(doc, "https://cdn.example.test/a.jpg?x=1&y=2", `Lion's "mane" <b>`)
|
|
want := `<p class="a">x & y</p><img src="https://cdn.example.test/a.jpg?x=1&y=2" alt="Lion's "mane" <b>"><img src="b.jpg" alt="old"/>`
|
|
if out != want || n != 1 || old != nil {
|
|
t.Fatalf("SetImageAlt = %q, %d, %v; want %q, 1, nil", out, n, old, want)
|
|
}
|
|
out, n, old = SetImageAlt(doc, "b.jpg", "")
|
|
if out != `<p class="a">x & y</p><img src="https://cdn.example.test/a.jpg?x=1&y=2"><img src="b.jpg" alt=""/>` || n != 1 || old == nil || *old != "old" {
|
|
t.Fatalf("decorative = %q, %d, %v", out, n, old)
|
|
}
|
|
if out, n, _ := SetImageAlt(doc, "missing.jpg", "x"); out != doc || n != 0 {
|
|
t.Fatalf("missing = %q, %d", out, n)
|
|
}
|
|
}
|