commit 237d1d8dcd1e1cc210135e34ca0bd37b4f6f3535 Author: Felix Schäfer Date: Thu Dec 12 16:09:47 2013 +0100 Themes are able to provide a favicon #15689 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 357a7e0..951ce67 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1254,7 +1254,8 @@ module ApplicationHelper end def favicon - "".html_safe + fav_path = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico' + "".html_safe end def robot_exclusion_tag diff --git a/lib/redmine/themes.rb b/lib/redmine/themes.rb index eb2ba91..c69244f 100644 --- a/lib/redmine/themes.rb +++ b/lib/redmine/themes.rb @@ -75,6 +75,18 @@ module Redmine @javascripts ||= assets("javascripts", "js") end + def favicons + @favicons ||= assets("favicon") + end + + def favicon + favicons.first + end + + def favicon? + favicon.present? + end + def stylesheet_path(source) "/themes/#{dir}/stylesheets/#{source}" end @@ -87,6 +99,10 @@ module Redmine "/themes/#{dir}/javascripts/#{source}" end + def favicon_path + "/themes/#{dir}/favicon/#{favicon}" + end + private def assets(dir, ext=nil) diff --git a/test/integration/lib/redmine/themes_test.rb b/test/integration/lib/redmine/themes_test.rb index 6d286ef..1089628 100644 --- a/test/integration/lib/redmine/themes_test.rb +++ b/test/integration/lib/redmine/themes_test.rb @@ -57,9 +57,42 @@ class ThemesTest < ActionController::IntegrationTest @theme.javascripts.delete 'theme' end + def test_use_default_favicon_if_theme_provides_none + get '/' + + assert_response :success + assert_tag tag: 'link', + attributes: {rel: 'shortcut icon', href: %r{\A/favicon.ico}} + end + + def test_use_theme_favicon_if_theme_provides_one + # Simulate a theme favicon + @theme.favicons << 'a.ico' + get '/' + + assert_response :success + assert_tag tag: 'link', + attributes: {rel: 'shortcut icon', href: %r{\A/themes/#{@theme.dir}/favicon/a.ico}} + ensure + @theme.favicons.delete 'a.ico' + end + + def test_use_only_one_theme_favicon_if_theme_provides_many + @theme.favicons.concat %w{b.ico a.png} + get '/' + + assert_response :success + assert_tag tag: 'link', + attributes: {rel: 'shortcut icon', href: %r{\A/themes/#{@theme.dir}/favicon/b.ico}} + ensure + @theme.favicons.delete("b.ico") + @theme.favicons.delete("a.png") + end + def test_with_sub_uri Redmine::Utils.relative_url_root = '/foo' @theme.javascripts << 'theme' + @theme.favicons << 'a.ico' get '/' assert_response :success @@ -67,7 +100,8 @@ class ThemesTest < ActionController::IntegrationTest :attributes => {:href => %r{^/foo/themes/#{@theme.dir}/stylesheets/application.css}} assert_tag :tag => 'script', :attributes => {:src => %r{^/foo/themes/#{@theme.dir}/javascripts/theme.js}} - + assert_tag tag: 'link', + attributes: {rel: 'shortcut icon', href: %r{\A/foo/themes/#{@theme.dir}/favicon/a.ico}} ensure Redmine::Utils.relative_url_root = '' end