wovnrb 0.2 → 0.2.01

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66caabf04f7163ba12bcac618e987d9562740c5a
4
- data.tar.gz: b03a3d9a2eeda144d7a4af12f8c575bb680100c5
3
+ metadata.gz: 1531f2d2d0c565e28d1473918d96f1c4566e3a8a
4
+ data.tar.gz: 1de5c991d544fc7578de043f53da32e069d7ae36
5
5
  SHA512:
6
- metadata.gz: 2cc613b2af55466b840ecac90237ec27fcffbdf8e9df09eb21eba1480ceedc274b1582909d6e039509c0f1790c6f94da92ca4a3e31a685e05fdb57188e9fc6f9
7
- data.tar.gz: b265d558f6cc8a73e21bf4b613ba503c32dd92005ae6e14390a2b9c5ee8344c918cad7ac7f50b987e7aca2e23b967e653492943b23120ea10fb545103f2dc922
6
+ metadata.gz: 08da2a6e09ca5109e475103ee38d213cfb4a45f6d471c12fa55b4270a7406dadb769b7449c5fb06dee1ca87027f73d6c8ed15a2fe98195516c47c235831c8992
7
+ data.tar.gz: f70c5edad9d5ae50b8702c4f3c7d55d4160369d0d8faa1cc0bdbdd373161b11d0bdc47b5c9a88430b3cc1f12a14476fa755200e3dd04dfb3139a4edfd417a8bd
data/lib/wovnrb.rb CHANGED
@@ -9,27 +9,26 @@ require 'wovnrb/railtie' if defined?(Rails)
9
9
 
10
10
  module Wovnrb
11
11
 
12
- STORE = Store.new
13
-
14
12
  class Interceptor
15
13
  def initialize(app, opts={})
16
14
  @app = app
15
+ @store = Store.new
17
16
  opts = opts.each_with_object({}){|(k,v),memo| memo[k.to_s]=v}
18
- STORE.settings(opts)
17
+ @store.settings(opts)
19
18
  end
20
19
 
21
20
  def call(env)
22
- unless STORE.valid_settings?
21
+ unless @store.valid_settings?
23
22
  return @app.call(env)
24
23
  end
25
24
  @env = env
26
- headers = Headers.new(env, STORE.settings)
27
- if STORE.settings['test_mode'] && STORE.settings['test_url'] != headers.url
25
+ headers = Headers.new(env, @store.settings)
26
+ if @store.settings['test_mode'] && @store.settings['test_url'] != headers.url
28
27
  return @app.call(env)
29
28
  end
30
29
  #redirect if the path is set to the default language (for SEO purposes)
31
- if (headers.path_lang == STORE.settings['default_lang'])
32
- redirect_headers = headers.redirect(STORE.settings['default_lang'])
30
+ if (headers.path_lang == @store.settings['default_lang'])
31
+ redirect_headers = headers.redirect(@store.settings['default_lang'])
33
32
  return [307, redirect_headers, ['']]
34
33
  end
35
34
  lang = headers.lang_code
@@ -38,7 +37,7 @@ module Wovnrb
38
37
  status, res_headers, body = @app.call(headers.request_out)
39
38
 
40
39
  if res_headers["Content-Type"] =~ /html/ # && !body[0].nil?
