Sha256: cc12e798e3780d356b4680b48d7cd911895b1d94ea9bcd5562709cac2ae20c89

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require "nokogiri"
require "test/unit"
require "#{File.expand_path(File.dirname(__FILE__))}/collections.rb"
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/sitemapper.rb"

class SiteMapperTest < Test::Unit::TestCase
   def setup
      @arraytest = [{url: "One"  , lastmod: Time.now, freq: "monthly", priority: 1}, 
                    {url: "Two"  , lastmod: Time.now, freq: "monthly", priority: 1}, 
                    {url: "Three", lastmod: Time.now, freq: "monthly", priority: 1}]

      @sitemapper = SiteMapper::SiteMapper.new
      @sitemapper.url = "http://localhost.com/sitemap.xml"
      @sitemapper.loc = :url
      @sitemapper.changefreq = :freq
      @sitemapper.priority = :priority
      @sitemapper.sitemap = "/tmp/sitemap.xml"
   end   

   def test_write_sitemap
      File.unlink(@sitemapper.sitemap) if File.exists?(@sitemapper.sitemap)
      @sitemapper.write_sitemap(@arraytest.entries) 
      assert File.exists?(@sitemapper.sitemap), "sitemap file not found"
   end

   def test_url_size
      test_write_sitemap
      doc = Nokogiri::XML(File.open(@sitemapper.sitemap))
      assert_equal @arraytest.entries.size, doc.search("url").size
   end

   def test_write_sitemap_with_extras
      File.unlink(@sitemapper.sitemap) if File.exists?(@sitemapper.sitemap)
      extras = [{url: "Four", lastmod: Time.now, freq: "yearly", priority: 0.5}, 
                {url: "Five", lastmod: Time.now, freq: "yearly", priority: 0.5}]
      @sitemapper.write_sitemap(@arraytest.entries,extras.entries) 
      doc = Nokogiri::XML(File.open(@sitemapper.sitemap))
      assert_equal @arraytest.entries.size+extras.size, doc.search("url").size
   end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
taq-sitemapper-0.0.3 test/sitemapper_test.rb