#!/usr/bin/env ruby
# $Id: test_common.rb,v 1.3 2004/05/12 10:42:27 eto Exp $
# 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/server"
require "pp"

module TestSession
  $KCODE = "u"

  def setup
    @config = Qwik::Config.new(true)
    @config.test = true # do not send mail
    @config.pass_file = "./password.txt"
    @org_data_dir = @config.data_dir.dup
    @config.data_dir = "./"
    @dir = "./test/".path
    @dir.rmtree if @dir.directory?
    @dir.rmdir  if @dir.directory?
    @dir.mkdir if !@dir.directory?
    @memory = Qwik::ServerMemory.new(@config)

    @req = Qwik::Request.new(@config)
    @res = Qwik::Response.new(@config)
    @req.cookies["user"] = "test@example.com"
    @req.cookies["pass"] = "ABAB4B32"
    @site = Qwik::Site.new(@config, "test")

    @pagename = "TestPage"
    options = Hash.new("")
    options["config"]   = @config
    options["memory"]   = @memory
    options["req"]      = @req
    options["res"]      = @res
    options["pagename"] = @pagename
    options["site"]     = @site
    options["user"]     = "test@example.com"
    @plugin = Qwik::Plugin.new(options)
    @site.plugin = @plugin
  end

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

module TestSite
  include TestSession
end
