diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-30 04:41:07 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-30 04:41:07 +0200 |
| commit | 36a4194ee3013dfa834aa8d4d57b0bfacf724a1a (patch) | |
| tree | 3f46fb04e6d6b38a7d3bef4d3ba1c98fb098a347 /test/controllers | |
| parent | 6c62d0c538e6b8baa416a7ed901a74a66de44348 (diff) | |
Emit per-page Open Graph metadata
Replaces one hardcoded German description and an unrenderable SVG with
per-page title, description, canonical URL, locale and publication date,
plus the card variant or a site-wide default.
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/content_controller_test.rb | 76 | ||||
| -rw-r--r-- | test/controllers/shared_previews_controller_test.rb | 15 |
2 files changed, 91 insertions, 0 deletions
diff --git a/test/controllers/content_controller_test.rb b/test/controllers/content_controller_test.rb index 9731d082..304fd921 100644 --- a/test/controllers/content_controller_test.rb +++ b/test/controllers/content_controller_test.rb | |||
| @@ -114,6 +114,82 @@ class ContentControllerTest < ActionController::TestCase | |||
| 114 | 114 | ||
| 115 | assert_response :success | 115 | assert_response :success |
| 116 | end | 116 | end |
| 117 | |||
| 118 | test "a published page emits article social metadata" do | ||
| 119 | node = create_node_under_root "og_article_test" | ||
| 120 | draft = find_or_create_draft(node, @user1) | ||
| 121 | draft.title = "Offener Brief" | ||
| 122 | draft.abstract = "Wir veröffentlichen den Wortlaut eines Offenen Briefes." | ||
| 123 | draft.save | ||
| 124 | node.publish_draft! | ||
| 125 | |||
| 126 | get :render_page, params: { :locale => "de", :page_path => ["og_article_test"] } | ||
| 127 | |||
| 128 | assert_response :success | ||
| 129 | assert_select "meta[property='og:type'][content=?]", "article" | ||
| 130 | assert_select "meta[property='og:title'][content=?]", "Offener Brief" | ||
| 131 | assert_select "meta[property='og:site_name'][content=?]", "Chaos Computer Club" | ||
| 132 | assert_select "meta[property='og:locale'][content=?]", "de_DE" | ||
| 133 | assert_select "meta[property='article:published_time']" | ||
| 134 | |||
| 135 | # og:title carries the bare title; page_title's "CCC | " prefix belongs | ||
| 136 | # to <title> only, since platforms render og:site_name separately. | ||
| 137 | assert_select "title", :text => "CCC | Offener Brief" | ||
| 138 | |||
| 139 | # A canonical URL must not carry a query string. | ||
| 140 | canonical = css_select("link[rel=canonical]").first["href"] | ||
| 141 | assert_match %r{/og_article_test\z}, canonical | ||
| 142 | |||
| 143 | assert_select "meta[name=robots]", false, "a public page must be indexable" | ||
| 144 | end | ||
| 145 | |||
| 146 | test "a page without a headline asset falls back to the default card" do | ||
| 147 | node = create_node_under_root "og_fallback_test" | ||
| 148 | find_or_create_draft(node, @user1).update!(:title => "Ohne Aufmacher") | ||
| 149 | node.publish_draft! | ||
| 150 | |||
| 151 | get :render_page, params: { :locale => "de", :page_path => ["og_fallback_test"] } | ||
| 152 | |||
| 153 | assert_response :success | ||
| 154 | assert_select "meta[property='og:image'][content=?]", | ||
| 155 | "http://test.host/images/social_default.png" | ||
| 156 | assert_select "meta[property='og:image:width'][content=?]", "1200" | ||
| 157 | assert_select "meta[property='og:image:height'][content=?]", "630" | ||
| 158 | end | ||
| 159 | |||
| 160 | test "a page with a headline asset points at its social card" do | ||
| 161 | node = create_node_under_root "og_variant_test" | ||
| 162 | draft = find_or_create_draft(node, @user1) | ||
| 163 | draft.title = "Mit Aufmacher" | ||
| 164 | draft.save | ||
| 165 | node.publish_draft! | ||
| 166 | node.reload | ||
| 167 | |||
| 168 | asset = Asset.create!(:name => "aufmacher", | ||
| 169 | :upload_file_name => "aufmacher.png", | ||
| 170 | :upload_content_type => "image/png", | ||
| 171 | :upload_updated_at => Time.at(1_700_000_000)) | ||
| 172 | node.attach_asset!(asset, :user => @user1, :headline => true) | ||
| 173 | |||
| 174 | # has_variant? only tests File.exist?, so touching the path is enough | ||
| 175 | # and no ImageMagick runs in the suite. image/png takes .jpg for the | ||
| 176 | # card, per variant_filename's per-style rule. | ||
| 177 | card = Rails.root.join("tmp", "test_uploads", asset.id.to_s, "og", "aufmacher.jpg") | ||
| 178 | |||
| 179 | begin | ||
| 180 | FileUtils.mkdir_p(File.dirname(card)) | ||
| 181 | FileUtils.touch(card) | ||
| 182 | |||
| 183 | get :render_page, params: { :locale => "de", :page_path => ["og_variant_test"] } | ||
| 184 | |||
| 185 | assert_response :success | ||
| 186 | assert_select "meta[property='og:image'][content=?]", | ||
| 187 | "http://test.host/system/uploads/#{asset.id}/og/aufmacher.jpg?v=1700000000" | ||
| 188 | assert_select "meta[property='og:image:alt'][content=?]", "aufmacher" | ||
| 189 | ensure | ||
| 190 | FileUtils.rm_rf(Rails.root.join("tmp", "test_uploads", asset.id.to_s)) | ||
| 191 | end | ||
| 192 | end | ||
| 117 | 193 | ||
| 118 | protected | 194 | protected |
| 119 | 195 | ||
diff --git a/test/controllers/shared_previews_controller_test.rb b/test/controllers/shared_previews_controller_test.rb index 4ebc785f..6d4588a8 100644 --- a/test/controllers/shared_previews_controller_test.rb +++ b/test/controllers/shared_previews_controller_test.rb | |||
| @@ -32,4 +32,19 @@ class SharedPreviewsControllerTest < ActionController::TestCase | |||
| 32 | 32 | ||
| 33 | assert_redirected_to node.head.public_link | 33 | assert_redirected_to node.head.public_link |
| 34 | end | 34 | end |
| 35 | |||
| 36 | test "a shared preview emits no social metadata and is not indexable" do | ||
| 37 | node = Node.root.children.create!(:slug => "shared_preview_no_og_test") | ||
| 38 | node.draft.update!(:title => "Unveröffentlichter Entwurf") | ||
| 39 | node.draft.ensure_preview_token! | ||
| 40 | |||
| 41 | get :show, params: { :token => node.draft.preview_token } | ||
| 42 | |||
| 43 | assert_response :success | ||
| 44 | |||
| 45 | # An unfurled preview link would otherwise hand the draft's title, | ||
| 46 | # abstract and headline image to everyone in the chat room. | ||
| 47 | assert_select "meta[property^='og:']", false, "a preview must emit no og tags" | ||
| 48 | assert_select "meta[name=robots][content=?]", "noindex, nofollow" | ||
| 49 | end | ||
| 35 | end | 50 | end |
