diff options
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/content_controller_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/controllers/content_controller_test.rb b/test/controllers/content_controller_test.rb index 304fd921..5bb02f3d 100644 --- a/test/controllers/content_controller_test.rb +++ b/test/controllers/content_controller_test.rb | |||
| @@ -190,6 +190,46 @@ class ContentControllerTest < ActionController::TestCase | |||
| 190 | FileUtils.rm_rf(Rails.root.join("tmp", "test_uploads", asset.id.to_s)) | 190 | FileUtils.rm_rf(Rails.root.join("tmp", "test_uploads", asset.id.to_s)) |
| 191 | end | 191 | end |
| 192 | end | 192 | end |
| 193 | |||
| 194 | test "a translated page declares hreflang alternates and canonicalises per locale" do | ||
| 195 | node = create_node_under_root "og_hreflang_test" | ||
| 196 | draft = find_or_create_draft(node, @user1) | ||
| 197 | draft.title = "Zweisprachig" | ||
| 198 | draft.save | ||
| 199 | node.publish_draft! | ||
| 200 | node.reload | ||
| 201 | Globalize.with_locale(:en) { node.head.update!(:title => "Bilingual") } | ||
| 202 | |||
| 203 | get :render_page, params: { :locale => "de", :page_path => ["og_hreflang_test"] } | ||
| 204 | |||
| 205 | assert_response :success | ||
| 206 | assert_select "link[rel=alternate][hreflang=de][href=?]", | ||
| 207 | "http://test.host/og_hreflang_test" | ||
| 208 | assert_select "link[rel=alternate][hreflang=en][href=?]", | ||
| 209 | "http://test.host/en/og_hreflang_test" | ||
| 210 | assert_select "link[rel=alternate][hreflang='x-default'][href=?]", | ||
| 211 | "http://test.host/og_hreflang_test" | ||
| 212 | assert_select "link[rel=canonical][href=?]", | ||
| 213 | "http://test.host/og_hreflang_test" | ||
| 214 | end | ||
| 215 | |||
| 216 | test "an untranslated page declares no alternates and canonicalises to the default locale" do | ||
| 217 | node = create_node_under_root "og_single_locale_test" | ||
| 218 | draft = find_or_create_draft(node, @user1) | ||
| 219 | draft.title = "Nur Deutsch" | ||
| 220 | draft.save | ||
| 221 | node.publish_draft! | ||
| 222 | |||
| 223 | get :render_page, params: { :locale => "en", :page_path => ["og_single_locale_test"] } | ||
| 224 | |||
| 225 | assert_response :success | ||
| 226 | assert_select "link[rel=alternate][hreflang]", false, | ||
| 227 | "one translation is nothing to declare" | ||
| 228 | # Served German through the fallback chain, so the German URL is | ||
| 229 | # canonical rather than the /en/ address that was requested. | ||
| 230 | assert_select "link[rel=canonical][href=?]", | ||
| 231 | "http://test.host/og_single_locale_test" | ||
| 232 | end | ||
| 193 | 233 | ||
| 194 | protected | 234 | protected |
| 195 | 235 | ||
