- schema: types per kind, @id links, every node kind, the publisher and local business, every validator rule, custom JSON-LD caps and merge - crawl: HTML parse, each check's positive and negative case, fix routes with the fitting tool, the rendered comparison, allowRequest, resolverRules and NewRenderer - pagination, alternates and x-default, primary parents, the filter's addresses, registry paths and fields, auto-link addresses
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package classes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// TestLangTag pins the language tags of locale codes.
|
|
func TestLangTag(t *testing.T) {
|
|
for in, want := range map[string]string{"pl": "pl", "PL": "pl", "pt_BR": "pt-BR", "pt-br": "pt-BR", " en-gb ": "en-GB", "de-": "de", "": ""} {
|
|
if got := LangTag(in); got != want {
|
|
t.Errorf("LangTag(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestAlternates pins D-55 to D-57: each translated locale with its
|
|
// absolute URL (the page itself included), x-default on the default
|
|
// locale's URL, none for one locale, a locale without an address or a
|
|
// repeated locale absent, and no x-default when the default locale is not
|
|
// translated.
|
|
func TestAlternates(t *testing.T) {
|
|
const site = "https://example.test"
|
|
rec := &pact.ContentRecord{Locales: []pact.ContentLocale{
|
|
{Locale: "pl", URL: "/blog/grzyby"},
|
|
{Locale: "en", URL: "/en/blog/mushrooms"},
|
|
{Locale: "de", URL: " "},
|
|
{Locale: "pl", URL: "/blog/again"},
|
|
{Locale: "pt_BR", URL: "https://example.test/pt/cogumelos"},
|
|
}}
|
|
got := Alternates(site, rec, "pl")
|
|
want := []Alternate{
|
|
{Hreflang: "pl", URL: site + "/blog/grzyby"},
|
|
{Hreflang: "en", URL: site + "/en/blog/mushrooms"},
|
|
{Hreflang: "pt-BR", URL: site + "/pt/cogumelos"},
|
|
{Hreflang: "x-default", URL: site + "/blog/grzyby"},
|
|
}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("alternates = %+v", got)
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Fatalf("alternate %d = %+v, want %+v", i, got[i], want[i])
|
|
}
|
|
}
|
|
if noDefault := Alternates(site, rec, "fr"); len(noDefault) != 3 || noDefault[2].Hreflang == "x-default" {
|
|
t.Fatalf("without the default locale = %+v", noDefault)
|
|
}
|
|
one := &pact.ContentRecord{Locales: []pact.ContentLocale{{Locale: "pl", URL: "/a"}, {Locale: "en", URL: ""}}}
|
|
if got := Alternates(site, one, "pl"); got == nil || len(got) != 0 {
|
|
t.Fatalf("one locale = %+v, want []", got)
|
|
}
|
|
if got := Alternates(site, nil, "pl"); len(got) != 0 {
|
|
t.Fatal("no record, no alternates")
|
|
}
|
|
}
|
|
|
|
// TestOGLocale pins og:locale without configuration: the default table,
|
|
// the region form and the doubled language.
|
|
func TestOGLocale(t *testing.T) {
|
|
s := &Service{}
|
|
for in, want := range map[string]string{"pl": "pl_PL", "en": "en_US", "de": "de_DE", "pt_BR": "pt_BR", "fr": "fr_FR", "": ""} {
|
|
if got := s.OGLocale(in); got != want {
|
|
t.Errorf("OGLocale(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|