2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-20 06:10:04 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package opml // import "miniflux.app/v2/internal/reader/opml"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
2017-11-20 23:35:11 +01:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
func TestSerialize(t *testing.T) {
|
|
|
|
var subscriptions SubcriptionList
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: "Category 1"})
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: "Category 2"})
|
|
|
|
|
|
|
|
output := Serialize(subscriptions)
|
|
|
|
feeds, err := Parse(bytes.NewBufferString(output))
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(feeds) != 3 {
|
|
|
|
t.Errorf("Wrong number of subscriptions: %d instead of %d", len(feeds), 3)
|
|
|
|
}
|
|
|
|
|
2017-11-20 23:35:11 +01:00
|
|
|
found := false
|
|
|
|
for _, feed := range feeds {
|
|
|
|
if feed.Title == "Feed 1" && feed.CategoryName == "Category 1" &&
|
|
|
|
feed.FeedURL == "http://example.org/feed/1" && feed.SiteURL == "http://example.org/1" {
|
|
|
|
found = true
|
|
|
|
break
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-20 23:35:11 +01:00
|
|
|
|
|
|
|
if !found {
|
|
|
|
t.Error("Serialized feed is incorrect")
|
|
|
|
}
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
2019-07-05 18:05:42 +02:00
|
|
|
|
|
|
|
func TestNormalizedCategoriesOrder(t *testing.T) {
|
|
|
|
var orderTests = []struct {
|
|
|
|
naturalOrderName string
|
|
|
|
correctOrderName string
|
|
|
|
}{
|
|
|
|
{"Category 2", "Category 1"},
|
|
|
|
{"Category 3", "Category 2"},
|
|
|
|
{"Category 1", "Category 3"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var subscriptions SubcriptionList
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: orderTests[0].naturalOrderName})
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: orderTests[1].naturalOrderName})
|
|
|
|
subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: orderTests[2].naturalOrderName})
|
|
|
|
|
2021-12-16 20:42:43 +01:00
|
|
|
feeds := convertSubscriptionsToOPML(subscriptions)
|
2019-07-05 18:05:42 +02:00
|
|
|
|
|
|
|
for i, o := range orderTests {
|
|
|
|
if feeds.Outlines[i].Text != o.correctOrderName {
|
|
|
|
t.Fatalf("need %v, got %v", o.correctOrderName, feeds.Outlines[i].Text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|