annotate .svn/pristine/e3/e31701d543027feaaec6f5716a6efe5c0c48db65.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 module RedmineMenuTestHelper
Chris@909 21 # Helpers
Chris@909 22 def get_menu_item(menu_name, item_name)
Chris@909 23 Redmine::MenuManager.items(menu_name).find {|item| item.name == item_name.to_sym}
Chris@909 24 end
Chris@909 25 end
Chris@909 26
Chris@909 27 class Redmine::MenuManager::MenuItemTest < ActiveSupport::TestCase
Chris@909 28 include RedmineMenuTestHelper
Chris@909 29
Chris@909 30 Redmine::MenuManager.map :test_menu do |menu|
Chris@909 31 menu.push(:parent, '/test', { })
Chris@909 32 menu.push(:child_menu, '/test', { :parent => :parent})
Chris@909 33 menu.push(:child2_menu, '/test', { :parent => :parent})
Chris@909 34 end
Chris@909 35
Chris@909 36 context "MenuItem#caption" do
Chris@909 37 should "be tested"
Chris@909 38 end
Chris@909 39
Chris@909 40 context "MenuItem#html_options" do
Chris@909 41 should "be tested"
Chris@909 42 end
Chris@909 43
Chris@909 44 # context new menu item
Chris@909 45 def test_new_menu_item_should_require_a_name
Chris@909 46 assert_raises ArgumentError do
Chris@909 47 Redmine::MenuManager::MenuItem.new
Chris@909 48 end
Chris@909 49 end
Chris@909 50
Chris@909 51 def test_new_menu_item_should_require_an_url
Chris@909 52 assert_raises ArgumentError do
Chris@909 53 Redmine::MenuManager::MenuItem.new(:test_missing_url)
Chris@909 54 end
Chris@909 55 end
Chris@909 56
Chris@909 57 def test_new_menu_item_should_require_the_options
Chris@909 58 assert_raises ArgumentError do
Chris@909 59 Redmine::MenuManager::MenuItem.new(:test_missing_options, '/test')
Chris@909 60 end
Chris@909 61 end
Chris@909 62
Chris@909 63 def test_new_menu_item_with_all_required_parameters
Chris@909 64 assert Redmine::MenuManager::MenuItem.new(:test_good_menu, '/test', {})
Chris@909 65 end
Chris@909 66
Chris@909 67 def test_new_menu_item_should_require_a_proc_to_use_for_the_if_condition
Chris@909 68 assert_raises ArgumentError do
Chris@909 69 Redmine::MenuManager::MenuItem.new(:test_error, '/test',
Chris@909 70 {
Chris@909 71 :if => ['not_a_proc']
Chris@909 72 })
Chris@909 73 end
Chris@909 74
Chris@909 75 assert Redmine::MenuManager::MenuItem.new(:test_good_if, '/test',
Chris@909 76 {
Chris@909 77 :if => Proc.new{}
Chris@909 78 })
Chris@909 79 end
Chris@909 80
Chris@909 81 def test_new_menu_item_should_allow_a_hash_for_extra_html_options
Chris@909 82 assert_raises ArgumentError do
Chris@909 83 Redmine::MenuManager::MenuItem.new(:test_error, '/test',
Chris@909 84 {
Chris@909 85 :html => ['not_a_hash']
Chris@909 86 })
Chris@909 87 end
Chris@909 88
Chris@909 89 assert Redmine::MenuManager::MenuItem.new(:test_good_html, '/test',
Chris@909 90 {
Chris@909 91 :html => { :onclick => 'doSomething'}
Chris@909 92 })
Chris@909 93 end
Chris@909 94
Chris@909 95 def test_new_menu_item_should_require_a_proc_to_use_the_children_option
Chris@909 96 assert_raises ArgumentError do
Chris@909 97 Redmine::MenuManager::MenuItem.new(:test_error, '/test',
Chris@909 98 {
Chris@909 99 :children => ['not_a_proc']
Chris@909 100 })
Chris@909 101 end
Chris@909 102
Chris@909 103 assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test',
Chris@909 104 {
Chris@909 105 :children => Proc.new{}
Chris@909 106 })
Chris@909 107 end
Chris@909 108
Chris@909 109 def test_new_should_not_allow_setting_the_parent_item_to_the_current_item
Chris@909 110 assert_raises ArgumentError do
Chris@909 111 Redmine::MenuManager::MenuItem.new(:test_error, '/test', { :parent => :test_error })
Chris@909 112 end
Chris@909 113 end
Chris@909 114
Chris@909 115 def test_has_children
Chris@909 116 parent_item = get_menu_item(:test_menu, :parent)
Chris@909 117 assert parent_item.hasChildren?
Chris@909 118 assert_equal 2, parent_item.children.size
Chris@909 119 assert_equal get_menu_item(:test_menu, :child_menu), parent_item.children[0]
Chris@909 120 assert_equal get_menu_item(:test_menu, :child2_menu), parent_item.children[1]
Chris@909 121 end
Chris@909 122 end