Class: TestHtmlToPlainText

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
HtmlToPlainText
Defined in:
lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb

Instance Method Summary collapse

Methods included from HtmlToPlainText

#convert_to_text

Instance Method Details

#assert_plaintext(out, raw, msg = nil) ⇒ Object



70
71
72
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 70

def assert_plaintext(out, raw, msg = nil)
  assert_equal out, convert_to_text(raw), msg
end

#test_accentsObject



6
7
8
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 6

def test_accents
  assert_plaintext 'cédille garçon à ñ', 'cédille garçon à ñ'
end

#test_headingsObject



39
40
41
42
43
44
45
46
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 39

def test_headings
  assert_plaintext "****\nTest\n****", "<h1>Test</h1>"
  assert_plaintext "****\nTest\n****", "\t<h1>\nTest</h1> "
  assert_plaintext "***********\nTest line 1\nTest 2\n***********", "\t<h1>\nTest line 1<br>Test 2</h1> "
  assert_plaintext "****\nTest\n****\n\n****\nTest\n****", "<h1>Test</h1> <h1>Test</h1>"
  assert_plaintext "----\nTest\n----", "<h2>Test</h2>"
  assert_plaintext "Test\n----", "<h3> <span class='a'>Test </span></h3>"
end

#test_line_breaksObject



17
18
19
20
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 17

def test_line_breaks
  assert_plaintext "Test text\nTest text", "Test text\r\nTest text"
  assert_plaintext "Test text\nTest text", "Test text\rTest text"
end


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 48

def test_links
  # basic
  assert_plaintext 'Link ( http://example.com/ )', '<a href="http://example.com/">Link</a>'
  
  # nested html
  assert_plaintext 'Link ( http://example.com/ )', '<a href="http://example.com/"><span class="a">Link</span></a>'
  
  # complex link
  assert_plaintext 'Link ( http://example.com:80/~user?aaa=bb&c=d,e,f#foo )', '<a href="http://example.com:80/~user?aaa=bb&amp;c=d,e,f#foo">Link</a>'
  
  # attributes
  assert_plaintext 'Link ( http://example.com/ )', '<a title=\'title\' href="http://example.com/">Link</a>'
  
  # spacing
  assert_plaintext 'Link ( http://example.com/ )', '<a href="   http://example.com/ "> Link </a>'
  
  # merge links
  assert_plaintext 'Link ( %%LINK%% )', '<a href="%%LINK%%">Link</a>'
  assert_plaintext 'Link ( [LINK] )', '<a href="[LINK]">Link</a>'
  assert_plaintext 'Link ( {LINK} )', '<a href="{LINK}">Link</a>'
end

#test_listsObject



22
23
24
25
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 22

def test_lists
  assert_plaintext "* item 1\n* item 2", "<li class='123'>item 1</li> <li>item 2</li>\n"
  assert_plaintext "* item 1\n* item 2\n* item 3", "<li>item 1</li> \t\n <li>item 2</li> <li> item 3</li>\n"
end

#test_paragraphs_and_breaksObject



31
32
33
34
35
36
37
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 31

def test_paragraphs_and_breaks
  assert_plaintext "Test text\n\nTest text", "<p>Test text</p><p>Test text</p>"
  assert_plaintext "Test text\n\nTest text", "\n<p>Test text</p>\n\n\n\t<p>Test text</p>\n"
  assert_plaintext "Test text\nTest text", "\n<p>Test text<br/>Test text</p>\n"
  assert_plaintext "Test text\nTest text", "\n<p>Test text<br> \tTest text<br></p>\n"
  assert_plaintext "Test text\n\nTest text", "Test text<br><BR />Test text"
end

#test_stripping_htmlObject



27
28
29
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 27

def test_stripping_html
  assert_plaintext 'test text', "<p class=\"123'45 , att\" att=tester>test <span class='te\"st'>text</span>\n"
end

#test_stripping_whitespaceObject



10
11
12
13
14
15
# File 'lib/html2email/vendor/premailer/tests/test_html_to_plain_text.rb', line 10

def test_stripping_whitespace
  assert_plaintext "text\ntext", "  \ttext\ntext\n"
  assert_plaintext "a\na", "  \na \n a \t"
  assert_plaintext "a\n\na", "  \na \n\t \n \n a \t"
  assert_plaintext "test text", "test text&nbsp;"
end