require 'test_helper' require 'webmock/minitest' module Wovnrb class ReplacerBaseTest < WovnMiniTest def test_replace replacer = LinkReplacer.new('query', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('/index.html?wovn=en', link) end def test_replace_multiple replacer = LinkReplacer.new('query', get_header) dom = Wovnrb.get_dom('link text
aaa
link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') link2 = dom.xpath('//a')[1].get_attribute('href') assert_equal('/index.html?wovn=en', link) assert_equal('/index2.html?wovn=en', link2) end def test_replace_ignore replacer = LinkReplacer.new('query', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('/index.html', link) end def test_replace_javascript_link_query replacer = LinkReplacer.new('query', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('javascript:void(0);', link) end def test_replace_javascript_link_path replacer = LinkReplacer.new('path', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('javascript:void(0);', link) end def test_replace_javascript_link_subdomain replacer = LinkReplacer.new('subdomain', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('javascript:void(0);', link) end def test_replace_mustache replacer = LinkReplacer.new('query', get_header) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal('{{hello}}', link) dom = Wovnrb.get_dom('link text') replacer.replace(dom, Lang.new('en')) link = dom.xpath('//a')[0].get_attribute('href') assert_equal(' {{hello}} ', link) end def get_header h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://favy.tips'), Wovnrb.get_settings('url_pattern' => 'query', 'url_pattern_reg' => '^(?[^.]+).')) end end end