Sha256: 86098f9d7d47cb93953225b552712549f9b1b1a50dac33ff58be4b42b00c2f8c

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

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

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.unflag(:dirty)
    @website.blackboard.dispatch_msg(:node_changed?, root)
    assert(!root.flagged(:dirty))

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

end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.7.20090227 test/test_tag_includefile.rb
thewoolleyman-webgen-0.5.8.20090419 test/test_tag_includefile.rb
webgen-0.5.7 test/test_tag_includefile.rb