#!/usr/bin/env ruby
# $Id$
# Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL2.

$LOAD_PATH.unshift('../../lib')
$LOAD_PATH.unshift('../../compat')
require 'test/unit'
require 'qwik/site'
require 'qwik/extension'
require 'qwik/ext_form'

class TC_Form < Test::Unit::TestCase
#  $KCODE = 'u'
  def setup()
    @config = Qwik::Config.new(true)
    @config.data_dir = './'
    @dir = './test/'.path
    @dir.rmtree if @dir.directory?
    @dir.rmdir  if @dir.directory?
    @dir.mkdir if !@dir.directory?

    @site = Qwik::Site.new(@config, 'test')
    @pagename = "TestPage"
    options = Hash.new('')
    options['pagename'] = @pagename
    options['site']     = @site
    @plugin = Qwik::Plugin.new(@config, options)
    @site.plugin = @plugin
  end

  def test_form
    page = @site.pages.create_new
    str = <<"EOS"
{{form
|項目|{{input(name,default,must)}}|
|説明|
||{{submit( 投稿 )}}|
}}
EOS
    page.store(str)
    xml = page.load.w.res(@site)
    assert_equal("<body><div class='form'><form action='TestPage.html' method='POST'><input name='page' type='hidden' value='TestPage'/><table class='form'><tr><td class='midashi'>項目</td><td class='nakami'><input name='name' size='must' value='default'/></td></tr><tr><td class='msg' colspan='2'>説明</td></tr><tr><td class='midashi'></td><td class='nakami'><input class='submit' type='submit' value=' 投稿 '/></td></tr></table></form></div></body>", xml.to_s)
  end

  def teardown()
    @dir.rmtree if @dir.directory?
    @dir.rmdir  if @dir.directory?
  end
end

