test/test_context.rb in webgen-0.5.8 vs test/test_context.rb in webgen-0.5.9
- old
+ new
@@ -4,18 +4,32 @@
require 'helper'
require 'webgen/context'
class TestContext < Test::Unit::TestCase
+ include Test::WebsiteHelper
+
def setup
+ super
@context = Webgen::Context.new(:content => 'test', :key => :value, :chain => [:first, :last])
end
def test_initialize
context = Webgen::Context.new
assert_equal('', context.content)
+ assert_equal({}, context.persistent)
assert_kind_of(Webgen::ContentProcessor::AccessHash, context[:processors])
+
+ context = Webgen::Context.new(:content => 'test', :key => :value)
+ assert_equal('test', context.content)
+ assert_equal(:value, context[:key])
+ assert_equal({}, context.persistent)
+
+ context = Webgen::Context.new({:content => 'test', :key => :value}, {:other => :val})
+ assert_equal('test', context.content)
+ assert_equal(:value, context[:key])
+ assert_equal({:other => :val}, context.persistent)
end
def test_clone
other = @context.clone(:content => 'new', :key => :other)
assert_equal('new', other.content)
@@ -35,8 +49,33 @@
assert_equal(:first, @context.ref_node)
assert_equal(:last, @context.content_node)
assert_equal(:last, @context.dest_node)
@context[:dest_node] = :other
assert_equal(:other, @context.dest_node)
+ end
+
+ def test_tags_methods
+ @context[:chain] = [Webgen::Tree.new.dummy_root]
+
+ klass = Class.new do
+ def set_params(*args); end
+ def create_tag_params(*args); end
+ def create_params_hash(*args); end
+ def call(tag, body, context); 'mivalue'; end
+ end
+ (@website.cache.volatile[:classes] ||= {})['TestTag'] = klass.new
+ @website.config['contentprocessor.tags.map'].update(:default => 'TestTag')
+
+ assert_equal('mivalue', @context.tag('mivalue'))
+ end
+
+ def test_render_methods
+ root = Webgen::Node.new(Webgen::Tree.new.dummy_root, '/', '/')
+ node = Webgen::Node.new(root, 'test', 'test')
+ node.node_info[:page] = Webgen::Page.from_data("--- name:content\ndata\n--- name:other\nother")
+ @context[:chain] = [root, node]
+
+ assert_equal('data', @context.render_block('content'))
+ assert_equal('other', @context.render_block(:name => 'other'))
end
end