require 'test_helper'
require 'webmock/minitest'
module Wovnrb
class MetaReplacerTest < WovnMiniTest
def test_replace_description
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('こんにちは', content)
end
def test_replace_og_description
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('こんにちは', content)
end
def test_replace_og_title
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('こんにちは', content)
end
def test_replace_twitter_title
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('こんにちは', content)
end
def test_replace_twitter_description
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('こんにちは', content)
end
def test_replace_multi
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
'Bye' => {'ja' => [{'data' => 'さようなら'}]}
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
content2 = dom.xpath('//meta')[1].get_attribute('content')
assert_equal('こんにちは', content)
assert_equal('さようなら', content2)
end
def test_replace_wovn_ignore
replacer = MetaReplacer.new({
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
})
dom = Wovnrb.get_dom('')
replacer.replace(dom, Lang.new('ja'))
content = dom.xpath('//meta')[0].get_attribute('content')
assert_equal('Hello', content)
end
end
end