Sha256: 375a2fa1c85a4988097410ced175223bc30c55ae956770f978cafc742295acdd

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

require 'test/unit'
require 'helper'
require 'fileutils'
require 'tempfile'
require 'webgen/tag'

class TestTagIncludeFile < Test::Unit::TestCase

  include Test::WebsiteHelper

  def setup
    super
    @obj = Webgen::Tag::IncludeFile.new
  end

  def call(context, filename, process, escape)
    @obj.set_params({'tag.includefile.filename' => filename,
                      'tag.includefile.process_output' => process,
                      'tag.includefile.escape_html' => escape})
    result = @obj.call('include_file', '', context)
    @obj.set_params({})
    result
  end

  def test_call
    root = Webgen::Node.new(Webgen::Tree.new.dummy_root, '/', '/')
    context = Webgen::ContentProcessor::Context.new(:chain => [root])

    content = "<a>This is 'a' Test</a>"
    file = Tempfile.new('webgen-test-file')
    file.write(content)
    file.close

    assert_equal([content, false], call(context, file.path, false, false))
    assert_equal([content, true], call(context, file.path, true, false))
    assert_equal([CGI::escapeHTML(content), true], call(context, file.path, true, true))
    assert_raise(Errno::ENOENT) { call(context, 'invalidfile', true, true) }

    root.dirty = false
    @website.blackboard.dispatch_msg(:node_changed?, root)
    assert(!root.dirty)

    File.utime(Time.now + 1, Time.now + 1, file.path)
    @website.blackboard.dispatch_msg(:node_changed?, root)
    assert(root.dirty)
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 test/test_tag_includefile.rb
gettalong-webgen-0.5.5.20081001 test/test_tag_includefile.rb
webgen-0.5.2 test/test_tag_includefile.rb
webgen-0.5.3 test/test_tag_includefile.rb
webgen-0.5.4 test/test_tag_includefile.rb
webgen-0.5.1 test/test_tag_includefile.rb
webgen-0.5.5 test/test_tag_includefile.rb