]> source.dussan.org Git - redmine.git/commitdiff
Implementing more unit tests for the plugin hooks
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 29 Jul 2008 00:02:23 +0000 (17:02 -0700)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 29 Jul 2008 00:02:23 +0000 (17:02 -0700)
test/unit/lib/redmine/plugin_hook_test.rb

index 75634d85cfb80dd05110e113fc57e7c8ee0739d3..22b58541b31abca087a024de4850977858ac1aed 100644 (file)
@@ -1,9 +1,52 @@
 require File.dirname(__FILE__) + '/../../../test_helper'
 
 class Redmine::Plugin::Hook::ManagerTest < Test::Unit::TestCase
+  def setup
+    @manager =  Redmine::Plugin::Hook::Manager
+  end
+  
+  def teardown
+    @manager.clear_listeners
+  end
+  
   def test_sanity
     assert true
   end
+  
+  def test_hook_format
+    assert_kind_of Hash, @manager::hooks
+    @manager::hooks.each do |hook, registrations|
+      assert_kind_of Symbol, hook
+      assert_kind_of Array, registrations
+      assert_equal 0, registrations.length
+    end
+  end
+  
+  def test_valid_hook
+    assert @manager::valid_hook?(:issue_show)
+  end
+  
+  def test_invalid_hook
+    assert_equal false, @manager::valid_hook?(:an_invalid_hook_name)
+  end
+  
+  def test_clear_listeners
+    assert_equal 0, @manager::hooks[:issue_show].length
+    @manager.add_listener(:issue_show, Proc.new { } )
+    @manager.add_listener(:issue_show, Proc.new { } )
+    @manager.add_listener(:issue_show, Proc.new { } )
+    @manager.add_listener(:issue_show, Proc.new { } )
+    assert_equal 4, @manager::hooks[:issue_show].length
+    
+    @manager.clear_listeners
+    assert_equal 0, @manager::hooks[:issue_show].length
+  end
+  
+  def test_add_listener
+    assert_equal 0, @manager::hooks[:issue_show].length
+    @manager.add_listener(:issue_show, Proc.new { } )
+    assert_equal 1, @manager::hooks[:issue_show].length
+  end
 end
 
 class Redmine::Plugin::Hook::BaseTest < Test::Unit::TestCase