diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb
index 5119817..d625a39 100644
--- a/app/helpers/content_viewer_helper.rb
+++ b/app/helpers/content_viewer_helper.rb
@@ -52,15 +52,6 @@ module ContentViewerHelper
end
end
- def addthis_facebook_url(article)
- "http://www.facebook.com/sharer.php?s=100&p[title]=%{title}&p[summary]=%{summary}&p[url]=%{url}&p[images][0]=%{image}" % {
- :title => CGI.escape(article.title),
- :url => CGI.escape(url_for(article.url)),
- :summary => CGI.escape(truncate(strip_tags(article.body.to_s), :length => 300)),
- :image => CGI.escape(article.body_images_paths.first.to_s)
- }
- end
-
def addthis_image_tag
if File.exists?(File.join(Rails.root, 'public', theme_path, 'images', 'addthis.gif'))
image_tag(File.join(theme_path, 'images', 'addthis.gif'), :border => 0, :alt => '')
diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml
index acee837..d058227 100644
--- a/app/views/layouts/application-ng.rhtml
+++ b/app/views/layouts/application-ng.rhtml
@@ -11,7 +11,6 @@
-
@@ -23,6 +22,7 @@
<% if @page %>
<% @page.body_images_paths.each do |img| %>
+
<% end %>
<% end %>
diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb
index d971faf..fd1c4da 100644
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -263,7 +263,7 @@ class ApplicationControllerTest < ActionController::TestCase
assert_no_tag :tag => 'a', :content => /Category 2/
end
- should 'show name of article as title of page' do
+ should 'show name of article as title of page without environment' do
p = create_user('test_user').person
a = p.articles.create!(:name => 'test article')
@@ -271,17 +271,22 @@ class ApplicationControllerTest < ActionController::TestCase
@controller.instance_variable_set('@page', a)
get :index
- assert_tag 'title', :content => 'test article - ' + p.name + ' - ' + p.environment.name
+ assert_tag 'title', :content => 'test article - ' + p.name
end
- should 'diplay name of profile in the title' do
+ should 'diplay name of profile in the title without environment' do
p = create_user('test_user').person
p.name = 'Some Test User'
p.save!
@controller.instance_variable_set('@profile', p)
get :index, :profile => p.identifier
- assert_tag 'title', :content => p.name + ' - ' + p.environment.name
+ assert_tag 'title', :content => p.name
+ end
+
+ should 'display environment name in title when profile and page are not defined' do
+ get :index
+ assert_tag 'title', :content => assigns(:environment).name
end
should 'display menu links for my environment when logged in other environment' do
@@ -324,7 +329,8 @@ class ApplicationControllerTest < ActionController::TestCase
end
should 'set html lang as the article language if an article is present and has a language' do
- a = fast_create(Article, :name => 'test article', :language => 'fr')
+ p = create_user('test_user').person
+ a = fast_create(Article, :name => 'test article', :language => 'fr', :profile_id => p.id )
@controller.instance_variable_set('@page', a)
FastGettext.stubs(:locale).returns('es')
get :index
@@ -338,7 +344,9 @@ class ApplicationControllerTest < ActionController::TestCase
end
should 'set html lang as locale if page has no language' do
- a = fast_create(Article, :name => 'test article', :language => nil)
+ p = create_user('test_user').person
+ a = fast_create(Article, :name => 'test article', :language => nil, :profile_id => p.id )
+
@controller.instance_variable_set('@page', a)
FastGettext.stubs(:locale).returns('es')
get :index
@@ -542,4 +550,18 @@ class ApplicationControllerTest < ActionController::TestCase
assert_equal nil, @controller.application_controller_test_other_filter_plugin_filter_plugin
end
+ should 'display meta tags for social media' do
+ get :index
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:card', :value => 'summary' }
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => assigns(:environment).name }
+ assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'website' }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => assigns(:environment).top_url }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => assigns(:environment).name }
+ assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' }
+ assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
+ end
end
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index b09c4d3..2d17f72 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1369,4 +1369,28 @@ class ContentViewerControllerTest < ActionController::TestCase
assert_match /this is a sample text file/, @response.body
end
+ should 'add meta tags with article info' do
+ a = TinyMceArticle.create(:name => 'Article to be shared', :body => 'This article should be shared with all social networks', :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.body }
+ 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.body }
+ assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
+ end
+
+ should 'add meta tags with article images' do
+ a = TinyMceArticle.create(:name => 'Article to be shared with images', :body => 'This article should be shared with all social networks ', :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
+
end
diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb
index 786a48f..06c7d3e 100644
--- a/test/unit/content_viewer_helper_test.rb
+++ b/test/unit/content_viewer_helper_test.rb
@@ -89,38 +89,6 @@ class ContentViewerHelperTest < ActiveSupport::TestCase
assert_no_match /feed/, result
end
- should 'generate facebook addthis url for article' do
- Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
- [TextileArticle, Blog, Folder, Gallery, UploadedFile, Forum, Event, TextArticle, TinyMceArticle].each do |model|
- a = model.new(:name => 'Some title', :body => 'Some text here.', :profile => profile)
- assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=Some+text+here.&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a)
- end
- end
-
- should 'generate facebook addthis url without body' do
- Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
- a = TinyMceArticle.new(:name => 'Test', :body => nil, :profile => profile)
- assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Test&p[summary]=&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Ftest&p[images][0]=", addthis_facebook_url(a)
- end
-
- should 'generate facebook addthis url without tags in body' do
- Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
- a = TinyMceArticle.new(:name => 'Some title', :body => '
This is a test
', :profile => profile) - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) - end - - should 'generate facebook addthis url with truncated body' do - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Some title', :body => 'test' * 76, :profile => profile) - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=#{'test' * 74}t...&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) - end - - should 'generate facebook addthis url for tinymce article with images' do - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Some title', :body => 'This is a test