Mercurial > hg > soundsoftware-site
comparison .svn/pristine/2d/2d611b348b4b0790a149102dbbb27f7bf647e472.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::PluginTest < ActiveSupport::TestCase | |
21 | |
22 def setup | |
23 @klass = Redmine::Plugin | |
24 # In case some real plugins are installed | |
25 @klass.clear | |
26 end | |
27 | |
28 def teardown | |
29 @klass.clear | |
30 end | |
31 | |
32 def test_register | |
33 @klass.register :foo do | |
34 name 'Foo plugin' | |
35 url 'http://example.net/plugins/foo' | |
36 author 'John Smith' | |
37 author_url 'http://example.net/jsmith' | |
38 description 'This is a test plugin' | |
39 version '0.0.1' | |
40 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' | |
41 end | |
42 | |
43 assert_equal 1, @klass.all.size | |
44 | |
45 plugin = @klass.find('foo') | |
46 assert plugin.is_a?(Redmine::Plugin) | |
47 assert_equal :foo, plugin.id | |
48 assert_equal 'Foo plugin', plugin.name | |
49 assert_equal 'http://example.net/plugins/foo', plugin.url | |
50 assert_equal 'John Smith', plugin.author | |
51 assert_equal 'http://example.net/jsmith', plugin.author_url | |
52 assert_equal 'This is a test plugin', plugin.description | |
53 assert_equal '0.0.1', plugin.version | |
54 end | |
55 | |
56 def test_installed | |
57 @klass.register(:foo) {} | |
58 | |
59 assert_equal true, @klass.installed?(:foo) | |
60 assert_equal false, @klass.installed?(:bar) | |
61 end | |
62 | |
63 def test_menu | |
64 assert_difference 'Redmine::MenuManager.items(:project_menu).size' do | |
65 @klass.register :foo do | |
66 menu :project_menu, :foo_menu_item, '/foo', :caption => 'Foo' | |
67 end | |
68 end | |
69 menu_item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name == :foo_menu_item} | |
70 assert_not_nil menu_item | |
71 assert_equal 'Foo', menu_item.caption | |
72 assert_equal '/foo', menu_item.url | |
73 end | |
74 | |
75 def test_delete_menu_item | |
76 Redmine::MenuManager.map(:project_menu).push(:foo_menu_item, '/foo', :caption => 'Foo') | |
77 | |
78 assert_difference 'Redmine::MenuManager.items(:project_menu).size', -1 do | |
79 @klass.register :foo do | |
80 delete_menu_item :project_menu, :foo_menu_item | |
81 end | |
82 end | |
83 assert_nil Redmine::MenuManager.items(:project_menu).detect {|i| i.name == :foo_menu_item} | |
84 end | |
85 | |
86 def test_requires_redmine | |
87 plugin = Redmine::Plugin.register(:foo) {} | |
88 Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "stable", 10817]) | |
89 | |
90 # Specific version without hash | |
91 assert plugin.requires_redmine('2.1.3') | |
92 assert plugin.requires_redmine('2.1') | |
93 assert_raise Redmine::PluginRequirementError do | |
94 plugin.requires_redmine('2.1.4') | |
95 end | |
96 assert_raise Redmine::PluginRequirementError do | |
97 plugin.requires_redmine('2.2') | |
98 end | |
99 | |
100 # Specific version | |
101 assert plugin.requires_redmine(:version => '2.1.3') | |
102 assert plugin.requires_redmine(:version => ['2.1.3', '2.2.0']) | |
103 assert plugin.requires_redmine(:version => '2.1') | |
104 assert_raise Redmine::PluginRequirementError do | |
105 plugin.requires_redmine(:version => '2.2.0') | |
106 end | |
107 assert_raise Redmine::PluginRequirementError do | |
108 plugin.requires_redmine(:version => ['2.1.4', '2.2.0']) | |
109 end | |
110 assert_raise Redmine::PluginRequirementError do | |
111 plugin.requires_redmine(:version => '2.2') | |
112 end | |
113 | |
114 # Version range | |
115 assert plugin.requires_redmine(:version => '2.0.0'..'2.2.4') | |
116 assert plugin.requires_redmine(:version => '2.1.3'..'2.2.4') | |
117 assert plugin.requires_redmine(:version => '2.0.0'..'2.1.3') | |
118 assert plugin.requires_redmine(:version => '2.0'..'2.2') | |
119 assert plugin.requires_redmine(:version => '2.1'..'2.2') | |
120 assert plugin.requires_redmine(:version => '2.0'..'2.1') | |
121 assert_raise Redmine::PluginRequirementError do | |
122 plugin.requires_redmine(:version => '2.1.4'..'2.2.4') | |
123 end | |
124 | |
125 | |
126 # Version or higher | |
127 assert plugin.requires_redmine(:version_or_higher => '0.1.0') | |
128 assert plugin.requires_redmine(:version_or_higher => '2.1.3') | |
129 assert plugin.requires_redmine(:version_or_higher => '2.1') | |
130 assert_raise Redmine::PluginRequirementError do | |
131 plugin.requires_redmine(:version_or_higher => '2.2.0') | |
132 end | |
133 assert_raise Redmine::PluginRequirementError do | |
134 plugin.requires_redmine(:version_or_higher => '2.2') | |
135 end | |
136 end | |
137 | |
138 def test_requires_redmine_plugin | |
139 test = self | |
140 other_version = '0.5.0' | |
141 | |
142 @klass.register :other do | |
143 name 'Other' | |
144 version other_version | |
145 end | |
146 | |
147 @klass.register :foo do | |
148 test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0') | |
149 test.assert requires_redmine_plugin(:other, :version_or_higher => other_version) | |
150 test.assert requires_redmine_plugin(:other, other_version) | |
151 test.assert_raise Redmine::PluginRequirementError do | |
152 requires_redmine_plugin(:other, :version_or_higher => '99.0.0') | |
153 end | |
154 | |
155 test.assert requires_redmine_plugin(:other, :version => other_version) | |
156 test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0']) | |
157 test.assert_raise Redmine::PluginRequirementError do | |
158 requires_redmine_plugin(:other, :version => '99.0.0') | |
159 end | |
160 test.assert_raise Redmine::PluginRequirementError do | |
161 requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0']) | |
162 end | |
163 # Missing plugin | |
164 test.assert_raise Redmine::PluginNotFound do | |
165 requires_redmine_plugin(:missing, :version_or_higher => '0.1.0') | |
166 end | |
167 test.assert_raise Redmine::PluginNotFound do | |
168 requires_redmine_plugin(:missing, '0.1.0') | |
169 end | |
170 test.assert_raise Redmine::PluginNotFound do | |
171 requires_redmine_plugin(:missing, :version => '0.1.0') | |
172 end | |
173 | |
174 end | |
175 end | |
176 end |