Project

General

Profile

Defect #41715 » allow_custom_svg_icons_for_admin_menu.patch

Takenori TAKAKI, 2024-11-08 12:23

View differences:

lib/redmine/menu_manager.rb
182 182
        end
183 183

  
184 184
        label = if item.icon.present?
185
                  sprite_icon(item.icon, h(caption))
185
                  sprite_icon(item.icon, h(caption), plugin: item.plugin)
186 186
                else
187 187
                  h(caption)
188 188
                end
......
431 431
    class MenuItem < MenuNode
432 432
      include Redmine::I18n
433 433
      attr_reader :name, :url, :param, :condition, :parent,
434
                  :child_menus, :last, :permission, :icon
434
                  :child_menus, :last, :permission, :icon, :plugin
435 435

  
436 436
      def initialize(name, url, options={})
437 437
        if options[:if] && !options[:if].respond_to?(:call)
......
461 461
        @parent = options[:parent]
462 462
        @child_menus = options[:children]
463 463
        @last = options[:last] || false
464
        @plugin = options[:plugin]
464 465
        super(@name.to_sym)
465 466
      end
466 467

  
test/unit/lib/redmine/menu_manager/menu_helper_test.rb
42 42
    assert_select("a.testing", "This is a test")
43 43
  end
44 44

  
45
  def test_render_single_menu_node_with_plugin_icon
46
    node = Redmine::MenuManager::MenuItem.new(:testing, '/test', { :icon => 'plugin_icon_name',:plugin => 'test_plugin_name' })
47
    @output_buffer = render_single_menu_node(node, 'This is a test', node.url, false)
48

  
49
    assert_select("a.testing", "This is a test") do
50
      assert_select("svg.icon-svg") do
51
        assert_select("use[href=?]", "/assets/plugin_assets/test_plugin_name/icons.svg#icon--plugin_icon_name")
52
      end
53
    end
54
  end
55

  
45 56
  def test_render_menu_node
46 57
    single_node = Redmine::MenuManager::MenuItem.new(:single_node, '/test', {})
47 58
    @output_buffer = render_menu_node(single_node, nil)
test/unit/lib/redmine/menu_manager/menu_item_test.rb
102 102
    end
103 103
  end
104 104

  
105
  def test_new_menu_item_should_allow_setting_the_plugin
106
    menu_item = Redmine::MenuManager::MenuItem.new(
107
      :test_plugin_menu, '/test', {:plugin => 'test_plugin_name'}
108
    )
109
    assert_equal 'test_plugin_name', menu_item.plugin
110
  end
111

  
105 112
  def test_has_children
106 113
    parent_item = get_menu_item(:test_menu, :parent)
107 114
    assert parent_item.children.present?
(2-2/2)