Sha256: b92b11e6a28b96f4766a52c672273b7b2428104b8417b20ea292bcf6cc30a990

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

# -*- encoding: utf-8 -*-

require 'webgen/test_helper'
require 'webgen/path_handler/page_utils'
require 'webgen/content_processor'
require 'webgen/path'

class TestPageUtils < MiniTest::Unit::TestCase

  include Webgen::TestHelper

  class MyHandler
    include Webgen::PathHandler::PageUtils
  end

  def setup
    @handler = MyHandler.new
  end

  def test_parse_as_page!
    path = Webgen::Path.new('/test.html') { StringIO.new("---\nkey: value\n---\ncontent") }
    blocks = @handler.send(:parse_as_page!, path)
    assert_kind_of(Hash, blocks)
    assert_equal('content', blocks['content'])
    assert_equal('value', path.meta_info['key'])
  end

  def test_render_block
    setup_context
    node = @context.node
    node.expect(:blocks, {'content' => 'mycontent'})
    @context.node.expect(:meta_info, {})
    @website.ext.content_processor = Webgen::ContentProcessor.new
    @website.ext.item_tracker = MiniTest::Mock.new
    @website.ext.item_tracker.expect(:add, nil, [node, :node_content, node.alcn])

    # invalid block name
    assert_raises(Webgen::RenderError) { @handler.render_block(node, 'unknown', @context) }

    # nothing to render because pipeline is empty
    @handler.render_block(node, 'content', @context)
    assert_equal('mycontent', @context.content)

    # invalid content processor
    assert_raises(Webgen::Error) { @handler.render_block(node, 'content', @context, ['test']) }

    node.meta_info['blocks'] = {'content' => {'pipeline' => ['test']}}
    assert_raises(Webgen::Error) { @handler.render_block(node, 'content', @context) }

    # with content processor
    @website.ext.content_processor.register('test') {|ctx| ctx.content = 'test' + ctx.content; ctx}
    @handler.render_block(node, 'content', @context)
    assert_equal('testmycontent', @context.content)

    @handler.render_block(node, 'content', @context, ['test', 'test'])
    assert_equal('testtestmycontent', @context.content)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webgen-1.0.0.beta1 test/webgen/path_handler/test_page_utils.rb