- ConvertContentH1 and ConvertTranslationH1 for post bodies and category pillar text - SetImageAlt with several matches, repeated alt attributes and markup that only looks like an img - the content facts outline, images, decorative images and embeds - the related-posts mode and count
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package classes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/compass"
|
|
)
|
|
|
|
// TestReadRelatedSettings pins the related-posts config: the category mode
|
|
// and 3 by default; "scored" in any case turns scoring on; the count
|
|
// clamped to 3..6, 0 or a non-number falling back to 3. The scoring and
|
|
// its ties by the newest post are TestJournalAPIMatrix's on the database.
|
|
func TestReadRelatedSettings(t *testing.T) {
|
|
if s := ReadRelatedSettings(nil); s.Mode != RelatedModeCategory || s.Count != 3 || s.Scored() {
|
|
t.Fatalf("nil config = %+v", s)
|
|
}
|
|
for _, tc := range []struct {
|
|
mode string
|
|
count any
|
|
want RelatedSettings
|
|
}{
|
|
{"", nil, RelatedSettings{RelatedModeCategory, 3}},
|
|
{" Scored ", 5, RelatedSettings{RelatedModeScored, 5}},
|
|
{"scored", 1, RelatedSettings{RelatedModeScored, 3}},
|
|
{"scored", 99, RelatedSettings{RelatedModeScored, 6}},
|
|
{"category", 4, RelatedSettings{RelatedModeCategory, 4}},
|
|
{"tags", 0, RelatedSettings{RelatedModeCategory, 3}},
|
|
{"scored", "many", RelatedSettings{RelatedModeScored, 3}},
|
|
} {
|
|
cfg, err := compass.Open(compass.Options{Dir: t.TempDir()})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tc.mode != "" {
|
|
_ = cfg.Set(RelatedModeKey, tc.mode)
|
|
}
|
|
if tc.count != nil {
|
|
_ = cfg.Set(RelatedCountKey, tc.count)
|
|
}
|
|
if got := ReadRelatedSettings(cfg); got != tc.want {
|
|
t.Errorf("mode %q count %v = %+v, want %+v", tc.mode, tc.count, got, tc.want)
|
|
}
|
|
}
|
|
if relatedTagPoints != 2 || relatedCategoryPoints != 1 {
|
|
t.Fatal("a shared tag is 2 points, a shared category 1")
|
|
}
|
|
}
|