1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
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.
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.
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.
18 require File.dirname(__FILE__) + '/../../../test_helper'
20 class Redmine::PluginTest < ActiveSupport::TestCase
23 @klass = Redmine::Plugin
24 # In case some real plugins are installed
33 @klass.register :foo do
35 url 'http://example.net/plugins/foo'
37 author_url 'http://example.net/jsmith'
38 description 'This is a test plugin'
40 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
43 assert_equal 1, @klass.all.size
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
56 def test_requires_redmine
58 version = Redmine::VERSION.to_a.slice(0,3).join('.')
60 @klass.register :foo do
61 test.assert requires_redmine(:version_or_higher => '0.1.0')
62 test.assert requires_redmine(:version_or_higher => version)
63 test.assert requires_redmine(version)
64 test.assert_raise Redmine::PluginRequirementError do
65 requires_redmine(:version_or_higher => '99.0.0')
68 test.assert requires_redmine(:version => version)
69 test.assert requires_redmine(:version => [version, '99.0.0'])
70 test.assert_raise Redmine::PluginRequirementError do
71 requires_redmine(:version => '99.0.0')
73 test.assert_raise Redmine::PluginRequirementError do
74 requires_redmine(:version => ['98.0.0', '99.0.0'])
79 def test_requires_redmine_plugin
81 other_version = '0.5.0'
83 @klass.register :other do
88 @klass.register :foo do
89 test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
90 test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
91 test.assert requires_redmine_plugin(:other, other_version)
92 test.assert_raise Redmine::PluginRequirementError do
93 requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
96 test.assert requires_redmine_plugin(:other, :version => other_version)
97 test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
98 test.assert_raise Redmine::PluginRequirementError do
99 requires_redmine_plugin(:other, :version => '99.0.0')
101 test.assert_raise Redmine::PluginRequirementError do
102 requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
105 test.assert_raise Redmine::PluginNotFound do
106 requires_redmine_plugin(:missing, :version_or_higher => '0.1.0')
108 test.assert_raise Redmine::PluginNotFound do
109 requires_redmine_plugin(:missing, '0.1.0')
111 test.assert_raise Redmine::PluginNotFound do
112 requires_redmine_plugin(:missing, :version => '0.1.0')