annotate test/unit/lib/redmine/menu_manager/mapper_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents e248c7af89ec
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
Chris@1464 21 test "Mapper#initialize should define a root MenuNode if menu is not present in items" do
Chris@1464 22 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@1464 23 node = menu_mapper.menu_items
Chris@1464 24 assert_not_nil node
Chris@1464 25 assert_equal :root, node.name
Chris@1464 26 end
Chris@1464 27
Chris@1464 28 test "Mapper#initialize should use existing MenuNode if present" do
Chris@1464 29 node = "foo" # just an arbitrary reference
Chris@1464 30 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
Chris@1464 31 assert_equal node, menu_mapper.menu_items
Chris@0 32 end
Chris@0 33
Chris@0 34 def test_push_onto_root
Chris@0 35 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 36 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 37
Chris@0 38 menu_mapper.exists?(:test_overview)
Chris@0 39 end
Chris@0 40
Chris@0 41 def test_push_onto_parent
Chris@0 42 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 43 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 44 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
Chris@0 45
Chris@0 46 assert menu_mapper.exists?(:test_child)
Chris@0 47 assert_equal :test_child, menu_mapper.find(:test_child).name
Chris@0 48 end
Chris@0 49
Chris@0 50 def test_push_onto_grandparent
Chris@0 51 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 52 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 53 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview}
Chris@0 54 menu_mapper.push :test_grandchild, { :controller => 'projects', :action => 'show'}, {:parent => :test_child}
Chris@0 55
Chris@0 56 assert menu_mapper.exists?(:test_grandchild)
Chris@0 57 grandchild = menu_mapper.find(:test_grandchild)
Chris@0 58 assert_equal :test_grandchild, grandchild.name
Chris@0 59 assert_equal :test_child, grandchild.parent.name
Chris@0 60 end
Chris@0 61
Chris@0 62 def test_push_first
Chris@0 63 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 64 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@0 65 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@0 66 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 67 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 68 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {:first => true}
Chris@0 69
Chris@0 70 root = menu_mapper.find(:root)
Chris@0 71 assert_equal 5, root.children.size
Chris@0 72 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@0 73 assert_not_nil root.children[position]
Chris@0 74 assert_equal name, root.children[position].name
Chris@0 75 end
Chris@909 76
Chris@0 77 end
Chris@909 78
Chris@0 79 def test_push_before
Chris@0 80 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 81 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@0 82 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@0 83 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 84 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 85 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {:before => :test_fourth}
Chris@0 86
Chris@0 87 root = menu_mapper.find(:root)
Chris@0 88 assert_equal 5, root.children.size
Chris@0 89 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@0 90 assert_not_nil root.children[position]
Chris@0 91 assert_equal name, root.children[position].name
Chris@0 92 end
Chris@909 93
Chris@0 94 end
Chris@0 95
Chris@0 96 def test_push_after
Chris@0 97 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 98 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@0 99 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@0 100 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@0 101 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 102 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {:after => :test_third}
Chris@0 103
Chris@0 104 root = menu_mapper.find(:root)
Chris@0 105 assert_equal 5, root.children.size
Chris@0 106 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@0 107 assert_not_nil root.children[position]
Chris@0 108 assert_equal name, root.children[position].name
Chris@0 109 end
Chris@909 110
Chris@0 111 end
Chris@0 112
Chris@0 113 def test_push_last
Chris@0 114 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 115 menu_mapper.push :test_first, { :controller => 'projects', :action => 'show'}, {}
Chris@0 116 menu_mapper.push :test_second, { :controller => 'projects', :action => 'show'}, {}
Chris@0 117 menu_mapper.push :test_third, { :controller => 'projects', :action => 'show'}, {}
Chris@0 118 menu_mapper.push :test_fifth, { :controller => 'projects', :action => 'show'}, {:last => true}
Chris@0 119 menu_mapper.push :test_fourth, { :controller => 'projects', :action => 'show'}, {}
Chris@0 120
Chris@0 121 root = menu_mapper.find(:root)
Chris@0 122 assert_equal 5, root.children.size
Chris@0 123 {0 => :test_first, 1 => :test_second, 2 => :test_third, 3 => :test_fourth, 4 => :test_fifth}.each do |position, name|
Chris@0 124 assert_not_nil root.children[position]
Chris@0 125 assert_equal name, root.children[position].name
Chris@0 126 end
Chris@909 127
Chris@0 128 end
Chris@909 129
Chris@0 130 def test_exists_for_child_node
Chris@0 131 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 132 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 133 menu_mapper.push :test_child, { :controller => 'projects', :action => 'show'}, {:parent => :test_overview }
Chris@0 134
Chris@0 135 assert menu_mapper.exists?(:test_child)
Chris@0 136 end
Chris@0 137
Chris@0 138 def test_exists_for_invalid_node
Chris@0 139 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 140 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 141
Chris@0 142 assert !menu_mapper.exists?(:nothing)
Chris@0 143 end
Chris@0 144
Chris@0 145 def test_find
Chris@0 146 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 147 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 148
Chris@0 149 item = menu_mapper.find(:test_overview)
Chris@0 150 assert_equal :test_overview, item.name
Chris@0 151 assert_equal({:controller => 'projects', :action => 'show'}, item.url)
Chris@0 152 end
Chris@0 153
Chris@0 154 def test_find_missing
Chris@0 155 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 156 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 157
Chris@0 158 item = menu_mapper.find(:nothing)
Chris@0 159 assert_equal nil, item
Chris@0 160 end
Chris@0 161
Chris@0 162 def test_delete
Chris@0 163 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 164 menu_mapper.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 165 assert_not_nil menu_mapper.delete(:test_overview)
Chris@0 166
Chris@0 167 assert_nil menu_mapper.find(:test_overview)
Chris@0 168 end
Chris@0 169
Chris@0 170 def test_delete_missing
Chris@0 171 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
Chris@0 172 assert_nil menu_mapper.delete(:test_missing)
Chris@0 173 end
Chris@0 174
Chris@0 175 test 'deleting all items' do
Chris@0 176 # Exposed by deleting :last items
Chris@0 177 Redmine::MenuManager.map :test_menu do |menu|
Chris@0 178 menu.push :not_last, Redmine::Info.help_url
Chris@0 179 menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
Chris@0 180 menu.push :help, Redmine::Info.help_url, :last => true
Chris@0 181 end
Chris@0 182
Chris@0 183 assert_nothing_raised do
Chris@0 184 Redmine::MenuManager.map :test_menu do |menu|
Chris@0 185 menu.delete(:administration)
Chris@0 186 menu.delete(:help)
Chris@0 187 menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
Chris@0 188 end
Chris@0 189 end
Chris@0 190 end
Chris@0 191 end