require 'helper' class TestMechanizePageMetaRefresh < Test::Unit::TestCase def setup @MR = Mechanize::Page::MetaRefresh @agent = Mechanize.new @uri = URI 'http://example/here/' end def util_page delay, uri body = <<-BODY
BODY Mechanize::Page.new(@uri, { 'content-type' => 'text/html' }, body, 200, @agent) end def util_meta_refresh page node = page.search('meta').first @MR.from_node node, page, @uri end def test_class_parse delay, uri = @MR.parse "0; url=http://localhost:8080/path", @uri assert_equal "0", delay assert_equal "http://localhost:8080/path", uri.to_s delay, uri = @MR.parse "100.001; url=http://localhost:8080/path", @uri assert_equal "100.001", delay assert_equal "http://localhost:8080/path", uri.to_s delay, uri = @MR.parse "0; url='http://localhost:8080/path'", @uri assert_equal "0", delay assert_equal "http://localhost:8080/path", uri.to_s delay, uri = @MR.parse "0; url=\"http://localhost:8080/path\"", @uri assert_equal "0", delay assert_equal "http://localhost:8080/path", uri.to_s delay, uri = @MR.parse "0; url=", @uri assert_equal "0", delay assert_equal "http://example/here/", uri.to_s delay, uri = @MR.parse "0", @uri assert_equal "0", delay assert_equal "http://example/here/", uri.to_s delay, uri = @MR.parse " 0; ", @uri assert_equal "0", delay assert_equal "http://example/here/", uri.to_s delay, uri = @MR.parse "0; UrL=http://localhost:8080/path", @uri assert_equal "0", delay assert_equal "http://localhost:8080/path", uri.to_s end def test_class_from_node page = util_page 5, 'http://b.example' link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://b.example', link.href page = util_page 5, 'http://example/a' link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://example/a', link.href page = util_page 5, 'test' link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://example/here/test', link.href page = util_page 5, '/test' link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://example/test', link.href page = util_page 5, nil link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://example/here/', link.href page = util_page 5, @uri link = util_meta_refresh page assert_equal 5, link.delay assert_equal 'http://example/here/', link.href end def test_class_from_node_no_content body = <<-BODY BODY page = Mechanize::Page.new(@uri, { 'content-type' => 'text/html' }, body, 200, @agent) assert_nil util_meta_refresh page end def test_class_from_node_not_refresh body = <<-BODY BODY page = Mechanize::Page.new(@uri, { 'content-type' => 'text/html' }, body, 200, @agent) assert_nil util_meta_refresh page end end