41
- values = STORE.get_values(headers.redis_url)
40
+ values = @store.get_values(headers.redis_url)
42
41
  url = {
43
42
  :protocol => headers.protocol,
44
43
  :host => headers.host,
@@ -128,7 +127,8 @@ module Wovnrb
128
127
  check_wovn_ignore(node.parent)
129
128
  end
130
129
 
131
- def switch_lang(body, values, url, lang=STORE.settings['default_lang'], headers)
130
+ def switch_lang(body, values, url, lang=@store.settings['default_lang'], headers)
131
+
132
132
  lang = Lang.get_code(lang)
133
133
  text_index = values['text_vals'] || {}
134
134
  src_index = values['img_vals'] || {}
@@ -149,13 +149,35 @@ module Wovnrb
149
149
  end
150
150
 
151
151
  # add lang code to anchors href if not default lang
152
- if lang != STORE.settings['default_lang']
152
+ if lang != @store.settings['default_lang']
153
+ pattern = @store.settings['url_pattern']
154
+
153
155
  d.xpath('//a').each do |a|
154
156
  next if check_wovn_ignore(a)
155
157
  href = a.get_attribute('href')
156
- new_href = add_lang_code(href, STORE.settings['url_pattern'], lang, headers)
158
+ new_href = add_lang_code(href, pattern, lang, headers)
157
159
  a.set_attribute('href', new_href)
158
160
  end
161
+
162
+ d.xpath('//form').each do |form|
163
+ next if check_wovn_ignore(form)
164
+ method = form.get_attribute('method')
165
+ if pattern == 'query' && (method.nil? || method.upcase == 'GET')
166
+ insert_node = Nokogiri::XML::Node.new('input', d)
167
+ insert_node['type'] = 'hidden'
168
+ insert_node['name'] = 'wovn'
169
+ insert_node['value'] = lang
170
+ if form.children.size > 0
171
+ form.children.first.add_previous_sibling(insert_node)
172
+ else
173
+ form.add_child(insert_node)
174
+ end
175
+ else
176
+ action = form.get_attribute('action')
177
+ new_action = add_lang_code(action, pattern, lang, headers)
178
+ form['action'] = new_action
179
+ end
180
+ end
159
181
  end
160
182
 
161
183
  # swap text
@@ -227,7 +249,7 @@ module Wovnrb
227
249
  insert_node['async'] = true
228
250
  #insert_node['src'] = '//j.dev-wovn.io:3000/0'
229
251
  version = defined?(VERSION) ? VERSION : ''
230
- insert_node['data-wovnio'] = "key=#{STORE.settings['user_token']}&backend=true&currentLang=#{lang}&defaultLang=#{STORE.settings['default_lang']}&urlPattern=#{STORE.settings['url_pattern']}&version=#{version}"
252
+ insert_node['data-wovnio'] = "key=#{@store.settings['user_token']}&backend=true&currentLang=#{lang}&defaultLang=#{@store.settings['default_lang']}&urlPattern=#{@store.settings['url_pattern']}&version=#{version}"
231
253
  # do this so that there will be a closing tag (better compatibility with browsers)
232
254
  insert_node.content = ' '
233
255
  if parent_node.children.size > 0
@@ -260,7 +282,7 @@ module Wovnrb
260
282
  #body
261
283
  end
262
284
 
263
- # this clearly needs to be refactored. I'm thinking maybe a Value service? (STORE.values.get_langs)
285
+ # this clearly needs to be refactored. I'm thinking maybe a Value service? (@store.values.get_langs)
264
286
  def get_langs(values)
265
287
  langs = Set.new
266
288
  (values['text_vals'] || {}).merge(values['img_vals'] || {}).each do |key, index|
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2"
2
+ VERSION = "0.2.01"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'wovnrb'
2
3
  require 'wovnrb/headers'
3
4
  require 'minitest/autorun'
@@ -459,6 +460,440 @@ class WovnrbTest < Minitest::Test
459
460
  assert_equal(generate_body('value_double_quote_translated'), swapped_body)
460
461
  end
461
462
 
463
+ def test_switch_lang_add_lang_code_path_from_action_no_method
464
+ i = Wovnrb::Interceptor.new(get_app, get_settings)
465
+ h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
466
+ body = <<"BODY"
467
+ <html>
468
+ <head><title>Hey</title></head>
469
+ <body>
470
+ <h1>Mr. Belvedere Fan Club</h1>
471
+ <div><p>Hello</p></div>
472
+ <a href="https://google.com/hello.html">TOP</a>
473
+ <form action="/form.php">
474
+ <input type="text" name="name" value="wovn.io" />
475
+ </form>
476
+ </body>
477
+ </html>
478
+ BODY
479
+ expected = <<"EXPECTED"
480
+ <html lang=\"ja\">
481
+ <head>
482
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
483
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=0.2\"> </script><title>Hey</title>
484
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
485
+ </head>
486
+ <body>
487
+ <h1>ベルベデアさんファンクラブ</h1>
488
+ <div><p>こんにちは</p></div>
489
+ <a href=\"https://google.com/ja/hello.html\">TOP</a>
490
+ <form action=\"/ja/form.php\">
491
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
492
+ </form>
493
+
494
+
495
+
496
+ </body>
497
+ </html>
498
+ EXPECTED
499
+ body = [body]
500
+ expected = [expected]
501
+ values = generate_values
502
+ url = h.url
503
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
504
+ assert_equal(expected, swapped_body)
505
+ end
506
+
507
+ def test_switch_lang_add_lang_code_path_from_action_get_method
508
+ i = Wovnrb::Interceptor.new(get_app, get_settings)
509
+ h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
510
+ body = <<"BODY"
511
+ <html>
512
+ <head><title>Hey</title></head>
513
+ <body>
514
+ <h1>Mr. Belvedere Fan Club</h1>
515
+ <div><p>Hello</p></div>
516
+ <a href="https://google.com/hello.html">TOP</a>
517
+ <form action="/form.php" method="GET">
518
+ <input type="text" name="name" value="wovn.io" />
519
+ </form>
520
+ </body>
521
+ </html>
522
+ BODY
523
+ expected = <<"EXPECTED"
524
+ <html lang=\"ja\">
525
+ <head>
526
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
527
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=0.2\"> </script><title>Hey</title>
528
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
529
+ </head>
530
+ <body>
531
+ <h1>ベルベデアさんファンクラブ</h1>
532
+ <div><p>こんにちは</p></div>
533
+ <a href=\"https://google.com/ja/hello.html\">TOP</a>
534
+ <form action=\"/ja/form.php\" method="GET">
535
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
536
+ </form>
537
+
538
+
539
+
540
+ </body>
541
+ </html>
542
+ EXPECTED
543
+ body = [body]
544
+ expected = [expected]
545
+ values = generate_values
546
+ url = h.url
547
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
548
+ assert_equal(expected, swapped_body)
549
+ end
550
+
551
+ def test_switch_lang_add_lang_code_path_from_action_post_method
552
+ i = Wovnrb::Interceptor.new(get_app, get_settings)
553
+ h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
554
+ body = <<"BODY"
555
+ <html>
556
+ <head><title>Hey</title></head>
557
+ <body>
558
+ <h1>Mr. Belvedere Fan Club</h1>
559
+ <div><p>Hello</p></div>
560
+ <a href="https://google.com/hello.html">TOP</a>
561
+ <form action="/form.php" method="POST">
562
+ <input type="text" name="name" value="wovn.io" />
563
+ </form>
564
+ </body>
565
+ </html>
566
+ BODY
567
+ expected = <<"EXPECTED"
568
+ <html lang=\"ja\">
569
+ <head>
570
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
571
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=0.2\"> </script><title>Hey</title>
572
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
573
+ </head>
574
+ <body>
575
+ <h1>ベルベデアさんファンクラブ</h1>
576
+ <div><p>こんにちは</p></div>
577
+ <a href=\"https://google.com/ja/hello.html\">TOP</a>
578
+ <form action=\"/ja/form.php\" method="POST">
579
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
580
+ </form>
581
+
582
+
583
+
584
+ </body>
585
+ </html>
586
+ EXPECTED
587
+ body = [body]
588
+ expected = [expected]
589
+ values = generate_values
590
+ url = h.url
591
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
592
+ assert_equal(expected, swapped_body)
593
+ end
594
+
595
+ def test_switch_lang_add_lang_code_subdomain_from_action_no_method
596
+ i = Wovnrb::Interceptor.new(
597
+ get_app,
598
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
599
+ )
600
+ h = Wovnrb::Headers.new(
601
+ get_env('url' => 'https://google.com'),
602
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
603
+ )
604
+ body = <<"BODY"
605
+ <html>
606
+ <head><title>Hey</title></head>
607
+ <body>
608
+ <h1>Mr. Belvedere Fan Club</h1>
609
+ <div><p>Hello</p></div>
610
+ <a href="https://google.com/hello.html">TOP</a>
611
+ <form action="/form.php">
612
+ <input type="text" name="name" value="wovn.io" />
613
+ </form>
614
+ </body>
615
+ </html>
616
+ BODY
617
+ expected = <<"EXPECTED"
618
+ <html lang=\"ja\">
619
+ <head>
620
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
621
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=subdomain&amp;version=0.2\"> </script><title>Hey</title>
622
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
623
+ </head>
624
+ <body>
625
+ <h1>ベルベデアさんファンクラブ</h1>
626
+ <div><p>こんにちは</p></div>
627
+ <a href=\"https://ja.google.com/hello.html\">TOP</a>
628
+ <form action=\"https://ja.google.com/form.php\">
629
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
630
+ </form>
631
+
632
+
633
+
634
+ </body>
635
+ </html>
636
+ EXPECTED
637
+ body = [body]
638
+ expected = [expected]
639
+ values = generate_values
640
+ url = h.url
641
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
642
+ assert_equal(expected, swapped_body)
643
+ end
644
+
645
+ def test_switch_lang_add_lang_code_subdomain_from_action_get_method
646
+ i = Wovnrb::Interceptor.new(
647
+ get_app,
648
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
649
+ )
650
+ h = Wovnrb::Headers.new(
651
+ get_env('url' => 'https://google.com'),
652
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
653
+ )
654
+ body = <<"BODY"
655
+ <html>
656
+ <head><title>Hey</title></head>
657
+ <body>
658
+ <h1>Mr. Belvedere Fan Club</h1>
659
+ <div><p>Hello</p></div>
660
+ <a href="https://google.com/hello.html">TOP</a>
661
+ <form action="/form.php" method="GET">
662
+ <input type="text" name="name" value="wovn.io" />
663
+ </form>
664
+ </body>
665
+ </html>
666
+ BODY
667
+ expected = <<"EXPECTED"
668
+ <html lang=\"ja\">
669
+ <head>
670
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
671
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=subdomain&amp;version=0.2\"> </script><title>Hey</title>
672
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
673
+ </head>
674
+ <body>
675
+ <h1>ベルベデアさんファンクラブ</h1>
676
+ <div><p>こんにちは</p></div>
677
+ <a href=\"https://ja.google.com/hello.html\">TOP</a>
678
+ <form action=\"https://ja.google.com/form.php\" method="GET">
679
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
680
+ </form>
681
+
682
+
683
+
684
+ </body>
685
+ </html>
686
+ EXPECTED
687
+ body = [body]
688
+ expected = [expected]
689
+ values = generate_values
690
+ url = h.url
691
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
692
+ assert_equal(expected, swapped_body)
693
+ end
694
+
695
+ def test_switch_lang_add_lang_code_subdomain_from_action_post_method
696
+ i = Wovnrb::Interceptor.new(
697
+ get_app,
698
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
699
+ )
700
+ h = Wovnrb::Headers.new(
701
+ get_env('url' => 'https://google.com'),
702
+ get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
703
+ )
704
+ body = <<"BODY"
705
+ <html>
706
+ <head><title>Hey</title></head>
707
+ <body>
708
+ <h1>Mr. Belvedere Fan Club</h1>
709
+ <div><p>Hello</p></div>
710
+ <a href="https://google.com/hello.html">TOP</a>
711
+ <form action="/form.php" method="POST">
712
+ <input type="text" name="name" value="wovn.io" />
713
+ </form>
714
+ </body>
715
+ </html>
716
+ BODY
717
+ expected = <<"EXPECTED"
718
+ <html lang=\"ja\">
719
+ <head>
720
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
721
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=subdomain&amp;version=0.2\"> </script><title>Hey</title>
722
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
723
+ </head>
724
+ <body>
725
+ <h1>ベルベデアさんファンクラブ</h1>
726
+ <div><p>こんにちは</p></div>
727
+ <a href=\"https://ja.google.com/hello.html\">TOP</a>
728
+ <form action=\"https://ja.google.com/form.php\" method="POST">
729
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
730
+ </form>
731
+
732
+
733
+
734
+ </body>
735
+ </html>
736
+ EXPECTED
737
+ body = [body]
738
+ expected = [expected]
739
+ values = generate_values
740
+ url = h.url
741
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
742
+ assert_equal(expected, swapped_body)
743
+ end
744
+
745
+ def test_switch_lang_add_lang_code_query_form_action_no_method
746
+ i = Wovnrb::Interceptor.new(
747
+ get_app,
748
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
749
+ )
750
+ h = Wovnrb::Headers.new(
751
+ get_env('url' => 'https://google.com'),
752
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
753
+ )
754
+ body = <<"BODY"
755
+ <html>
756
+ <head><title>Hey</title></head>
757
+ <body>
758
+ <h1>Mr. Belvedere Fan Club</h1>
759
+ <div><p>Hello</p></div>
760
+ <a href="https://google.com/hello.html">TOP</a>
761
+ <form action="/form.php">
762
+ <input type="text" name="name" value="wovn.io" />
763
+ </form>
764
+ </body>
765
+ </html>
766
+ BODY
767
+ expected = <<"EXPECTED"
768
+ <html lang=\"ja\">
769
+ <head>
770
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
771
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=query&amp;version=0.2\"> </script><title>Hey</title>
772
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
773
+ </head>
774
+ <body>
775
+ <h1>ベルベデアさんファンクラブ</h1>
776
+ <div><p>こんにちは</p></div>
777
+ <a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
778
+ <form action=\"/form.php\">
779
+ <input type=\"hidden\" name=\"wovn\" value=\"ja\">
780
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
781
+ </form>
782
+
783
+
784
+
785
+ </body>
786
+ </html>
787
+ EXPECTED
788
+ body = [body]
789
+ expected = [expected]
790
+ values = generate_values
791
+ url = h.url
792
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
793
+ assert_equal(expected, swapped_body)
794
+ end
795
+
796
+ def test_switch_lang_add_lang_code_query_form_action_get_method
797
+ i = Wovnrb::Interceptor.new(
798
+ get_app,
799
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
800
+ )
801
+ h = Wovnrb::Headers.new(
802
+ get_env('url' => 'https://google.com'),
803
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
804
+ )
805
+ body = <<"BODY"
806
+ <html>
807
+ <head><title>Hey</title></head>
808
+ <body>
809
+ <h1>Mr. Belvedere Fan Club</h1>
810
+ <div><p>Hello</p></div>
811
+ <a href="https://google.com/hello.html">TOP</a>
812
+ <form action="/form.php" method="GET">
813
+ <input type="text" name="name" value="wovn.io" />
814
+ </form>
815
+ </body>
816
+ </html>
817
+ BODY
818
+ expected = <<"EXPECTED"
819
+ <html lang=\"ja\">
820
+ <head>
821
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
822
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=query&amp;version=0.2\"> </script><title>Hey</title>
823
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
824
+ </head>
825
+ <body>
826
+ <h1>ベルベデアさんファンクラブ</h1>
827
+ <div><p>こんにちは</p></div>
828
+ <a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
829
+ <form action=\"/form.php\" method="GET">
830
+ <input type=\"hidden\" name=\"wovn\" value=\"ja\">
831
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
832
+ </form>
833
+
834
+
835
+
836
+ </body>
837
+ </html>
838
+ EXPECTED
839
+ body = [body]
840
+ expected = [expected]
841
+ values = generate_values
842
+ url = h.url
843
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
844
+ assert_equal(expected, swapped_body)
845
+ end
846
+
847
+ def test_switch_lang_add_lang_code_query_form_action_post_method
848
+ i = Wovnrb::Interceptor.new(
849
+ get_app,
850
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
851
+ )
852
+ h = Wovnrb::Headers.new(
853
+ get_env('url' => 'https://google.com'),
854
+ get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
855
+ )
856
+ body = <<"BODY"
857
+ <html>
858
+ <head><title>Hey</title></head>
859
+ <body>
860
+ <h1>Mr. Belvedere Fan Club</h1>
861
+ <div><p>Hello</p></div>
862
+ <a href="https://google.com/hello.html">TOP</a>
863
+ <form action="/form.php" method="POST">
864
+ <input type="text" name="name" value="wovn.io" />
865
+ </form>
866
+ </body>
867
+ </html>
868
+ BODY
869
+ expected = <<"EXPECTED"
870
+ <html lang=\"ja\">
871
+ <head>
872
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
873
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=query&amp;version=0.2\"> </script><title>Hey</title>
874
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
875
+ </head>
876
+ <body>
877
+ <h1>ベルベデアさんファンクラブ</h1>
878
+ <div><p>こんにちは</p></div>
879
+ <a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
880
+ <form action=\"/form.php?wovn=ja\" method="POST">
881
+ <input type=\"text\" name=\"name\" value=\"wovn.io\">
882
+ </form>
883
+
884
+
885
+
886
+ </body>
887
+ </html>
888
+ EXPECTED
889
+ body = [body]
890
+ expected = [expected]
891
+ values = generate_values
892
+ url = h.url
893
+ swapped_body = i.switch_lang(body, values, url, 'ja', h)
894
+ assert_equal(expected, swapped_body)
895
+ end
896
+
462
897
  def get_settings(options={})
463
898
  settings = {}
464
899
  settings['user_token'] = 'OHYx9'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-16 00:00:00.000000000 Z
12
+ date: 2016-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo