github.com/elmarschill/hugo_sample@v0.47.1/hugolib/minify_publisher_test.go (about)

     1  // Copyright 2018 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  	"testing"
    18  
    19  	"github.com/spf13/viper"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestMinifyPublisher(t *testing.T) {
    25  	t.Parallel()
    26  	assert := require.New(t)
    27  
    28  	v := viper.New()
    29  	v.Set("minify", true)
    30  	v.Set("baseURL", "https://example.org/")
    31  
    32  	htmlTemplate := `
    33  <!DOCTYPE html>
    34  <html lang="en">
    35  <head>
    36  	<meta charset="utf-8">
    37  	<title>HTML5 boilerplate – all you really need…</title>
    38  	<link rel="stylesheet" href="css/style.css">
    39  	<!--[if IE]>
    40  		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    41  	<![endif]-->
    42  </head>
    43  
    44  <body id="home">
    45  
    46  	<h1>{{ .Page.Title }}</h1>
    47  
    48  </body>
    49  </html>
    50  `
    51  
    52  	b := newTestSitesBuilder(t)
    53  	b.WithViper(v).WithContent("page.md", pageWithAlias)
    54  	b.WithTemplates("_default/list.html", htmlTemplate, "_default/single.html", htmlTemplate, "alias.html", htmlTemplate)
    55  	b.CreateSites().Build(BuildCfg{})
    56  
    57  	assert.Equal(1, len(b.H.Sites))
    58  	require.Len(t, b.H.Sites[0].RegularPages, 1)
    59  
    60  	// Check minification
    61  	// HTML
    62  	b.AssertFileContent("public/page/index.html", "<!doctype html><html lang=en><head><meta charset=utf-8><title>HTML5 boilerplate – all you really need…</title><link rel=stylesheet href=css/style.css></head><body id=home><h1>Has Alias</h1></body></html>")
    63  	// HTML alias. Note the custom template which does no redirect.
    64  	b.AssertFileContent("public/foo/bar/index.html", "<!doctype html><html lang=en><head><meta charset=utf-8><title>HTML5 boilerplate ")
    65  
    66  	// RSS
    67  	b.AssertFileContent("public/index.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel><title/><link>https://example.org/</link>")
    68  
    69  	// Sitemap
    70  	b.AssertFileContent("public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><url><loc>https://example.org/</loc><priority>0</priority></url><url>")
    71  }