From 2a288a9570f4f929bb80f90519f35d6478638c9c Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Wed, 4 Nov 2026 23:28:15 +0100 Subject: [PATCH] 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. --- classes/alternates_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/classes/alternates_test.go b/classes/alternates_test.go index 79ee1ce..5928368 100644 --- a/classes/alternates_test.go +++ b/classes/alternates_test.go @@ -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,