Skip to content

Commit

Permalink
Merge branch 'test_plugin_pr' of git://github.com/zunda/tdiary-core i…
Browse files Browse the repository at this point in the history
…nto zunda-test_plugin_pr
  • Loading branch information
hsbt committed Nov 3, 2012
2 parents 68fcb0e + 1583c59 commit 87b10db
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
45 changes: 42 additions & 3 deletions test/test_plugin_helper.rb
Expand Up @@ -4,7 +4,12 @@ def add_header_proc(*args); end
def add_body_enter_proc(*args); end
def add_update_proc(*args); end
def add_conf_proc(*args); end
def add_title_proc(*args); end
def add_subtitle_proc(*args); end
def add_footer_proc(*args); end
def feed?; false; end
def enable_js(*args); end
def add_js_setting(*args); end
def to_native( str, charset = nil )
from = case charset
when /^utf-8$/i
Expand All @@ -19,7 +24,41 @@ def to_native( str, charset = nil )
NKF::nkf( "-m0 -#{from}w", str )
end
end
end

include TDiary::PluginTestStub
@options = {}
module PluginTestHelper
def PluginTestHelper.absolute_path_of(plugin_relative_path)
File.expand_path(File.join(File.dirname(__FILE__), '..', plugin_relative_path))
end

def PluginTestHelper.resource_relative_path_of(plugin_relative_path, lang)
File.join(File.dirname(plugin_relative_path), lang, File.basename(plugin_relative_path))
end

def PluginTestHelper.resource_absolute_path_of(plugin_relative_path, lang)
ppath = PluginTestHelper.absolute_path_of(plugin_relative_path)
File.join(File.dirname(ppath), lang, File.basename(ppath))
end
end

class ConfStub
def style; 'tDiary'; end
end

class PluginTestCase < Test::Unit::TestCase
include TDiary::PluginTestStub

def add_stub_ivars
@options = {}
@conf_genre_label = {}
@conf = TDiary::ConfStub.new
end

def load_plugin(plugin_relative_path, lang = 'en', context = binding)
add_stub_ivars
ppath = PluginTestHelper.absolute_path_of(plugin_relative_path)
pl10n = PluginTestHelper.resource_absolute_path_of(plugin_relative_path, lang)
File.open(pl10n){|f| eval(f.read, context, PluginTestHelper.resource_relative_path_of(plugin_relative_path, lang))}
File.open(ppath){|f| eval(f.read, context, plugin_relative_path)}
end
end
end
28 changes: 28 additions & 0 deletions test/test_plugin_helper_test.rb
@@ -0,0 +1,28 @@
# Test cases for test_plugin_helper.rb
require File.expand_path('../test_helper', __FILE__)
require File.expand_path('../test_plugin_helper', __FILE__)

class TestPluginHelper < TDiary::PluginTestCase
def test_absolute_path_of
abspath = File.expand_path(File.join(File.dirname(__FILE__), '..', 'plugin', '00default.rb'))
assert_equal(abspath, TDiary::PluginTestHelper.absolute_path_of('plugin/00default.rb'))
end

def test_resource_absolute_path_of
abspath = File.expand_path(File.join(File.dirname(__FILE__), '..', 'plugin', 'en', '00default.rb'))
assert_equal(abspath, TDiary::PluginTestHelper.resource_absolute_path_of('plugin/00default.rb', 'en'))
end

def test_resource_relative_path_of
abspath = File.join('plugin', 'en', '00default.rb')
assert_equal(abspath, TDiary::PluginTestHelper.resource_relative_path_of('plugin/00default.rb', 'en'))
end

def test_load_plugin_en
assert_nothing_raised{load_plugin('plugin/00default.rb', 'en', binding)}
end

def test_load_plugin_ja
assert_nothing_raised{load_plugin('plugin/00default.rb', 'ja', binding)}
end
end
33 changes: 33 additions & 0 deletions test/weather_test.rb
@@ -0,0 +1,33 @@
require File.expand_path('../test_helper', __FILE__)
require File.expand_path('../test_plugin_helper', __FILE__)

module EmptyRenderingTests
def setup
load_plugin('misc/plugin/weather.rb', language, binding)
@weather = Weather.new
end

def test_empty_rendering_to_html
assert_equal('', @weather.to_html)
end

def test_empty_rendering_to_i_html
assert_equal('', @weather.to_i_html)
end
end

class TestEmptyRenderingEn < TDiary::PluginTestCase
include EmptyRenderingTests

def language
"en"
end
end

class TestEmptyRenderingJa < TDiary::PluginTestCase
include EmptyRenderingTests

def language
"ja"
end
end

0 comments on commit 87b10db

Please sign in to comment.