# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")
require "qwik/generator-plain"

module Qwik
  class Action
    def act_test_plain # only for check design
      #w = c_get("TextFormatSimple")
      w = c_get("TextFormat")
      #w = login_page("http://example.com/HelloQwik/")
      c_plain("act_test_plain"){w}
    end

    def c_plain(title, status=200, &b)
      msg = yield
      generate_plain_page(status, title, msg)
    end

    def generate_plain_page(status, title, msg)
      @res.status = status
      template = @memory.template.get("plain")
      @res.body = Qwik::PlainPageGenerator.generate(template, title, msg)
      c_set_html
      c_set_no_cache
      nil
    end
  end
end

if $0 == __FILE__
  require "t/test"
  $debug = true
end

if $debug
  class TC_ActPlain < Test::Unit::TestCase
    include TestSession

    def test_all
      res = session

      @action.generate_plain_page(200, "title", "msg")
      assert_equal(200, res.status)
      assert_xpath([:title, "title"], "title", res)

      @action.c_plain("c_plain title"){"msg"}
      assert_equal(200, res.status)
      assert_xpath([:title, "c_plain title"], "title", res)

      t_add_user

      res = session("/test/.test_plain")
      assert_xpath([:title, "act_test_plain"], "title", res)
    end
  end
end
