- an additional address whose absolute URL a listed record already has is left out with the new reason duplicate (models.ReasonDuplicate) - the settings screen counts it under Already listed by a content type - a record left out by the filter or the type switch does not count
52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
package classes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/sm-sitemap-plugin/contract"
|
|
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
|
)
|
|
|
|
// TestMarkListedExtras pins the de-duplication of the additional
|
|
// addresses: an address a listed record has (as a path or as the same
|
|
// absolute URL) is left out as duplicate; a record left out by the filter
|
|
// or the type switch, another address and a record's other locale do not
|
|
// count; an address already left out keeps its reason.
|
|
func TestMarkListedExtras(t *testing.T) {
|
|
const site = "https://example.test"
|
|
records := []wanted{
|
|
{key: slotKey{"page", "1", "en"}, url: "/"},
|
|
{key: slotKey{"page", "2", "en"}, url: "/blog"},
|
|
{key: slotKey{"page", "3", "en"}, url: "/faq", reason: contract.ReasonNoindex},
|
|
{key: slotKey{"page", "4", "en"}, url: "/off", reason: contract.ReasonType},
|
|
{key: slotKey{"page", "5", "pl"}, url: "/pl/o-nas"},
|
|
}
|
|
extras := extraRows([]models.ExtraURL{
|
|
{URL: "/"},
|
|
{URL: site + "/blog"},
|
|
{URL: "/faq"},
|
|
{URL: "/off"},
|
|
{URL: "/kontakt"},
|
|
{URL: "/o-nas"},
|
|
{URL: "javascript:alert(1)"},
|
|
})
|
|
if len(extras) != 6 {
|
|
t.Fatalf("extraRows kept %d addresses, want 6 (the javascript: one is not allowed)", len(extras))
|
|
}
|
|
extras[5].reason = contract.ReasonNoindex
|
|
markListedExtras(records, extras, site)
|
|
want := []string{models.ReasonDuplicate, models.ReasonDuplicate, "", "", "", contract.ReasonNoindex}
|
|
for i, w := range extras {
|
|
if w.reason != want[i] {
|
|
t.Errorf("extra %s: reason %q, want %q", w.url, w.reason, want[i])
|
|
}
|
|
}
|
|
|
|
// Without a site URL the paths are compared as they are.
|
|
extras = extraRows([]models.ExtraURL{{URL: "/blog"}, {URL: site + "/blog"}})
|
|
markListedExtras(records, extras, "")
|
|
if extras[0].reason != models.ReasonDuplicate || extras[1].reason != "" {
|
|
t.Fatalf("without a site URL: %q %q, want duplicate and listed", extras[0].reason, extras[1].reason)
|
|
}
|
|
}
|