Chris@0: # Redmine - project management software Chris@0: # Copyright (C) 2006-2008 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: require File.dirname(__FILE__) + '/../../../test_helper' Chris@0: Chris@0: class Redmine::PluginTest < ActiveSupport::TestCase Chris@0: Chris@0: def setup Chris@0: @klass = Redmine::Plugin Chris@0: # In case some real plugins are installed Chris@0: @klass.clear Chris@0: end Chris@0: Chris@0: def teardown Chris@0: @klass.clear Chris@0: end Chris@0: Chris@0: def test_register Chris@0: @klass.register :foo do Chris@0: name 'Foo plugin' Chris@0: url 'http://example.net/plugins/foo' Chris@0: author 'John Smith' Chris@0: author_url 'http://example.net/jsmith' Chris@0: description 'This is a test plugin' Chris@0: version '0.0.1' Chris@0: settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' Chris@0: end Chris@0: Chris@0: assert_equal 1, @klass.all.size Chris@0: Chris@0: plugin = @klass.find('foo') Chris@0: assert plugin.is_a?(Redmine::Plugin) Chris@0: assert_equal :foo, plugin.id Chris@0: assert_equal 'Foo plugin', plugin.name Chris@0: assert_equal 'http://example.net/plugins/foo', plugin.url Chris@0: assert_equal 'John Smith', plugin.author Chris@0: assert_equal 'http://example.net/jsmith', plugin.author_url Chris@0: assert_equal 'This is a test plugin', plugin.description Chris@0: assert_equal '0.0.1', plugin.version Chris@0: end Chris@0: Chris@0: def test_requires_redmine Chris@0: test = self Chris@0: version = Redmine::VERSION.to_a.slice(0,3).join('.') Chris@0: Chris@0: @klass.register :foo do Chris@0: test.assert requires_redmine(:version_or_higher => '0.1.0') Chris@0: test.assert requires_redmine(:version_or_higher => version) Chris@0: test.assert requires_redmine(version) Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine(:version_or_higher => '99.0.0') Chris@0: end Chris@0: Chris@0: test.assert requires_redmine(:version => version) Chris@0: test.assert requires_redmine(:version => [version, '99.0.0']) Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine(:version => '99.0.0') Chris@0: end Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine(:version => ['98.0.0', '99.0.0']) Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: def test_requires_redmine_plugin Chris@0: test = self Chris@0: other_version = '0.5.0' Chris@0: Chris@0: @klass.register :other do Chris@0: name 'Other' Chris@0: version other_version Chris@0: end Chris@0: Chris@0: @klass.register :foo do Chris@0: test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0') Chris@0: test.assert requires_redmine_plugin(:other, :version_or_higher => other_version) Chris@0: test.assert requires_redmine_plugin(:other, other_version) Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine_plugin(:other, :version_or_higher => '99.0.0') Chris@0: end Chris@0: Chris@0: test.assert requires_redmine_plugin(:other, :version => other_version) Chris@0: test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0']) Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine_plugin(:other, :version => '99.0.0') Chris@0: end Chris@0: test.assert_raise Redmine::PluginRequirementError do Chris@0: requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0']) Chris@0: end Chris@0: # Missing plugin Chris@0: test.assert_raise Redmine::PluginNotFound do Chris@0: requires_redmine_plugin(:missing, :version_or_higher => '0.1.0') Chris@0: end Chris@0: test.assert_raise Redmine::PluginNotFound do Chris@0: requires_redmine_plugin(:missing, '0.1.0') Chris@0: end Chris@0: test.assert_raise Redmine::PluginNotFound do Chris@0: requires_redmine_plugin(:missing, :version => '0.1.0') Chris@0: end Chris@0: Chris@0: end Chris@0: end Chris@0: end