#!/usr/bin/env ruby
# $Id: tc_ext_rss.rb,v 1.9 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.

require 'test_common'

class TC_RSS < Test::Unit::TestCase
  include TestSite

  def test_rss
    page = @site.create("1")
    page.store("* あ")

    # test_rss091
    rssgen = Qwik::RSS091Generator.new(@config, @site)
    xml = rssgen.generate
    assert_equal('<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">', xml.doctype.to_s)
    assert_equal("0.91", xml.elements['/rss'].attribute('version').to_s)
    assert_equal("qwik.jp/test", xml.elements['/rss/channel/title'].text.to_s)
    assert_equal("http://qwik.jp/test/", xml.elements['/rss/channel/link'].text.to_s)

    # test_rss10
    rssgen = Qwik::RSS10Generator.new(@config, @site)
    xml = rssgen.generate
    #puts xml.to_s(0)
    assert_equal("http://purl.org/rss/1.0/", xml.elements['/rdf:RDF'].attribute('xmlns').to_s)
  end
end

class TC_RssGet < Test::Unit::TestCase
  include TestSession

  def test_get_rss
    @site.member.add('test@example.com')
    @site.create_new.store('* あ')

    assert_equal("<a href='test.rss'>RSS</a>", "{{rss}}".w.html_p(@site))

    @req.parse_host_path('qwik.jp', '/test/test.rss')
    @session = Qwik::Session.new(@config, @memory, @req, @res)
    @session.run
    str = @res.body
#    puts xml.to_xhtml(0)
    assert_equal("application/xml", @res['Content-Type'])
    assert_match(/qwik.jp\/test/, str)
  end
end
