22 |
22 |
class Redmine::PluginTest < ActiveSupport::TestCase
|
23 |
23 |
def setup
|
24 |
24 |
@klass = Redmine::Plugin
|
|
25 |
# Change plugin directory for testing to default
|
|
26 |
# plugins/foo => test/fixtures/plugins/foo
|
|
27 |
@klass.directory = Rails.root.join('test/fixtures/plugins')
|
25 |
28 |
# In case some real plugins are installed
|
26 |
29 |
@klass.clear
|
27 |
30 |
end
|
... | ... | |
31 |
34 |
end
|
32 |
35 |
|
33 |
36 |
def test_register
|
34 |
|
@klass.register :foo do
|
|
37 |
@klass.register :foo_plugin do
|
35 |
38 |
name 'Foo plugin'
|
36 |
39 |
url 'http://example.net/plugins/foo'
|
37 |
40 |
author 'John Smith'
|
... | ... | |
43 |
46 |
|
44 |
47 |
assert_equal 1, @klass.all.size
|
45 |
48 |
|
46 |
|
plugin = @klass.find('foo')
|
|
49 |
plugin = @klass.find('foo_plugin')
|
47 |
50 |
assert plugin.is_a?(Redmine::Plugin)
|
48 |
|
assert_equal :foo, plugin.id
|
|
51 |
assert_equal :foo_plugin, plugin.id
|
49 |
52 |
assert_equal 'Foo plugin', plugin.name
|
50 |
53 |
assert_equal 'http://example.net/plugins/foo', plugin.url
|
51 |
54 |
assert_equal 'John Smith', plugin.author
|
... | ... | |
55 |
58 |
end
|
56 |
59 |
|
57 |
60 |
def test_installed
|
58 |
|
@klass.register(:foo) {}
|
59 |
|
assert_equal true, @klass.installed?(:foo)
|
|
61 |
@klass.register(:foo_plugin) {}
|
|
62 |
assert_equal true, @klass.installed?(:foo_plugin)
|
60 |
63 |
assert_equal false, @klass.installed?(:bar)
|
61 |
64 |
end
|
62 |
65 |
|
63 |
66 |
def test_menu
|
64 |
67 |
assert_difference 'Redmine::MenuManager.items(:project_menu).size' do
|
65 |
|
@klass.register :foo do
|
|
68 |
@klass.register :foo_plugin do
|
66 |
69 |
menu :project_menu, :foo_menu_item, '/foo', :caption => 'Foo'
|
67 |
70 |
end
|
68 |
71 |
end
|
... | ... | |
77 |
80 |
def test_delete_menu_item
|
78 |
81 |
Redmine::MenuManager.map(:project_menu).push(:foo_menu_item, '/foo', :caption => 'Foo')
|
79 |
82 |
assert_difference 'Redmine::MenuManager.items(:project_menu).size', -1 do
|
80 |
|
@klass.register :foo do
|
|
83 |
@klass.register :foo_plugin do
|
81 |
84 |
delete_menu_item :project_menu, :foo_menu_item
|
82 |
85 |
end
|
83 |
86 |
end
|
... | ... | |
88 |
91 |
|
89 |
92 |
def test_directory_with_override
|
90 |
93 |
@klass.register(:foo) do
|
91 |
|
directory '/path/to/foo'
|
|
94 |
directory 'test/fixtures/plugins/foo_plugin'
|
92 |
95 |
end
|
93 |
|
assert_equal '/path/to/foo', @klass.find('foo').directory
|
|
96 |
assert_equal 'test/fixtures/plugins/foo_plugin', @klass.find('foo').directory
|
94 |
97 |
end
|
95 |
98 |
|
96 |
99 |
def test_directory_without_override
|
97 |
|
@klass.register(:foo) {}
|
98 |
|
assert_equal File.join(@klass.directory, 'foo'), @klass.find('foo').directory
|
|
100 |
@klass.register(:other_plugin) {}
|
|
101 |
assert_equal File.join(@klass.directory, 'other_plugin'), @klass.find('other_plugin').directory
|
99 |
102 |
end
|
100 |
103 |
|
101 |
104 |
def test_requires_redmine
|
102 |
|
plugin = Redmine::Plugin.register(:foo) {}
|
|
105 |
plugin = Redmine::Plugin.register(:foo_plugin) {}
|
103 |
106 |
Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "stable", 10817])
|
104 |
107 |
# Specific version without hash
|
105 |
108 |
assert plugin.requires_redmine('2.1.3')
|
... | ... | |
148 |
151 |
def test_requires_redmine_plugin
|
149 |
152 |
test = self
|
150 |
153 |
other_version = '0.5.0'
|
151 |
|
@klass.register :other do
|
|
154 |
@klass.register :other_plugin do
|
152 |
155 |
name 'Other'
|
153 |
156 |
version other_version
|
154 |
157 |
end
|
155 |
|
@klass.register :foo do
|
156 |
|
test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
|
157 |
|
test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
|
158 |
|
test.assert requires_redmine_plugin(:other, other_version)
|
|
158 |
@klass.register :foo_plugin do
|
|
159 |
test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => '0.1.0')
|
|
160 |
test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => other_version)
|
|
161 |
test.assert requires_redmine_plugin(:other_plugin, other_version)
|
159 |
162 |
test.assert_raise Redmine::PluginRequirementError do
|
160 |
|
requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
|
|
163 |
requires_redmine_plugin(:other_plugin, :version_or_higher => '99.0.0')
|
161 |
164 |
end
|
162 |
|
test.assert requires_redmine_plugin(:other, :version => other_version)
|
163 |
|
test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
|
|
165 |
test.assert requires_redmine_plugin(:other_plugin, :version => other_version)
|
|
166 |
test.assert requires_redmine_plugin(:other_plugin, :version => [other_version, '99.0.0'])
|
164 |
167 |
test.assert_raise Redmine::PluginRequirementError do
|
165 |
|
requires_redmine_plugin(:other, :version => '99.0.0')
|
|
168 |
requires_redmine_plugin(:other_plugin, :version => '99.0.0')
|
166 |
169 |
end
|
167 |
170 |
test.assert_raise Redmine::PluginRequirementError do
|
168 |
|
requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
|
|
171 |
requires_redmine_plugin(:other_plugin, :version => ['98.0.0', '99.0.0'])
|
169 |
172 |
end
|
170 |
173 |
# Missing plugin
|
171 |
174 |
test.assert_raise Redmine::PluginRequirementError do
|
... | ... | |
181 |
184 |
end
|
182 |
185 |
|
183 |
186 |
def test_settings_warns_about_possible_partial_collision
|
184 |
|
@klass.register(:foo) { settings :partial => 'foo/settings' }
|
|
187 |
@klass.register(:foo_plugin) { settings :partial => 'foo/settings' }
|
185 |
188 |
Rails.logger.expects(:warn)
|
186 |
|
@klass.register(:bar) { settings :partial => 'foo/settings' }
|
|
189 |
@klass.register(:other_plugin) { settings :partial => 'foo/settings' }
|
187 |
190 |
end
|
188 |
191 |
|
189 |
192 |
def test_migrate_redmine_plugin
|
190 |
|
@klass.register :foo do
|
|
193 |
@klass.register :foo_plugin do
|
191 |
194 |
name 'Foo plugin'
|
192 |
195 |
version '0.0.1'
|
193 |
196 |
end
|
194 |
197 |
|
195 |
|
assert Redmine::Plugin.migrate('foo')
|
|
198 |
assert Redmine::Plugin.migrate('foo_plugin')
|
196 |
199 |
end
|
197 |
200 |
end
|