You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.4KB

  1. extern crate site;
  2. mod common;
  3. use std::env;
  4. use common::build_site;
  5. use site::Site;
  6. #[test]
  7. fn can_parse_multilingual_site() {
  8. let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
  9. path.push("test_site_i18n");
  10. let mut site = Site::new(&path, "config.toml").unwrap();
  11. site.load().unwrap();
  12. let library = site.library.read().unwrap();
  13. assert_eq!(library.pages().len(), 10);
  14. assert_eq!(library.sections().len(), 6);
  15. // default index sections
  16. let default_index_section =
  17. library.get_section(&path.join("content").join("_index.md")).unwrap();
  18. assert_eq!(default_index_section.pages.len(), 1);
  19. assert!(default_index_section.ancestors.is_empty());
  20. let fr_index_section =
  21. library.get_section(&path.join("content").join("_index.fr.md")).unwrap();
  22. assert_eq!(fr_index_section.pages.len(), 1);
  23. assert!(fr_index_section.ancestors.is_empty());
  24. // blog sections get only their own language pages
  25. let blog_path = path.join("content").join("blog");
  26. let default_blog = library.get_section(&blog_path.join("_index.md")).unwrap();
  27. assert_eq!(default_blog.subsections.len(), 0);
  28. assert_eq!(default_blog.pages.len(), 4);
  29. assert_eq!(
  30. default_blog.ancestors,
  31. vec![*library.get_section_key(&default_index_section.file.path).unwrap()]
  32. );
  33. for key in &default_blog.pages {
  34. let page = library.get_page_by_key(*key);
  35. assert_eq!(page.lang, "en");
  36. }
  37. let fr_blog = library.get_section(&blog_path.join("_index.fr.md")).unwrap();
  38. assert_eq!(fr_blog.subsections.len(), 0);
  39. assert_eq!(fr_blog.pages.len(), 3);
  40. assert_eq!(
  41. fr_blog.ancestors,
  42. vec![*library.get_section_key(&fr_index_section.file.path).unwrap()]
  43. );
  44. for key in &fr_blog.pages {
  45. let page = library.get_page_by_key(*key);
  46. assert_eq!(page.lang, "fr");
  47. }
  48. }
  49. #[test]
  50. fn can_build_multilingual_site() {
  51. let (_, _tmp_dir, public) = build_site("test_site_i18n");
  52. assert!(public.exists());
  53. // Index pages
  54. assert!(file_exists!(public, "index.html"));
  55. assert!(file_exists!(public, "fr/index.html"));
  56. assert!(file_contains!(public, "fr/index.html", "Une page"));
  57. assert!(file_contains!(public, "fr/index.html", "Language: fr"));
  58. assert!(file_exists!(public, "base/index.html"));
  59. assert!(file_exists!(public, "fr/base/index.html"));
  60. // Sections are there as well, with translations info
  61. assert!(file_exists!(public, "blog/index.html"));
  62. assert!(file_contains!(
  63. public,
  64. "blog/index.html",
  65. "Translated in fr: Mon blog https://example.com/fr/blog/"
  66. ));
  67. assert!(file_contains!(
  68. public,
  69. "blog/index.html",
  70. "Translated in it: Il mio blog https://example.com/it/blog/"
  71. ));
  72. assert!(file_exists!(public, "fr/blog/index.html"));
  73. assert!(file_contains!(public, "fr/blog/index.html", "Language: fr"));
  74. assert!(file_contains!(
  75. public,
  76. "fr/blog/index.html",
  77. "Translated in en: My blog https://example.com/blog/"
  78. ));
  79. assert!(file_contains!(
  80. public,
  81. "fr/blog/index.html",
  82. "Translated in it: Il mio blog https://example.com/it/blog/"
  83. ));
  84. // Normal pages are there with the translations
  85. assert!(file_exists!(public, "blog/something/index.html"));
  86. assert!(file_contains!(
  87. public,
  88. "blog/something/index.html",
  89. "Translated in fr: Quelque chose https://example.com/fr/blog/something/"
  90. ));
  91. assert!(file_exists!(public, "fr/blog/something/index.html"));
  92. assert!(file_contains!(public, "fr/blog/something/index.html", "Language: fr"));
  93. assert!(file_contains!(
  94. public,
  95. "fr/blog/something/index.html",
  96. "Translated in en: Something https://example.com/blog/something/"
  97. ));
  98. // sitemap contains all languages
  99. assert!(file_exists!(public, "sitemap.xml"));
  100. assert!(file_contains!(public, "sitemap.xml", "https://example.com/blog/something-else/"));
  101. assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/blog/something-else/"));
  102. assert!(file_contains!(public, "sitemap.xml", "https://example.com/it/blog/something-else/"));
  103. // one rss per language
  104. assert!(file_exists!(public, "rss.xml"));
  105. assert!(file_contains!(public, "rss.xml", "https://example.com/blog/something-else/"));
  106. assert!(!file_contains!(public, "rss.xml", "https://example.com/fr/blog/something-else/"));
  107. assert!(file_exists!(public, "fr/rss.xml"));
  108. assert!(!file_contains!(public, "fr/rss.xml", "https://example.com/blog/something-else/"));
  109. assert!(file_contains!(public, "fr/rss.xml", "https://example.com/fr/blog/something-else/"));
  110. // Italian doesn't have RSS enabled
  111. assert!(!file_exists!(public, "it/rss.xml"));
  112. // Taxonomies are per-language
  113. assert!(file_exists!(public, "authors/index.html"));
  114. assert!(file_contains!(public, "authors/index.html", "Queen"));
  115. assert!(!file_contains!(public, "authors/index.html", "Vincent"));
  116. assert!(!file_exists!(public, "auteurs/index.html"));
  117. assert!(file_exists!(public, "authors/queen-elizabeth/rss.xml"));
  118. assert!(!file_exists!(public, "fr/authors/index.html"));
  119. assert!(file_exists!(public, "fr/auteurs/index.html"));
  120. assert!(!file_contains!(public, "fr/auteurs/index.html", "Queen"));
  121. assert!(file_contains!(public, "fr/auteurs/index.html", "Vincent"));
  122. assert!(!file_exists!(public, "fr/auteurs/vincent-prouillet/rss.xml"));
  123. }