github.com/neohugo/neohugo@v0.123.8/hugolib/rss_test.go (about)

     1  // Copyright 2019 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package hugolib
    15  
    16  import (
    17  	"path/filepath"
    18  	"strings"
    19  	"testing"
    20  
    21  	"github.com/neohugo/neohugo/deps"
    22  )
    23  
    24  func TestRSSOutput(t *testing.T) {
    25  	t.Parallel()
    26  
    27  	rssLimit := len(weightedSources) - 1
    28  
    29  	cfg, fs := newTestCfg()
    30  	cfg.Set("baseURL", "http://auth/bub/")
    31  	cfg.Set("title", "RSSTest")
    32  	cfg.Set("rssLimit", rssLimit)
    33  	th, configs := newTestHelperFromProvider(cfg, fs, t)
    34  
    35  	rssURI := "index.xml"
    36  
    37  	for _, src := range weightedSources {
    38  		writeSource(t, fs, filepath.Join("content", "sect", src[0]), src[1])
    39  	}
    40  
    41  	buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{})
    42  
    43  	// Home RSS
    44  	th.assertFileContent(filepath.Join("public", rssURI), "<?xml", "rss version", "RSSTest")
    45  	// Section RSS
    46  	th.assertFileContent(filepath.Join("public", "sect", rssURI), "<?xml", "rss version", "Sects on RSSTest")
    47  	// Taxonomy RSS
    48  	th.assertFileContent(filepath.Join("public", "categories", "hugo", rssURI), "<?xml", "rss version", "Hugo on RSSTest")
    49  
    50  	// RSS Item Limit
    51  	content := readWorkingDir(t, fs, filepath.Join("public", rssURI))
    52  	c := strings.Count(content, "<item>")
    53  	if c != rssLimit {
    54  		t.Errorf("incorrect RSS item count: expected %d, got %d", rssLimit, c)
    55  	}
    56  
    57  	// Encoded summary
    58  	th.assertFileContent(filepath.Join("public", rssURI), "<?xml", "description", "A &lt;em&gt;custom&lt;/em&gt; summary")
    59  }
    60  
    61  // Before Hugo 0.49 we set the pseudo page kind RSS on the page when output to RSS.
    62  // This had some unintended side effects, esp. when the only output format for that page
    63  // was RSS.
    64  // For the page kinds that can have multiple output formats, the Kind should be one of the
    65  // standard home, page etc.
    66  // This test has this single purpose: Check that the Kind is that of the source page.
    67  // See https://github.com/neohugo/neohugo/issues/5138
    68  func TestRSSKind(t *testing.T) {
    69  	t.Parallel()
    70  
    71  	b := newTestSitesBuilder(t)
    72  	b.WithSimpleConfigFile().WithTemplatesAdded("index.rss.xml", `RSS Kind: {{ .Kind }}`)
    73  
    74  	b.Build(BuildCfg{})
    75  
    76  	b.AssertFileContent("public/index.xml", "RSS Kind: home")
    77  }
    78  
    79  func TestRSSCanonifyURLs(t *testing.T) {
    80  	t.Parallel()
    81  
    82  	b := newTestSitesBuilder(t)
    83  	b.WithSimpleConfigFile().WithTemplatesAdded("index.rss.xml", `<rss>{{ range .Pages }}<item>{{ .Content | html }}</item>{{ end }}</rss>`)
    84  	b.WithContent("page.md", `---
    85  Title: My Page
    86  ---
    87  
    88  Figure:
    89  
    90  {{< figure src="/images/sunset.jpg" title="Sunset" >}}
    91  
    92  
    93  
    94  `)
    95  	b.Build(BuildCfg{})
    96  
    97  	b.AssertFileContent("public/index.xml", "img src=&#34;http://example.com/images/sunset.jpg")
    98  }