github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/hugolib/integration_test.go (about)

     1  // Copyright 2022 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_test
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/gohugoio/hugo/hugolib"
    20  )
    21  
    22  // Issue 9073
    23  func TestPageTranslationsMap(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	files := `
    27  -- config.toml --
    28  baseURL = 'https://example.org/'
    29  title = 'Issue-9073'
    30  defaultContentLanguageInSubdir = true
    31  
    32  [taxonomies]
    33  tag = 'tags'
    34  
    35  [languages.en]
    36  contentDir = 'content/en'
    37  weight = 1
    38  disableKinds = ['RSS','sitemap']
    39  
    40  [languages.de]
    41  contentDir = 'content/de'
    42  weight = 2
    43  disableKinds = ['home', 'page', 'section', 'taxonomy', 'term','RSS','sitemap']
    44  -- content/de/posts/p1.md --
    45  ---
    46  title: P1
    47  tags: ['T1']
    48  ---
    49  -- content/en/posts/p1.md --
    50  ---
    51  title: P1
    52  tags: ['T1']
    53  ---
    54  -- layouts/_default/single.html --
    55  <ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul>
    56  -- layouts/_default/list.html --
    57  <ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul>
    58  	`
    59  
    60  	b := hugolib.NewIntegrationTestBuilder(
    61  		hugolib.IntegrationTestConfig{
    62  			T:           t,
    63  			TxtarString: files,
    64  		},
    65  	)
    66  	b.Build()
    67  
    68  	// Kind home
    69  	b.AssertFileContent("public/en/index.html",
    70  		"<ul><li>Issue-9073-en</li></ul>",
    71  	)
    72  	// Kind section
    73  	b.AssertFileContent("public/en/posts/index.html",
    74  		"<ul><li>Posts-en</li></ul>",
    75  	)
    76  	// Kind page
    77  	b.AssertFileContent("public/en/posts/p1/index.html",
    78  		"<ul><li>P1-en</li></ul>",
    79  	)
    80  	// Kind taxonomy
    81  	b.AssertFileContent("public/en/tags/index.html",
    82  		"<ul><li>Tags-en</li></ul>",
    83  	)
    84  	// Kind term
    85  	b.AssertFileContent("public/en/tags/t1/index.html",
    86  		"<ul><li>T1-en</li></ul>",
    87  	)
    88  
    89  }