- XML escaping and namespaces, no priority, the image cap and file names - News window and cap, sources and languages, the publication name - IndexNow batches of 10 000, answer outcomes, keys and the host filter - HTML sitemap group order, tree order and paging - default slugs, the effective type setting, lastmod config, slot edges
49 lines
2.2 KiB
Go
49 lines
2.2 KiB
Go
package classes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
|
"git.golem15.com/golem15/summercms/modules/lagoon"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// TestDefaultSlug pins the default group slug: the last segment of the
|
|
// key, lower-cased, letters and digits only, in plural form.
|
|
func TestDefaultSlug(t *testing.T) {
|
|
for key, want := range map[string]string{
|
|
"journal-post": "posts", "journal-category": "categories", "seo-page": "pages", "journal-tag": "tags",
|
|
"journal-author": "authors", "acme.news": "news", "acme_day": "days", "shop-boxes": "boxes", "Acme-Story": "stories",
|
|
"x-y": "ys", "a-key": "keys", "": "pages", "acme-": "pages", "acme-żółw": "ws",
|
|
} {
|
|
if got := DefaultSlug(key); got != want {
|
|
t.Errorf("DefaultSlug(%q) = %q, want %q", key, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestEffectiveType pins a content type's setting: listed under its
|
|
// default slug without a saved row; the saved include, slug and headings
|
|
// otherwise, with an invalid saved slug falling back to the default.
|
|
func TestEffectiveType(t *testing.T) {
|
|
typ := pact.MenuItemType{Key: "journal-post", Label: "Posts"}
|
|
if got := EffectiveType(typ, nil); got.Key != "journal-post" || got.Label != "Posts" || !got.Include || got.Slug != "posts" || got.Titles != nil {
|
|
t.Fatalf("without a row = %+v", got)
|
|
}
|
|
rows := map[string]models.TypeSetting{"journal-post": {TypeKey: "journal-post", Include: false, Slug: "articles", Titles: lagoon.Jsonable[map[string]string]{Data: map[string]string{"pl": "Artykuły"}, Valid: true}}}
|
|
if got := EffectiveType(typ, rows); got.Include || got.Slug != "articles" || got.Titles["pl"] != "Artykuły" {
|
|
t.Fatalf("with a row = %+v", got)
|
|
}
|
|
rows["journal-post"] = models.TypeSetting{TypeKey: "journal-post", Include: true, Slug: "Bad Slug"}
|
|
if got := EffectiveType(typ, rows); !got.Include || got.Slug != "posts" || got.Titles != nil {
|
|
t.Fatalf("with an invalid slug = %+v", got)
|
|
}
|
|
}
|
|
|
|
// TestReservedSlugs pins the slugs the image and News files own.
|
|
func TestReservedSlugs(t *testing.T) {
|
|
if !ReservedSlugs["images"] || !ReservedSlugs["news"] || len(ReservedSlugs) != 2 || ReservedSlugs["pages"] {
|
|
t.Fatalf("ReservedSlugs = %v", ReservedSlugs)
|
|
}
|
|
}
|