diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d8cc7d6..1b5be1b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -50,6 +50,10 @@ module ApplicationHelper
include ButtonsHelper
+ include ProfileImageHelper
+
+ include ThemeLoaderHelper
+
def locale
(@page && !@page.language.blank?) ? @page.language : FastGettext.locale
end
@@ -281,48 +285,6 @@ module ApplicationHelper
end
end
- def theme_path
- if session[:theme]
- '/user_themes/' + current_theme
- else
- '/designs/themes/' + current_theme
- end
- end
-
- def current_theme
- @current_theme ||=
- begin
- if session[:theme]
- session[:theme]
- else
- # utility for developers: set the theme to 'random' in development mode and
- # you will get a different theme every request. This is interesting for
- # testing
- if Rails.env.development? && environment.theme == 'random'
- @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
- @random_theme
- elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
- params[:theme]
- else
- if profile && !profile.theme.nil?
- profile.theme
- elsif environment
- environment.theme
- else
- if logger
- logger.warn("No environment found. This is weird.")
- logger.warn("Request environment: %s" % request.env.inspect)
- logger.warn("Request parameters: %s" % params.inspect)
- end
-
- # could not determine the theme, so return the default one
- 'default'
- end
- end
- end
- end
- end
-
def theme_view_file(template, theme=nil)
# Since we cannot control what people are doing in external themes, we
# will keep looking for the deprecated .rhtml extension here.
@@ -395,141 +357,6 @@ module ApplicationHelper
Theme.find(current_theme).owner.identifier
end
- # generates a image tag for the profile.
- #
- # If the profile has no image set yet, then a default image is used.
- def profile_image(profile, size=:portrait, opt={})
- return '' if profile.nil?
- opt[:alt] ||= profile.name()
- opt[:title] ||= ''
- opt[:class] ||= ''
- opt[:class] += ( profile.class == Person ? ' photo' : ' logo' )
- image_tag(profile_icon(profile, size), opt )
- end
-
- def profile_icon( profile, size=:portrait, return_mimetype=false )
- filename, mimetype = '', 'image/png'
- if profile.image
- filename = profile.image.public_filename( size )
- mimetype = profile.image.content_type
- else
- icon =
- if profile.organization?
- if profile.kind_of?(Community)
- '/images/icons-app/community-'+ size.to_s() +'.png'
- else
- '/images/icons-app/enterprise-'+ size.to_s() +'.png'
- end
- else
- pixels = Image.attachment_options[:thumbnails][size].split('x').first
- gravatar_profile_image_url(
- profile.email,
- :size => pixels,
- :d => gravatar_default
- )
- end
- filename = default_or_themed_icon(icon)
- end
- return_mimetype ? [filename, mimetype] : filename
- end
-
- def default_or_themed_icon(icon)
- if File.exists?(Rails.root.join('public', theme_path, icon))
- theme_path + icon
- else
- icon
- end
- end
-
- def profile_sex_icon( profile )
- return '' unless profile.is_a?(Person)
- return '' unless !environment.enabled?('disable_gender_icon')
- sex = ( profile.sex ? profile.sex.to_s() : 'undef' )
- title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) )
- sex = content_tag 'span',
- content_tag( 'span', sex ),
- :class => 'sex-'+sex,
- :title => title
- sex
- end
-
- def links_for_balloon(profile)
- if environment.enabled?(:show_balloon_with_profile_links_when_clicked)
- if profile.kind_of?(Person)
- [
- {_('Wall') => {:href => url_for(profile.public_profile_url)}},
- {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}},
- {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}},
- {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
- {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}}
- ]
- elsif profile.kind_of?(Community)
- [
- {_('Wall') => {:href => url_for(profile.public_profile_url)}},
- {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
- {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
- {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}},
- {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}},
- {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}
- ]
- elsif profile.kind_of?(Enterprise)
- [
- {_('Products') => {:href => catalog_path(profile.identifier)}},
- {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
- {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
- {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
- ]
- else
- []
- end
- end
- end
-
- # displays a link to the profile homepage with its image (as generated by
- # #profile_image) and its name below it.
- def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
- if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info)
- return instance_exec(&content)
- end
- name = profile.short_name
- if profile.person?
- url = url_for(profile.check_friendship_url)
- trigger_class = 'person-trigger'
- else
- city = ''
- url = url_for(profile.check_membership_url)
- if profile.community?
- trigger_class = 'community-trigger'
- elsif profile.enterprise?
- trigger_class = 'enterprise-trigger'
- end
- end
-
- extra_info_tag = ''
- img_class = 'profile-image'
-
- if extra_info.is_a? Hash
- extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
- img_class +=' '+extra_info[:class]
- else
- extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
- end
-
- links = links_for_balloon(profile)
- content_tag('div', content_tag(tag,
- (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ?
- popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
- link_to(
- content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
- content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
- extra_info_tag + profile_sex_icon( profile ),
- profile.url,
- :class => 'profile_link url',
- :help => _('Click on this icon to go to the %s\'s home page') % profile.name,
- :title => profile.name ),
- :class => 'vcard'), :class => 'common-profile-list-block')
- end
-
def popover_menu(title,menu_title,links,html_options={})
html_options[:class] = "" unless html_options[:class]
html_options[:class] << " menu-submenu-trigger"
@@ -538,10 +365,6 @@ module ApplicationHelper
link_to(content_tag(:span, title), '#', html_options)
end
- def gravatar_default
- (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm'
- end
-
attr_reader :environment
def select_categories(object_name, title=nil, title_size=4)
diff --git a/app/helpers/profile_image_helper.rb b/app/helpers/profile_image_helper.rb
new file mode 100644
index 0000000..867aee8
--- /dev/null
+++ b/app/helpers/profile_image_helper.rb
@@ -0,0 +1,140 @@
+module ProfileImageHelper
+ def default_or_themed_icon(icon)
+ if File.exists?(Rails.root.join('public', theme_path, icon))
+ theme_path + icon
+ else
+ icon
+ end
+ end
+
+ def gravatar_default
+ (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm'
+ end
+
+ def profile_sex_icon( profile )
+ return '' unless profile.is_a?(Person)
+ return '' unless !environment.enabled?('disable_gender_icon')
+ sex = ( profile.sex ? profile.sex.to_s() : 'undef' )
+ title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) )
+ sex = content_tag 'span',
+ content_tag( 'span', sex ),
+ :class => 'sex-'+sex,
+ :title => title
+ sex
+ end
+
+ def profile_icon( profile, size=:portrait, return_mimetype=false )
+ filename, mimetype = '', 'image/png'
+ if profile.image
+ filename = profile.image.public_filename( size )
+ mimetype = profile.image.content_type
+ else
+ icon =
+ if profile.organization?
+ if profile.kind_of?(Community)
+ '/images/icons-app/community-'+ size.to_s() +'.png'
+ else
+ '/images/icons-app/enterprise-'+ size.to_s() +'.png'
+ end
+ else
+ pixels = Image.attachment_options[:thumbnails][size].split('x').first
+ gravatar_profile_image_url(
+ profile.email,
+ :size => pixels,
+ :d => gravatar_default
+ )
+ end
+ filename = default_or_themed_icon(icon)
+ end
+ return_mimetype ? [filename, mimetype] : filename
+ end
+
+ # generates a image tag for the profile.
+ #
+ # If the profile has no image set yet, then a default image is used.
+ def profile_image(profile, size=:portrait, opt={})
+ return '' if profile.nil?
+ opt[:alt] ||= profile.name()
+ opt[:title] ||= ''
+ opt[:class] ||= ''
+ opt[:class] += ( profile.class == Person ? ' photo' : ' logo' )
+ image_tag(profile_icon(profile, size), opt )
+ end
+
+ def links_for_balloon(profile)
+ if environment.enabled?(:show_balloon_with_profile_links_when_clicked)
+ if profile.kind_of?(Person)
+ [
+ {_('Wall') => {:href => url_for(profile.public_profile_url)}},
+ {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}},
+ {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}},
+ {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
+ {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}}
+ ]
+ elsif profile.kind_of?(Community)
+ [
+ {_('Wall') => {:href => url_for(profile.public_profile_url)}},
+ {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
+ {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
+ {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}},
+ {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}},
+ {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}
+ ]
+ elsif profile.kind_of?(Enterprise)
+ [
+ {_('Products') => {:href => catalog_path(profile.identifier)}},
+ {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
+ {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
+ {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
+ ]
+ else
+ []
+ end
+ end
+ end
+
+ # displays a link to the profile homepage with its image (as generated by
+ # #profile_image) and its name below it.
+ def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
+ if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info)
+ return instance_exec(&content)
+ end
+ name = profile.short_name
+ if profile.person?
+ url = url_for(profile.check_friendship_url)
+ trigger_class = 'person-trigger'
+ else
+ city = ''
+ url = url_for(profile.check_membership_url)
+ if profile.community?
+ trigger_class = 'community-trigger'
+ elsif profile.enterprise?
+ trigger_class = 'enterprise-trigger'
+ end
+ end
+
+ extra_info_tag = ''
+ img_class = 'profile-image'
+
+ if extra_info.is_a? Hash
+ extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
+ img_class +=' '+extra_info[:class]
+ else
+ extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
+ end
+
+ links = links_for_balloon(profile)
+ content_tag('div', content_tag(tag,
+ (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ?
+ popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
+ link_to(
+ content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
+ content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
+ extra_info_tag + profile_sex_icon( profile ),
+ profile.url,
+ :class => 'profile_link url',
+ :help => _('Click on this icon to go to the %s\'s home page') % profile.name,
+ :title => profile.name ),
+ :class => 'vcard'), :class => 'common-profile-list-block')
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/theme_loader_helper.rb b/app/helpers/theme_loader_helper.rb
new file mode 100644
index 0000000..6304640
--- /dev/null
+++ b/app/helpers/theme_loader_helper.rb
@@ -0,0 +1,43 @@
+module ThemeLoaderHelper
+ def current_theme
+ @current_theme ||=
+ begin
+ if session[:theme]
+ session[:theme]
+ else
+ # utility for developers: set the theme to 'random' in development mode and
+ # you will get a different theme every request. This is interesting for
+ # testing
+ if Rails.env.development? && environment.theme == 'random'
+ @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
+ @random_theme
+ elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
+ params[:theme]
+ else
+ if profile && !profile.theme.nil?
+ profile.theme
+ elsif environment
+ environment.theme
+ else
+ if logger
+ logger.warn("No environment found. This is weird.")
+ logger.warn("Request environment: %s" % request.env.inspect)
+ logger.warn("Request parameters: %s" % params.inspect)
+ end
+
+ # could not determine the theme, so return the default one
+ 'default'
+ end
+ end
+ end
+ end
+ end
+
+ def theme_path
+ if session[:theme]
+ '/user_themes/' + current_theme
+ else
+ '/designs/themes/' + current_theme
+ end
+ end
+end
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb
index 30f0b3b..7e10dac 100644
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -145,35 +145,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator'
end
- should 'get theme from environment by default' do
- @environment = mock
- @environment.stubs(:theme).returns('my-environment-theme')
- stubs(:profile).returns(nil)
- assert_equal 'my-environment-theme', current_theme
- end
-
- should 'get theme from profile when profile is present' do
- profile = mock
- profile.stubs(:theme).returns('my-profile-theme')
- stubs(:profile).returns(profile)
- assert_equal 'my-profile-theme', current_theme
- end
-
- should 'override theme with testing theme from session' do
- stubs(:session).returns(:theme => 'theme-under-test')
- assert_equal 'theme-under-test', current_theme
- end
-
- should 'point to system theme path by default' do
- expects(:current_theme).returns('my-system-theme')
- assert_equal '/designs/themes/my-system-theme', theme_path
- end
-
- should 'point to user theme path when testing theme' do
- stubs(:session).returns({:theme => 'theme-under-test'})
- assert_equal '/user_themes/theme-under-test', theme_path
- end
-
should 'render theme footer' do
stubs(:theme_path).returns('/user_themes/mytheme')
footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb')
@@ -295,38 +266,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert_nil select_categories(mock)
end
- should 'provide sex icon for males' do
- stubs(:environment).returns(Environment.default)
- expects(:content_tag).with(anything, 'male').returns('MALE!!')
- expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL")
- assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male'))
- end
-
- should 'provide sex icon for females' do
- stubs(:environment).returns(Environment.default)
- expects(:content_tag).with(anything, 'female').returns('FEMALE!!')
- expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL")
- assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female'))
- end
-
- should 'provide undef sex icon' do
- stubs(:environment).returns(Environment.default)
- expects(:content_tag).with(anything, 'undef').returns('UNDEF!!')
- expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL")
- assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil))
- end
-
- should 'not draw sex icon for non-person profiles' do
- assert_equal '', profile_sex_icon(Community.new)
- end
-
- should 'not draw sex icon when disabled in the environment' do
- env = fast_create(Environment, :name => 'env test')
- env.expects(:enabled?).with('disable_gender_icon').returns(true)
- stubs(:environment).returns(env)
- assert_equal '', profile_sex_icon(build(Person, :sex => 'male'))
- end
-
should 'display field on person signup' do
env = create(Environment, :name => 'env test')
stubs(:environment).returns(env)
@@ -524,19 +463,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert_equal Environment.default.name, page_title
end
- should 'gravatar default parameter' do
- profile = mock
- profile.stubs(:theme).returns('some-theme')
- stubs(:profile).returns(profile)
-
- NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
- assert_equal gravatar_default, 'crazyvatar'
-
- stubs(:theme_option).returns('gravatar' => 'nicevatar')
- NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
- assert_equal gravatar_default, 'nicevatar'
- end
-
should 'use theme passed via param when in development mode' do
stubs(:environment).returns(build(Environment, :theme => 'environment-theme'))
Rails.env.stubs(:development?).returns(true)
@@ -558,48 +484,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert_equal environment.theme, current_theme
end
- should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do
- env = Environment.default
- env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false)
- stubs(:environment).returns(env)
- profile = Profile.new
- assert_nil links_for_balloon(profile)
- end
-
- should 'return ordered list of links to balloon to Person' do
- env = Environment.default
- env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
- stubs(:environment).returns(env)
- person = Person.new identifier: 'person'
- person.stubs(:url).returns('url for person')
- person.stubs(:public_profile_url).returns('url for person')
- links = links_for_balloon(person)
- assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first}
- end
-
- should 'return ordered list of links to balloon to Community' do
- env = Environment.default
- env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
- stubs(:environment).returns(env)
- community = Community.new identifier: 'comm'
- community.stubs(:url).returns('url for community')
- community.stubs(:public_profile_url).returns('url for community')
- links = links_for_balloon(community)
- assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first}
- end
-
- should 'return ordered list of links to balloon to Enterprise' do
- env = Environment.default
- env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
- stubs(:environment).returns(env)
- enterprise = Enterprise.new identifier: 'coop'
- enterprise.stubs(:url).returns('url for enterprise')
- enterprise.stubs(:public_profile_url).returns('url for enterprise')
- stubs(:catalog_path)
- links = links_for_balloon(enterprise)
- assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first}
- end
-
should 'use favicon from environment theme if does not have profile' do
stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme'))
stubs(:profile).returns(nil)
@@ -651,24 +535,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert admin_link.present?
end
- should 'not return mime type of profile icon if not requested' do
- stubs(:profile).returns(Person.new)
- stubs(:current_theme).returns('default')
-
- filename, mime = profile_icon(Person.new, :thumb)
- assert_not_nil filename
- assert_nil mime
- end
-
- should 'return mime type of profile icon' do
- stubs(:profile).returns(Person.new)
- stubs(:current_theme).returns('default')
-
- filename, mime = profile_icon(Person.new, :thumb, true)
- assert_not_nil filename
- assert_not_nil mime
- end
-
should 'pluralize without count' do
assert_equal "tests", pluralize_without_count(2, "test")
assert_equal "test", pluralize_without_count(1, "test")
@@ -1037,31 +903,6 @@ class ApplicationHelperTest < ActionView::TestCase
assert_equal c.top_url, top_url
end
- should "Extra info with hash" do
- @plugins = mock
- @plugins.stubs(:dispatch_first).returns(false)
- env = Environment.default
- stubs(:environment).returns(env)
- stubs(:profile).returns(profile)
- profile = fast_create(Person, :environment_id => env.id)
- info = {:value =>_('New'), :class => 'new-profile'}
- html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
- assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' }
- assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New'
- end
-
- should "Extra info without hash" do
- @plugins = mock
- @plugins.stubs(:dispatch_first).returns(false)
- env = Environment.default
- stubs(:environment).returns(env)
- stubs(:profile).returns(profile)
- profile = fast_create(Person, :environment_id => env.id)
- info = 'new'
- html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
- assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new'
- end
-
protected
include NoosferoTestHelper
diff --git a/test/unit/profile_image_helper_test.rb b/test/unit/profile_image_helper_test.rb
new file mode 100644
index 0000000..a1a8e25
--- /dev/null
+++ b/test/unit/profile_image_helper_test.rb
@@ -0,0 +1,138 @@
+# encoding: UTF-8
+require_relative "../test_helper"
+
+class ProfileImageHelperTest < ActionView::TestCase
+ include Noosfero::Gravatar
+ include ThemeLoaderHelper
+ include ProfileImageHelper
+
+ should "Extra info with hash" do
+ @plugins = mock
+ @plugins.stubs(:dispatch_first).returns(false)
+ env = Environment.default
+ stubs(:environment).returns(env)
+ stubs(:profile).returns(profile)
+ profile = fast_create(Person, :environment_id => env.id)
+ info = {:value =>_('New'), :class => 'new-profile'}
+ html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
+ assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' }
+ assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New'
+ end
+
+ should "Extra info without hash" do
+ @plugins = mock
+ @plugins.stubs(:dispatch_first).returns(false)
+ env = Environment.default
+ stubs(:environment).returns(env)
+ stubs(:profile).returns(profile)
+ profile = fast_create(Person, :environment_id => env.id)
+ info = 'new'
+ html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
+ assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new'
+ end
+
+ should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do
+ env = Environment.default
+ env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false)
+ stubs(:environment).returns(env)
+ profile = Profile.new
+ assert_nil links_for_balloon(profile)
+ end
+
+ should 'return ordered list of links to balloon to Person' do
+ env = Environment.default
+ env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
+ stubs(:environment).returns(env)
+ person = Person.new identifier: 'person'
+ person.stubs(:url).returns('url for person')
+ person.stubs(:public_profile_url).returns('url for person')
+ links = links_for_balloon(person)
+ assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first}
+ end
+
+ should 'return ordered list of links to balloon to Community' do
+ env = Environment.default
+ env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
+ stubs(:environment).returns(env)
+ community = Community.new identifier: 'comm'
+ community.stubs(:url).returns('url for community')
+ community.stubs(:public_profile_url).returns('url for community')
+ links = links_for_balloon(community)
+ assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first}
+ end
+
+ should 'return ordered list of links to balloon to Enterprise' do
+ env = Environment.default
+ env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
+ stubs(:environment).returns(env)
+ enterprise = Enterprise.new identifier: 'coop'
+ enterprise.stubs(:url).returns('url for enterprise')
+ enterprise.stubs(:public_profile_url).returns('url for enterprise')
+ stubs(:catalog_path)
+ links = links_for_balloon(enterprise)
+ assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first}
+ end
+
+ should 'not return mime type of profile icon if not requested' do
+ stubs(:profile).returns(Person.new)
+ stubs(:current_theme).returns('default')
+
+ filename, mime = profile_icon(Person.new, :thumb)
+ assert_not_nil filename
+ assert_nil mime
+ end
+
+ should 'return mime type of profile icon' do
+ stubs(:profile).returns(Person.new)
+ stubs(:current_theme).returns('default')
+
+ filename, mime = profile_icon(Person.new, :thumb, true)
+ assert_not_nil filename
+ assert_not_nil mime
+ end
+
+ should 'provide sex icon for males' do
+ stubs(:environment).returns(Environment.default)
+ expects(:content_tag).with(anything, 'male').returns('MALE!!')
+ expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL")
+ assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male'))
+ end
+
+ should 'provide sex icon for females' do
+ stubs(:environment).returns(Environment.default)
+ expects(:content_tag).with(anything, 'female').returns('FEMALE!!')
+ expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL")
+ assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female'))
+ end
+
+ should 'provide undef sex icon' do
+ stubs(:environment).returns(Environment.default)
+ expects(:content_tag).with(anything, 'undef').returns('UNDEF!!')
+ expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL")
+ assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil))
+ end
+
+ should 'not draw sex icon for non-person profiles' do
+ assert_equal '', profile_sex_icon(Community.new)
+ end
+
+ should 'not draw sex icon when disabled in the environment' do
+ env = fast_create(Environment, :name => 'env test')
+ env.expects(:enabled?).with('disable_gender_icon').returns(true)
+ stubs(:environment).returns(env)
+ assert_equal '', profile_sex_icon(build(Person, :sex => 'male'))
+ end
+
+ should 'gravatar default parameter' do
+ profile = mock
+ profile.stubs(:theme).returns('some-theme')
+ stubs(:profile).returns(profile)
+
+ NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
+ assert_equal gravatar_default, 'crazyvatar'
+
+ stubs(:theme_option).returns('gravatar' => 'nicevatar')
+ NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
+ assert_equal gravatar_default, 'nicevatar'
+ end
+end
\ No newline at end of file
diff --git a/test/unit/theme_loader_helper_test.rb b/test/unit/theme_loader_helper_test.rb
new file mode 100644
index 0000000..917cd62
--- /dev/null
+++ b/test/unit/theme_loader_helper_test.rb
@@ -0,0 +1,36 @@
+# encoding: UTF-8
+require_relative "../test_helper"
+
+class ThemeLoaderHelperTest < ActionView::TestCase
+ include ThemeLoaderHelper
+
+ should 'get theme from environment by default' do
+ @environment = mock
+ @environment.stubs(:theme).returns('my-environment-theme')
+ stubs(:profile).returns(nil)
+ stubs(:environment).returns(@environment)
+ assert_equal 'my-environment-theme', current_theme
+ end
+
+ should 'get theme from profile when profile is present' do
+ profile = mock
+ profile.stubs(:theme).returns('my-profile-theme')
+ stubs(:profile).returns(profile)
+ assert_equal 'my-profile-theme', current_theme
+ end
+
+ should 'override theme with testing theme from session' do
+ stubs(:session).returns(:theme => 'theme-under-test')
+ assert_equal 'theme-under-test', current_theme
+ end
+
+ should 'point to system theme path by default' do
+ expects(:current_theme).returns('my-system-theme')
+ assert_equal '/designs/themes/my-system-theme', theme_path
+ end
+
+ should 'point to user theme path when testing theme' do
+ stubs(:session).returns({:theme => 'theme-under-test'})
+ assert_equal '/user_themes/theme-under-test', theme_path
+ end
+end
\ No newline at end of file
--
libgit2 0.21.2