# -*- encoding: UTF-8 -*- require 'test_helper' require 'webmock/minitest' module Wovnrb class MetaReplacerTest < WovnMiniTest def test_replace_description store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 store = Store.instance replacer = MetaReplacer.new(store, { '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 def test_replace_wovn_ignore_og store = Store.instance headers = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'https://test.com'), Wovnrb.get_settings) replacer = MetaReplacer.new(store, { 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}, }, 'path', headers) dom = Wovnrb.get_dom('') replacer.replace(dom, Lang.new('ja')) content = dom.xpath('//meta')[0].get_attribute('content') assert_equal('https://test.com/ja/', content) end end end