File: test_warnings.rb

package info (click to toggle)
ruby-premailer 1.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 440 kB
  • sloc: ruby: 2,344; makefile: 3
file content (95 lines) | stat: -rw-r--r-- 2,701 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__)) + '/helper'

class TestWarnings < Premailer::TestCase
  def _test_element_warnings
    html = <<END_HTML
    <!DOCTYPE html>
    <html>
    <head><link rel="alternate" href="http://example.com/"></head>
    <body>
    <form method="post"> Test </form>
    </body>
		</html>
END_HTML

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter)
      assert_equal 2, warnings.length
      assert warnings.any? { |w| w[:message] == 'form HTML element'}
      assert warnings.any? { |w| w[:message] == 'link HTML element'}
    end
  end

  def _test_css_warnings
    html = <<END_HTML
    <!DOCTYPE html>
    <html><body>
    <div style="margin: 5px; height: 100px;">Test</div>
    </body></html>
END_HTML

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter)
      assert_equal 2, warnings.length
      assert warnings.any? { |w| w[:message] == 'height CSS property'}
      assert warnings.any? { |w| w[:message] == 'margin CSS property'}
    end
  end

  def _test_css_aliased_warnings
    html = <<END_HTML
    <!DOCTYPE html>
    <html><body>
    <div style="margin-top: 5px;">Test</div>
    </body></html>
END_HTML

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter)
      assert_equal 1, warnings.length
      assert warnings.any? { |w| w[:message] == 'margin-top CSS property'}
    end
  end

  def _test_attribute_warnings
    html = <<END_HTML
    <!DOCTYPE html>
    <html><body>
    <img src="#" ismap>
    </body></html>
END_HTML

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter)
      assert_equal 1, warnings.length
      assert warnings.any? { |w| w[:message] == 'ismap HTML attribute'}
    end
  end

  def _test_warn_level
    html = <<END_HTML
    <!DOCTYPE html>
    <html><body>
    <div style="color: red; font-family: sans-serif;">Test</div>
    </body></html>
END_HTML

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter, Premailer::Warnings::SAFE)
      assert_equal 2, warnings.length
    end

    [:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
      warnings = get_warnings(html, adapter, Premailer::Warnings::POOR)
      assert_equal 1, warnings.length
    end
  end

protected
  def get_warnings(html, adapter = :nokogiri, warn_level = Premailer::Warnings::SAFE)
    pm = Premailer.new(html, {:adapter => adapter, :with_html_string => true, :warn_level => warn_level})
    pm.to_inline_css
    pm.check_client_support
  end
end