test: Journal-shaped records in the hreflang test

TestAlternates also runs on a record shaped as the Journal descriptors
describe one: every enabled locale present, the untranslated one with
URL "" and the default locale's title, description and word count; it
answers no hreflang for that locale.
This commit is contained in:
Jakub Zych
2026-11-04 23:28:15 +01:00
parent e2af5b44c8
commit 2a288a9570

View File

@@ -54,6 +54,31 @@ func TestAlternates(t *testing.T) {
if got := Alternates(site, nil, "pl"); len(got) != 0 {
t.Fatal("no record, no alternates")
}
// G3: a Journal-shaped record, as the Journal descriptors describe one
// (P33-64): every enabled locale in sort order, the untranslated de
// with URL "" and the default locale's title, description and word
// count. de gets no hreflang.
words := 120
journalShaped := &pact.ContentRecord{Locales: []pact.ContentLocale{
{Locale: "pl", URL: "/blog/grzyby", Title: "Grzyby", Description: "O grzybach", Words: &words},
{Locale: "en", URL: "/en/blog/mushrooms", Title: "Mushrooms", Description: "About mushrooms", Words: &words},
{Locale: "de", URL: "", Title: "Grzyby", Description: "O grzybach", Words: &words},
}}
got = Alternates(site, journalShaped, "pl")
want = []Alternate{
{Hreflang: "pl", URL: site + "/blog/grzyby"},
{Hreflang: "en", URL: site + "/en/blog/mushrooms"},
{Hreflang: "x-default", URL: site + "/blog/grzyby"},
}
if len(got) != len(want) {
t.Fatalf("Journal-shaped alternates = %+v", got)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("Journal-shaped alternate %d = %+v, want %+v", i, got[i], want[i])
}
}
}
// TestOGLocale pins og:locale without configuration: the default table,