ref: master
plugins/metadata/test/functional/content_viewer_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
require 'test_helper' class ContentViewerControllerTest < ActionController::TestCase def setup @controller = ContentViewerController.new @profile = create_user('testinguser').person @environment = @profile.environment @environment.enabled_plugins += ['MetadataPlugin'] @environment.save! end attr_reader :profile, :environment should 'produce meta tags for profile if on homepage' do get :view_page, profile: profile.identifier, page: [] assert_tag tag: 'meta', attributes: {property: 'og:title', content: profile.name} end should 'add meta tags with article info' do a = TextArticle.create(name: 'Article to be shared', body: '<p>This article should be shared with all social networks</p>', profile: profile) get :view_page, profile: profile.identifier, page: [ a.name.to_slug ] assert_tag tag: 'meta', attributes: { name: 'twitter:title', content: /#{a.name} - #{a.profile.name}/ } assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.lead.gsub(/<\/?p>/,'') } assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' } assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' } assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ } assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ } assert_tag tag: 'meta', attributes: { property: 'og:site_name', content: a.profile.name } assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.lead.gsub(/<\/?p>/,'') } assert_no_tag tag: 'meta', attributes: { property: 'og:image' } end should 'add meta tags with article images' do a = TextArticle.create(name: 'Article to be shared with images', body: 'This article should be shared with all social networks <img src="/images/x.png" />', profile: profile) get :view_page, profile: profile.identifier, page: [ a.name.to_slug ] assert_tag tag: 'meta', attributes: { name: 'twitter:image', content: /\/images\/x.png/ } assert_tag tag: 'meta', attributes: { property: 'og:image', content: /\/images\/x.png/ } end should 'escape utf8 characters correctly' do a = TextArticle.create(name: 'Article to be shared with images', body: 'This article should be shared with all social networks <img src="/images/รง.png" />', profile: profile) get :view_page, profile: profile.identifier, page: [ a.name.to_slug ] assert_tag tag: 'meta', attributes: { property: 'og:image', content: /\/images\/%C3%A7.png/ } end should 'render not_found page properly' do assert_equal false, Article.exists?(:slug => 'non-existing-page') assert_nothing_raised do get :view_page, profile: profile.identifier, page: [ 'non-existing-page' ] assert_response 404 # not found assert_template 'not_found' end end should 'not expose metadata on private pages' do profile.update_column :public_profile, false a = TextArticle.create(name: 'Article to be shared with images', body: 'This article should be shared with all social networks <img src="/images/x.png" />', profile: profile) get :view_page, profile: profile.identifier, page: [ a.name.to_slug ] assert_no_tag tag: 'meta', attributes: { property: 'og:image', content: /\/images\/x.png/ } end end |