taler-merchant-demos

Python-based Frontends for the Demonstration Web site
Log | Files | Refs | README | LICENSE

articles_test.go (1697B)


      1 package web
      2 
      3 import "testing"
      4 
      5 func TestParseArticle(t *testing.T) {
      6 	article, ok := parseArticle("en", "stable-file-name", `<h2>A &amp; B?</h2><p id="teaser">A <a href="/useful">useful</a> &amp; concise teaser.</p><p>Body.</p>`)
      7 	if !ok {
      8 		t.Fatal("article was rejected")
      9 	}
     10 	if article.Title != "A & B?" || article.Slug != "stable-file-name" {
     11 		t.Fatalf("article = %#v", article)
     12 	}
     13 	if article.Summary != "A useful & concise teaser." {
     14 		t.Fatalf("article summary = %q", article.Summary)
     15 	}
     16 }
     17 
     18 func TestArticleLocalesAndStableSlugs(t *testing.T) {
     19 	articles, err := loadArticles()
     20 	if err != nil {
     21 		t.Fatal(err)
     22 	}
     23 	if len(articles["uk"]) == 0 {
     24 		t.Fatal("Ukrainian articles were not mapped to uk")
     25 	}
     26 	if len(articles["zh_Hant"]) != 0 {
     27 		t.Fatal("articles were exposed under the unsupported zh_Hant locale")
     28 	}
     29 	expectedCounts := map[string]int{
     30 		"en": 20, "de": 18, "es": 20, "fr": 20, "it": 20,
     31 		"pt": 17, "ru": 20, "tr": 19, "uk": 15,
     32 	}
     33 	if len(articles) != len(expectedCounts) {
     34 		t.Errorf("loaded articles for %d locales, want %d", len(articles), len(expectedCounts))
     35 	}
     36 	for locale, localized := range articles {
     37 		if !supportedLocales[locale] {
     38 			t.Errorf("articles were exposed under unsupported locale %s", locale)
     39 		}
     40 		if len(localized) != expectedCounts[locale] {
     41 			t.Errorf("loaded %d articles for %s, want %d", len(localized), locale, expectedCounts[locale])
     42 		}
     43 		for slug, article := range localized {
     44 			if !selectedArticleSlugs[slug] {
     45 				t.Errorf("unselected article %q was loaded for %s", slug, locale)
     46 			}
     47 			if slug != article.Slug || slug == "" {
     48 				t.Errorf("unstable article identity for %s: key %q, article %q", locale, slug, article.Slug)
     49 			}
     50 		}
     51 	}
     52 }