diff options
author | Go MAEDA <maeda@farend.jp> | 2019-05-19 22:27:41 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-05-19 22:27:41 +0000 |
commit | f992df684fe4db936ee56c1e7d334eebfae40329 (patch) | |
tree | 901f0b13ad2abe01c93116280a0ce3d435ec515c /test/helpers | |
parent | 6f8bfab179ce785a08d13d137f849c6bfece0df9 (diff) | |
download | redmine-f992df684fe4db936ee56c1e7d334eebfae40329.tar.gz redmine-f992df684fe4db936ee56c1e7d334eebfae40329.zip |
Small refactorization of avatar methods (#31391).
* move existing methods from ApplicationHelper to a new helper file (AvatarsHelper)
* change default avatar size from 50 to 24 because most of the avatars are using the size 24
* class 'gravatar' is always added and all custom classes are appended
* added user name as default title for avatar images
* added two new methods: @assignee_avatar@ and @author_avatar@
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@18175 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/helpers')
-rw-r--r-- | test/helpers/application_helper_test.rb | 81 | ||||
-rw-r--r-- | test/helpers/avatars_helper_test.rb | 93 |
2 files changed, 93 insertions, 81 deletions
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 41ed07bc1..2804c3253 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1495,87 +1495,6 @@ RAW assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}" end - def test_avatar_with_user - with_settings :gravatar_enabled => '1' do - assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar(User.find_by_mail('jsmith@somenet.foo')) - end - end - - def test_avatar_with_email_string - with_settings :gravatar_enabled => '1' do - assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar('jsmith <jsmith@somenet.foo>') - end - end - - def test_avatar_with_anonymous_user - with_settings :gravatar_enabled => '1' do - assert_match %r{src="/images/anonymous.png(\?\d+)?"}, avatar(User.anonymous) - end - end - - def test_avatar_with_group - with_settings :gravatar_enabled => '1' do - assert_nil avatar(Group.first) - end - end - - def test_avatar_with_invalid_arg_should_return_nil - with_settings :gravatar_enabled => '1' do - assert_nil avatar('jsmith') - assert_nil avatar(nil) - end - end - - def test_avatar_default_size_should_be_50 - with_settings :gravatar_enabled => '1' do - assert_include 'size=50', avatar('jsmith <jsmith@somenet.foo>') - end - end - - def test_avatar_with_size_option - with_settings :gravatar_enabled => '1' do - assert_include 'size=24', avatar('jsmith <jsmith@somenet.foo>', :size => 24) - assert_include 'width="24" height="24"', avatar(User.anonymous, :size => 24) - end - end - - def test_avatar_with_html_option - with_settings :gravatar_enabled => '1' do - # Non-avatar options should be considered html options - assert_include 'title="John Smith"', avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith') - end - end - - def test_avatar_css_class - with_settings :gravatar_enabled => '1' do - # The default class of the img tag should be gravatar - assert_include 'class="gravatar"', avatar('jsmith <jsmith@somenet.foo>') - assert_not_include 'class="gravatar"', avatar('jsmith <jsmith@somenet.foo>', :class => 'picture') - assert_include 'class="picture"', avatar('jsmith <jsmith@somenet.foo>', :class => 'picture') - end - end - - def test_avatar_disabled - with_settings :gravatar_enabled => '0' do - assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) - end - end - - def test_avatar_server_url - to_test = { - 'https://www.gravatar.com' => %r|https://www.gravatar.com/avatar/\h{32}|, - 'https://seccdn.libravatar.org' => %r|https://seccdn.libravatar.org/avatar/\h{32}|, - 'http://localhost:8080' => %r|http://localhost:8080/avatar/\h{32}|, - } - with_settings :gravatar_enabled => '1' do - to_test.each do |url, expected| - Redmine::Configuration.with 'avatar_server_url' => url do - assert_match expected, avatar('<jsmith@somenet.foo>') - end - end - end - end - def test_link_to_user user = User.find(2) result = link_to("John Smith", "/users/2", :class => "user active") diff --git a/test/helpers/avatars_helper_test.rb b/test/helpers/avatars_helper_test.rb new file mode 100644 index 000000000..a02ced8e1 --- /dev/null +++ b/test/helpers/avatars_helper_test.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2017 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class AvatarsHelperTest < Redmine::HelperTest + include ERB::Util + include Rails.application.routes.url_helpers + include AvatarsHelper + + fixtures :users, :email_addresses + + def setup + Setting.gravatar_enabled = '1' + end + + def test_avatar_with_user + assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar(User.find_by_mail('jsmith@somenet.foo')) + end + + def test_avatar_with_email_string + assert_include Digest::MD5.hexdigest('jsmith@somenet.foo'), avatar('jsmith <jsmith@somenet.foo>') + end + + def test_avatar_with_anonymous_user + assert_match %r{src="/images/anonymous.png(\?\d+)?"}, avatar(User.anonymous) + end + + def test_avatar_with_group + assert_nil avatar(Group.first) + end + + def test_avatar_with_invalid_arg_should_return_nil + assert_nil avatar('jsmith') + assert_nil avatar(nil) + end + + def test_avatar_default_size_should_be_24 + assert_include 'size=24', avatar('jsmith <jsmith@somenet.foo>') + end + + def test_avatar_with_size_option + assert_include 'size=24', avatar('jsmith <jsmith@somenet.foo>', :size => 24) + assert_include 'width="24" height="24"', avatar(User.anonymous, :size => 24) + end + + def test_avatar_with_html_option + # Non-avatar options should be considered html options + assert_include 'title="John Smith"', avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith') + end + + def test_avatar_css_class + # The default class of the img tag should be gravatar + assert_include 'class="gravatar"', avatar('jsmith <jsmith@somenet.foo>') + assert_include 'class="gravatar picture"', avatar('jsmith <jsmith@somenet.foo>', :class => 'picture') + end + + def test_avatar_disabled + with_settings :gravatar_enabled => '0' do + assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) + end + end + + def test_avatar_server_url + to_test = { + 'https://www.gravatar.com' => %r|https://www.gravatar.com/avatar/\h{32}|, + 'https://seccdn.libravatar.org' => %r|https://seccdn.libravatar.org/avatar/\h{32}|, + 'http://localhost:8080' => %r|http://localhost:8080/avatar/\h{32}|, + } + + to_test.each do |url, expected| + Redmine::Configuration.with 'avatar_server_url' => url do + assert_match expected, avatar('<jsmith@somenet.foo>') + end + end + end +end |