diff options
author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-03 07:03:33 +0000 |
---|---|---|
committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-03 07:03:33 +0000 |
commit | 3d712cdd9d1f99c6bcc106898783bafe9d2c1cde (patch) | |
tree | 1ce4ff588fbcb18b51b107e186cd9caf10bf8686 | |
parent | 4e8d491b9024549fd8237531e4dab5f72af5704a (diff) | |
download | ruby-3d712cdd9d1f99c6bcc106898783bafe9d2c1cde.tar.gz |
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/rss/maker/0.9.rb | 160 | ||||
-rw-r--r-- | lib/rss/maker/2.0.rb | 129 | ||||
-rw-r--r-- | lib/rss/maker/base.rb | 430 | ||||
-rw-r--r-- | lib/rss/maker/content.rb | 29 | ||||
-rw-r--r-- | lib/rss/maker/dublincore.rb | 47 | ||||
-rw-r--r-- | lib/rss/maker/syndication.rb | 27 | ||||
-rw-r--r-- | lib/rss/maker/trackback.rb | 30 | ||||
-rw-r--r-- | test/rss/test_maker_0.9.rb | 397 | ||||
-rw-r--r-- | test/rss/test_maker_1.0.rb | 363 | ||||
-rw-r--r-- | test/rss/test_maker_2.0.rb | 622 | ||||
-rw-r--r-- | test/rss/test_maker_xml-stylesheet.rb | 75 |
11 files changed, 2309 insertions, 0 deletions
diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb new file mode 100644 index 0000000000..05578082b0 --- /dev/null +++ b/lib/rss/maker/0.9.rb @@ -0,0 +1,160 @@ +require "rss/0.9" + +require "rss/maker/base" + +module RSS + module Maker + + class RSS09 < RSSBase + + def initialize(rss_version="0.91") + super + end + + def to_rss + rss = Rss.new(@rss_version, @version, @encoding, @standalone) + setup_xml_stylesheets(rss) + setup_channel(rss) + setup_other_elements(rss) + if rss.channel + rss + else + nil + end + end + + private + def setup_channel(rss) + @channel.to_rss(rss) + end + + class Channel < ChannelBase + + def to_rss(rss) + channel = Rss::Channel.new + set = setup_values(channel) + if set + rss.channel = channel + setup_items(rss) + setup_image(rss) + setup_textinput(rss) + setup_other_elements(rss) + if rss.channel.image + rss + else + nil + end + end + end + + def have_required_values? + @title and @link and @description and @language and + @maker.image.have_required_values? + end + + private + def setup_items(rss) + @maker.items.to_rss(rss) + end + + def setup_image(rss) + @maker.image.to_rss(rss) + end + + def setup_textinput(rss) + @maker.textinput.to_rss(rss) + end + + def variables + super + ["pubDate"] + end + + class Cloud < CloudBase + end + + end + + class Image < ImageBase + def to_rss(rss) + image = Rss::Channel::Image.new + set = setup_values(image) + if set + image.link = link + rss.channel.image = image + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @title and link + end + end + + class Items < ItemsBase + def to_rss(rss) + if rss.channel + normalize.each do |item| + item.to_rss(rss) + end + setup_other_elements(rss) + end + end + + class Item < ItemBase + def to_rss(rss) + item = Rss::Channel::Item.new + set = setup_values(item) + if set + rss.items << item + setup_other_elements(rss) + end + end + + private + def have_required_values? + @title and @link + end + + class Guid < GuidBase + def to_rss(*args) + end + end + + class Enclosure < EnclosureBase + def to_rss(*args) + end + end + + class Source < SourceBase + def to_rss(*args) + end + end + + class Category < CategoryBase + def to_rss(*args) + end + end + + end + end + + class Textinput < TextinputBase + def to_rss(rss) + textInput = Rss::Channel::TextInput.new + set = setup_values(textInput) + if set + rss.channel.textInput = textInput + setup_other_elements(rss) + end + end + + private + def have_required_values? + @title and @description and @name and @link + end + end + end + + add_maker(filename_to_version(__FILE__), RSS09) + end +end diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb new file mode 100644 index 0000000000..05fc46480a --- /dev/null +++ b/lib/rss/maker/2.0.rb @@ -0,0 +1,129 @@ +require "rss/2.0" + +require "rss/maker/0.9" + +module RSS + module Maker + + class RSS20 < RSS09 + + def initialize(rss_version="2.0") + super + end + + class Channel < RSS09::Channel + + add_other_element("cloud") + + def have_required_values? + @title and @link and @description + end + + private + def setup_cloud(rss, current) + @maker.channel.cloud.to_rss(rss) + end + + class Cloud < RSS09::Channel::Cloud + def to_rss(rss) + cloud = Rss::Channel::Cloud.new + set = setup_values(cloud) + if set + rss.channel.cloud = cloud + setup_other_elements(rss) + end + end + + def have_required_values? + @domain and @port and @path and + @registerProcedure and @protocol + end + end + end + + class Image < RSS09::Image + end + + class Items < RSS09::Items + + class Item < RSS09::Items::Item + + def have_required_values? + @title or @description + end + + private + def variables + super + ["pubDate"] + end + + class Guid < RSS09::Items::Item::Guid + def to_rss(rss, item) + guid = Rss::Channel::Item::Guid.new + set = setup_values(guid) + if set + item.guid = guid + setup_other_elements(rss) + end + end + + def have_required_values? + @content + end + end + + class Enclosure < RSS09::Items::Item::Enclosure + def to_rss(rss, item) + enclosure = Rss::Channel::Item::Enclosure.new + set = setup_values(enclosure) + if set + item.enclosure = enclosure + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @length and @type + end + end + + class Source < RSS09::Items::Item::Source + def to_rss(rss, item) + source = Rss::Channel::Item::Source.new + set = setup_values(source) + if set + item.source = source + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @content + end + end + + class Category < RSS09::Items::Item::Category + def to_rss(rss, item) + category = Rss::Channel::Item::Category.new + set = setup_values(category) + if set + item.category = category + setup_other_elements(rss) + end + end + + def have_required_values? + @content + end + end + end + + end + + class Textinput < RSS09::Textinput + end + end + + add_maker(filename_to_version(__FILE__), RSS20) + end +end diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb new file mode 100644 index 0000000000..21222351f2 --- /dev/null +++ b/lib/rss/maker/base.rb @@ -0,0 +1,430 @@ +require 'forwardable' + +require 'rss/rss' + +module RSS + module Maker + + module Base + + def self.append_features(klass) + super + + klass.module_eval(<<-EOC, __FILE__, __LINE__) + + OTHER_ELEMENTS = [] + NEED_INITIALIZE_VARIABLES = [] + + def self.inherited(subclass) + subclass.const_set("OTHER_ELEMENTS", []) + subclass.const_set("NEED_INITIALIZE_VARIABLES", []) + + subclass.module_eval(<<-EOEOC, __FILE__, __LINE__) + def self.other_elements + const_get("OTHER_ELEMENTS") + super + end + + def self.need_initialize_variables + const_get("NEED_INITIALIZE_VARIABLES") + super + end + EOEOC + end + + def self.add_other_element(variable_name) + const_get("OTHER_ELEMENTS") << variable_name + end + + def self.other_elements + OTHER_ELEMENTS + end + + def self.add_need_initialize_variable(variable_name) + const_get("NEED_INITIALIZE_VARIABLES") << variable_name + end + + def self.need_initialize_variables + NEED_INITIALIZE_VARIABLES + end + EOC + end + + def initialize(maker) + @maker = maker + initialize_variables + end + + def have_required_values? + true + end + + private + def initialize_variables + self.class.need_initialize_variables.each do |variable_name| + instance_eval("@#{variable_name} = nil", __FILE__, __LINE__) + end + end + + def setup_other_elements(rss) + self.class.other_elements.each do |element| + __send__("setup_#{element}", rss, current_element(rss)) + end + end + + def setup_values(target) + set = false + if have_required_values? + variables.each do |var| + setter = "#{var}=" + if target.respond_to?(setter) + value = self.__send__(var) + if value + target.__send__(setter, value) + set = true + end + end + end + end + set + end + + def variables + self.class.need_initialize_variables + end + + end + + class RSSBase + include Base + + class << self + def make(&block) + new.make(&block) + end + end + + attr_reader :rss_version, :xml_stylesheets + attr_reader :channel, :image, :items, :textinput + + attr_accessor :version, :encoding, :standalone + + def initialize(rss_version) + super(self) + @rss_version = rss_version + @version = "1.0" + @encoding = "UTF-8" + @standalone = nil + @xml_stylesheets = make_xml_stylesheets + @channel = make_channel + @image = make_image + @items = make_items + @textinput = make_textinput + end + + def make(&block) + block.call(self) if block + to_rss + end + + def current_element(rss) + rss + end + + private + def make_xml_stylesheets + XMLStyleSheets.new(self) + end + + def make_channel + self.class::Channel.new(self) + end + + def make_image + self.class::Image.new(self) + end + + def make_items + self.class::Items.new(self) + end + + def make_textinput + self.class::Textinput.new(self) + end + + def setup_xml_stylesheets(rss) + @xml_stylesheets.to_rss(rss) + end + + end + + class XMLStyleSheets + include Base + + include Enumerable + extend Forwardable + + def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last) + def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift) + def_delegators(:@xml_stylesheets, :each) + + def initialize(maker) + super + @xml_stylesheets = [] + end + + def to_rss(rss) + @xml_stylesheets.each do |xss| + xss.to_rss(rss) + end + end + + def new_xml_stylesheet + xss = XMLStyleSheet.new(@maker) + @xml_stylesheets << xss + xss + end + + class XMLStyleSheet + include Base + + ::RSS::XMLStyleSheet::ATTRIBUTES.each do |attribute| + attr_accessor attribute + add_need_initialize_variable(attribute) + end + + def to_rss(rss) + xss = ::RSS::XMLStyleSheet.new + guess_type_if_need(xss) + set = setup_values(xss) + if set + rss.xml_stylesheets << xss + end + end + + def have_required_values? + @href and @type + end + + private + def guess_type_if_need(xss) + if @type.nil? + xss.href = @href + @type = xss.type + end + end + end + end + + class ChannelBase + include Base + + attr_reader :cloud + + %w(about title link description language copyright + managingEditor webMaster rating docs skipDays + skipHours date lastBuildDate category generator ttl + ).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + alias_method(:pubDate, :date) + alias_method(:pubDate=, :date=) + + def initialize(maker) + super + @cloud = make_cloud + end + + def current_element(rss) + rss.channel + end + + private + def make_cloud + self.class::Cloud.new(@maker) + end + + class CloudBase + include Base + + %w(domain port path registerProcedure protocol).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def current_element(rss) + rss.channel.cloud + end + + end + end + + class ImageBase + include Base + + %w(title url width height description).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def link + @maker.channel.link + end + + def current_element(rss) + rss.image + end + end + + class ItemsBase + include Base + + include Enumerable + extend Forwardable + + def_delegators(:@items, :<<, :[], :[]=, :first, :last) + def_delegators(:@items, :push, :pop, :shift, :unshift) + def_delegators(:@items, :each) + + attr_accessor :do_sort + + def initialize(maker) + super + @items = [] + @do_sort = false + end + + def normalize + sort_if_need + end + + def current_element(rss) + rss.items + end + + def new_item + item = self.class::Item.new(@maker) + @items << item + item + end + + private + def sort_if_need + if @do_sort.respond_to?(:call) + @items.sort do |x, y| + @do_sort.call(x, y) + end + elsif @do_sort + @items.sort do |x, y| + y <=> x + end + else + @items + end + end + + class ItemBase + include Base + + %w(guid enclosure source category).each do |element| + attr_reader element + add_other_element(element) + module_eval(<<-EOC, __FILE__, __LINE__) + private + def setup_#{element}(rss, current) + @#{element}.to_rss(rss, current) + end + + def make_#{element} + self.class::#{element[0,1].upcase}#{element[1..-1]}.new(@maker) + end +EOC + end + + %w(title link description date author comments).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + alias_method(:pubDate, :date) + alias_method(:pubDate=, :date=) + + def initialize(maker) + super + @guid = make_guid + @enclosure = make_enclosure + @source = make_source + @category = make_category + end + + def <=>(other) + if @date and other.date + @date <=> other.date + elsif @date + 1 + elsif other.date + -1 + else + 0 + end + end + + def current_element(rss) + rss.items.last + end + + class GuidBase + include Base + + %w(isPermaLink content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class EnclosureBase + include Base + + %w(url length type).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class SourceBase + include Base + + %w(url content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class CategoryBase + include Base + + %w(domain content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + end + end + + class TextinputBase + include Base + + %w(title description name link).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def current_element(rss) + rss.textinput + end + + end + + end +end diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb new file mode 100644 index 0000000000..96f3ccb6d9 --- /dev/null +++ b/lib/rss/maker/content.rb @@ -0,0 +1,29 @@ +require 'rss/content' +require 'rss/maker/1.0' + +module RSS + module Maker + module ContentModel + def self.append_features(klass) + super + + ::RSS::ContentModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = @#{element} if @#{element} + end + end + EOC + end + end + end + + class ItemsBase + class ItemBase; include ContentModel; end + end + end +end diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb new file mode 100644 index 0000000000..a9b8d58715 --- /dev/null +++ b/lib/rss/maker/dublincore.rb @@ -0,0 +1,47 @@ +require 'rss/dublincore' +require 'rss/maker/1.0' + +module RSS + module Maker + module DublinCoreModel + def self.append_features(klass) + super + + ::RSS::DublinCoreModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = #{element} + end + end +EOC + end + end + end + + class ChannelBase + include DublinCoreModel + + undef_method(:dc_date) + undef_method(:dc_date=) + alias_method(:dc_date, :date) + alias_method(:dc_date=, :date=) + end + + class ImageBase; include DublinCoreModel; end + class ItemsBase + class ItemBase + include DublinCoreModel + + undef_method(:dc_date) + undef_method(:dc_date=) + alias_method(:dc_date, :date) + alias_method(:dc_date=, :date=) + end + end + class TextinputBase; include DublinCoreModel; end + end +end diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb new file mode 100644 index 0000000000..72d00c63ea --- /dev/null +++ b/lib/rss/maker/syndication.rb @@ -0,0 +1,27 @@ +require 'rss/syndication' +require 'rss/maker/1.0' + +module RSS + module Maker + module SyndicationModel + def self.append_features(klass) + super + + ::RSS::SyndicationModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = @#{element} if @#{element} + end + end + EOC + end + end + end + + class ChannelBase; include SyndicationModel; end + end +end diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb new file mode 100644 index 0000000000..1ec59ab0b0 --- /dev/null +++ b/lib/rss/maker/trackback.rb @@ -0,0 +1,30 @@ +require 'rss/trackback' +require 'rss/maker/1.0' + +module RSS + module Maker + module TrackBackModel + def self.append_features(klass) + super + + %w(ping about).each do |element| + name = "#{RSS::TRACKBACK_PREFIX}_#{element}" + klass.add_need_initialize_variable(name) + klass.add_other_element(name) + klass.__send__(:attr_accessor, name) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{name}(rss, current) + if #{name} and current.respond_to?(:#{name}=) + current.#{name} = @#{name} if @#{name} + end + end + EOC + end + end + end + + class ItemsBase + class ItemBase; include TrackBackModel; end + end + end +end diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb new file mode 100644 index 0000000000..df8cd5fe11 --- /dev/null +++ b/test/rss/test_maker_0.9.rb @@ -0,0 +1,397 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMaker09 < TestCase + + def test_rss + rss = RSS::Maker.make("0.9") + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + end + assert_equal("0.91", rss.rss_version) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.encoding = "EUC-JP" + end + assert_equal("0.91", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.standalone = "yes" + end + assert_equal("0.91", rss.rss_version) + assert_equal("yes", rss.standalone) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.encoding = "EUC-JP" + maker.standalone = "yes" + end + assert_equal("0.91", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + assert_equal("yes", rss.standalone) + end + + def test_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + copyright = "foo" + managingEditor = "bar" + webMaster = "web master" + rating = "6" + docs = "http://foo.com/doc" + skipDays = "Sunday" + skipHours = "13" + pubDate = Time.now + lastBuildDate = Time.now + + rss = RSS::Maker.make("0.9") do |maker| + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + maker.channel.copyright = copyright + maker.channel.managingEditor = managingEditor + maker.channel.webMaster = webMaster + maker.channel.rating = rating + maker.channel.docs = docs + maker.channel.skipDays = skipDays + maker.channel.skipHours = skipHours + maker.channel.pubDate = pubDate + maker.channel.lastBuildDate = lastBuildDate + + setup_dummy_image(maker) + end + channel = rss.channel + + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert_equal(language, channel.language) + assert_equal(copyright, channel.copyright) + assert_equal(managingEditor, channel.managingEditor) + assert_equal(webMaster, channel.webMaster) + assert_equal(rating, channel.rating) + assert_equal(docs, channel.docs) + assert_equal(skipDays, channel.skipDays) + assert_equal(skipHours, channel.skipHours) + assert_equal(pubDate, channel.pubDate) + assert_equal(lastBuildDate, channel.lastBuildDate) + + assert(channel.items.empty?) + assert_not_nil(channel.image) + assert_nil(channel.textInput) + end + + def test_not_valid_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + + rss = RSS::Maker.make("0.9") do |maker| + # setup_dummy_image(maker) + + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_image(maker) + + # maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_image(maker) + + maker.channel.title = title + # maker.channel.link = link + maker.channel.link = nil + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_image(maker) + + maker.channel.title = title + maker.channel.link = link + # maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_image(maker) + + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + # maker.channel.language = language + end + assert_nil(rss) + end + + def test_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + image = rss.image + assert_equal(title, image.title) + assert_equal(link, image.link) + assert_equal(url, image.url) + assert_equal(width, image.width) + assert_equal(height, image.height) + assert_equal(description, image.description) + + rss = RSS::Maker.make("0.9") do |maker| + # setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + end + + def test_not_valid_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + # maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + # maker.channel.link = link + maker.channel.link = nil + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + # maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + end + + def test_items + title = "TITLE" + link = "http://hoge.com/" + description = "text hoge fuga" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + end + assert(rss.channel.items.empty?) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + item = maker.items.new_item + item.title = title + item.link = link + # item.description = description + end + assert_equal(1, rss.channel.items.size) + item = rss.channel.items.first + assert_equal(title, item.title) + assert_equal(link, item.link) + assert_nil(item.description) + + + item_size = 5 + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.do_sort = true + end + assert_equal(item_size, rss.items.size) + rss.channel.items.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.do_sort = Proc.new do |x, y| + y.title[-1] <=> x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.channel.items.reverse.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + end + + def test_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + textInput = rss.channel.textInput + assert_equal(title, textInput.title) + assert_equal(description, textInput.description) + assert_equal(name, textInput.name) + assert_equal(link, textInput.link) + + rss = RSS::Maker.make("0.9") do |maker| + # setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss) + end + + def test_not_valid_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + # maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + end + end +end diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb new file mode 100644 index 0000000000..8f80f6e2fe --- /dev/null +++ b/test/rss/test_maker_1.0.rb @@ -0,0 +1,363 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMaker10 < TestCase + + def test_rdf + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + end + assert_equal("1.0", rss.rss_version) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.encoding = "EUC-JP" + end + assert_equal("1.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.standalone = "yes" + end + assert_equal("1.0", rss.rss_version) + assert_equal("yes", rss.standalone) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.encoding = "EUC-JP" + maker.standalone = "yes" + end + assert_equal("1.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + assert_equal("yes", rss.standalone) + end + + def test_channel + about = "http://hoge.com" + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + + rss = RSS::Maker.make("1.0") + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + channel = rss.channel + assert_equal(about, channel.about) + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert_equal(true, channel.items.Seq.lis.empty?) + assert_nil(channel.image) + assert_nil(channel.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + + setup_dummy_image(maker) + + setup_dummy_textinput(maker) + end + channel = rss.channel + assert_equal(about, channel.about) + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert(channel.items.Seq.lis.empty?) + assert_equal(rss.image.about, channel.image.resource) + assert_equal(rss.textinput.about, channel.textinput.resource) + end + + def test_not_valid_channel + about = "http://hoge.com" + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + + rss = RSS::Maker.make("1.0") do |maker| + # maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + # maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + # maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + # maker.channel.description = description + end + assert_nil(rss) + end + + + def test_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + end + image = rss.image + assert_equal(url, image.about) + assert_equal(url, rss.channel.image.resource) + assert_equal(title, image.title) + assert_equal(link, image.link) + assert_equal(url, image.url) + + rss = RSS::Maker.make("1.0") do |maker| + # setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + end + assert_nil(rss) + end + + def test_not_valid_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + # maker.image.url = url + maker.image.title = title + end + assert_nil(rss.channel.image) + assert_nil(rss.image) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.url = url + # maker.image.title = title + end + assert_nil(rss.channel.image) + assert_nil(rss.image) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + # maker.channel.link = link + maker.channel.link = nil + + maker.image.url = url + maker.image.title = title + end + assert_nil(rss) + end + + def test_items + title = "TITLE" + link = "http://hoge.com/" + description = "text hoge fuga" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + end + assert(rss.items.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + item.title = title + item.link = link + # item.description = description + end + assert_equal(1, rss.items.size) + item = rss.items.first + assert_equal(link, item.about) + assert_equal(title, item.title) + assert_equal(link, item.link) + assert_nil(item.description) + + + item_size = 5 + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.do_sort = true + end + assert_equal(item_size, rss.items.size) + rss.items.each_with_index do |item, i| + assert_equal("#{link}#{i}", item.about) + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.do_sort = Proc.new do |x, y| + y.title[-1] <=> x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.items.reverse.each_with_index do |item, i| + assert_equal("#{link}#{i}", item.about) + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + end + + def test_not_valid_items + title = "TITLE" + link = "http://hoge.com/" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + # item.title = title + item.link = link + end + assert(rss.items.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + item.title = title + # item.link = link + end + assert(rss.items.empty?) + end + + def test_textinput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + textinput = rss.textinput + assert_equal(link, textinput.about) + assert_equal(link, rss.channel.textinput.resource) + assert_equal(title, textinput.title) + assert_equal(name, textinput.name) + assert_equal(description, textinput.description) + assert_equal(link, textinput.link) + + rss = RSS::Maker.make("1.0") do |maker| + # setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss) + end + + def test_not_valid_textinput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + # maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + end + + end +end diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb new file mode 100644 index 0000000000..b0752f985f --- /dev/null +++ b/test/rss/test_maker_2.0.rb @@ -0,0 +1,622 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMaker20 < TestCase + + def test_rss + rss = RSS::Maker.make("2.0") + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + end + assert_equal("2.0", rss.rss_version) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.encoding = "EUC-JP" + end + assert_equal("2.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.standalone = "yes" + end + assert_equal("2.0", rss.rss_version) + assert_equal("yes", rss.standalone) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.encoding = "EUC-JP" + maker.standalone = "yes" + end + assert_equal("2.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + assert_equal("yes", rss.standalone) + end + + def test_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + copyright = "foo" + managingEditor = "bar" + webMaster = "web master" + rating = "6" + docs = "http://foo.com/doc" + skipDays = "Sunday" + skipHours = "13" + pubDate = Time.now + lastBuildDate = Time.now + category = "Nespapers" + generator = "RSS Maker" + ttl = 60 + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + maker.channel.copyright = copyright + maker.channel.managingEditor = managingEditor + maker.channel.webMaster = webMaster + maker.channel.rating = rating + maker.channel.docs = docs + maker.channel.skipDays = skipDays + maker.channel.skipHours = skipHours + maker.channel.pubDate = pubDate + maker.channel.lastBuildDate = lastBuildDate + maker.channel.category = category + maker.channel.generator = generator + maker.channel.ttl = ttl + end + channel = rss.channel + + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert_equal(language, channel.language) + assert_equal(copyright, channel.copyright) + assert_equal(managingEditor, channel.managingEditor) + assert_equal(webMaster, channel.webMaster) + assert_equal(rating, channel.rating) + assert_equal(docs, channel.docs) + assert_equal(skipDays, channel.skipDays) + assert_equal(skipHours, channel.skipHours) + assert_equal(pubDate, channel.pubDate) + assert_equal(lastBuildDate, channel.lastBuildDate) + assert_equal(category, channel.category) + assert_equal(generator, channel.generator) + assert_equal(ttl, channel.ttl) + + assert(channel.items.empty?) + assert_nil(channel.image) + assert_nil(channel.textInput) + end + + def test_not_valid_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + + rss = RSS::Maker.make("2.0") do |maker| + # maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + # maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + # maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + # maker.channel.language = language + end + assert_not_nil(rss) + end + + + def test_cloud + domain = "rpc.sys.com" + port = "80" + path = "/RPC2" + registerProcedure = "myCloud.rssPleaseNotify" + protocol = "xml-rpc" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + cloud = rss.channel.cloud + assert_equal(domain, cloud.domain) + assert_equal(port, cloud.port) + assert_equal(path, cloud.path) + assert_equal(registerProcedure, cloud.registerProcedure) + assert_equal(protocol, cloud.protocol) + end + + def test_not_valid_cloud + domain = "rpc.sys.com" + port = "80" + path = "/RPC2" + registerProcedure = "myCloud.rssPleaseNotify" + protocol = "xml-rpc" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + # maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + # maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + # maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + # maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + # maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + end + + + def test_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + image = rss.image + assert_equal(title, image.title) + assert_equal(link, image.link) + assert_equal(url, image.url) + assert_equal(width, image.width) + assert_equal(height, image.height) + assert_equal(description, image.description) + + rss = RSS::Maker.make("2.0") do |maker| + # setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + end + + def test_not_valid_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + # maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss.image) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + # maker.channel.link = link + maker.channel.link = nil + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + # maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss.image) + end + + def test_items + title = "TITLE" + link = "http://hoge.com/" + description = "text hoge fuga" + author = "oprah@oxygen.net" + comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290" + pubDate = Time.now + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + end + assert(rss.channel.items.empty?) + + item_size = 5 + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + item.author = "#{author}#{i}" + item.comments = "#{comments}#{i}" + item.date = pubDate + end + maker.items.do_sort = true + end + assert_equal(item_size, rss.items.size) + rss.channel.items.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + assert_equal("#{author}#{i}", item.author) + assert_equal("#{comments}#{i}", item.comments) + assert_equal(pubDate, item.pubDate) + end + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + item.author = "#{author}#{i}" + item.comments = "#{comments}#{i}" + item.date = pubDate + end + maker.items.do_sort = Proc.new do |x, y| + y.title[-1] <=> x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.channel.items.reverse.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + assert_equal("#{author}#{i}", item.author) + assert_equal("#{comments}#{i}", item.comments) + assert_equal(pubDate, item.pubDate) + end + end + + def test_guid + isPermaLink = true + content = "http://inessential.com/2002/09/01.php#a2" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + guid = maker.items.last.guid + guid.isPermaLink = isPermaLink + guid.content = content + end + guid = rss.channel.items.last.guid + assert_equal(isPermaLink, guid.isPermaLink) + assert_equal(content, guid.content) + end + + def test_not_valid_guid + content = "http://inessential.com/2002/09/01.php#a2" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + guid = maker.items.last.guid + # guid.content = content + end + assert_nil(rss.channel.items.last.guid) + end + + def test_enclosure + url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3" + length = "12216320" + type = "audio/mpeg" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + enclosure.length = length + enclosure.type = type + end + enclosure = rss.channel.items.last.enclosure + assert_equal(url, enclosure.url) + assert_equal(length, enclosure.length) + assert_equal(type, enclosure.type) + end + + def test_not_valid_enclosure + url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3" + length = "12216320" + type = "audio/mpeg" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + # enclosure.url = url + enclosure.length = length + enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + # enclosure.length = length + enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + enclosure.length = length + # enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + end + + + def test_source + url = "http://static.userland.com/tomalak/links2.xml" + content = "Tomalak's Realm" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + source.url = url + source.content = content + end + source = rss.channel.items.last.source + assert_equal(url, source.url) + assert_equal(content, source.content) + end + + def test_not_valid_source + url = "http://static.userland.com/tomalak/links2.xml" + content = "Tomalak's Realm" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + # source.url = url + source.content = content + end + assert_nil(rss.channel.items.last.source) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + source.url = url + # source.content = content + end + assert_nil(rss.channel.items.last.source) + end + + def test_category + domain = "http://www.fool.com/cusips" + content = "MSFT" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + category = maker.items.last.category + category.domain = domain + category.content = content + end + category = rss.channel.items.last.category + assert_equal(domain, category.domain) + assert_equal(content, category.content) + end + + def test_not_valid_category + content = "Grateful Dead" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + category = maker.items.last.category + # category.content = content + end + assert_nil(rss.channel.items.last.category) + end + + def test_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + textInput = rss.channel.textInput + assert_equal(title, textInput.title) + assert_equal(description, textInput.description) + assert_equal(name, textInput.name) + assert_equal(link, textInput.link) + + rss = RSS::Maker.make("2.0") do |maker| + # setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss) + end + + def test_not_valid_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + # maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + end + end +end diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb new file mode 100644 index 0000000000..bbdfdc682b --- /dev/null +++ b/test/rss/test_maker_xml-stylesheet.rb @@ -0,0 +1,75 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerXMLStyleSheet < TestCase + + def test_xml_stylesheet + href = 'a.xsl' + type = 'text/xsl' + title = 'sample' + media = 'printer' + charset = 'UTF-8' + alternate = 'yes' + + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + xss.href = href + xss.type = type + xss.title = title + xss.media = media + xss.charset = charset + xss.alternate = alternate + + setup_dummy_channel(maker) + end + + xss = rss.xml_stylesheets.first + assert_equal(href, xss.href) + assert_equal(type, xss.type) + assert_equal(title, xss.title) + assert_equal(media, xss.media) + assert_equal(charset, xss.charset) + assert_equal(alternate, xss.alternate) + + + href = 'http://example.com/index.xsl' + type = 'text/xsl' + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + xss.href = href + + setup_dummy_channel(maker) + end + + xss = rss.xml_stylesheets.first + assert_equal(href, xss.href) + assert_equal(type, xss.type) + end + + def test_not_valid_xml_stylesheet + href = 'xss.XXX' + type = "text/xsl" + + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + # xss.href = href + xss.type = type + + setup_dummy_channel(maker) + end + assert(rss.xml_stylesheets.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + xss.href = href + # xss.type = type + + setup_dummy_channel(maker) + end + assert(rss.xml_stylesheets.empty?) + end + + end +end |