From 6de94974a581bf10751f2a36ce34e37ab5c30947 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 29 Dec 2014 16:39:59 +0100 Subject: [PATCH] Added initial email build tests. --- app/models/channel/email_build.rb | 29 +++++++++++++++++++++++++++++ test/unit/email_build_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/unit/email_build_test.rb diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 26e2f7f1b..380589504 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -46,6 +46,10 @@ module Channel::EmailBuild if attr[:content_type] && attr[:content_type] == 'text/html' mail.html_part = Mail::Part.new do content_type 'text/html; charset=UTF-8' + + # complete check + attr[:body] = html_complete_check( attr[:body] ) + body attr[:body] end @@ -71,4 +75,29 @@ module Channel::EmailBuild end mail end + +=begin + + full_html_document_string = Channel::EmailBuild.html_complete_check( html_string ) + +=end + + def self.html_complete_check(html) + return html if html =~ //i + + css = 'font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;' + + html = < + + + ' + + + + +HERE + + html + end end \ No newline at end of file diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb new file mode 100644 index 000000000..5e4acdb57 --- /dev/null +++ b/test/unit/email_build_test.rb @@ -0,0 +1,25 @@ +# encoding: utf-8 +require 'test_helper' + +class EmailBuildTest < ActiveSupport::TestCase + test 'document complete check' do + + html = 'test' + result = Channel::EmailBuild.html_complete_check( html ) + + assert( result =~ /^<\!DOCTYPE/, 'test 1') + assert( result !~ /^.+?<\!DOCTYPE/, 'test 1') + assert( result =~ //, 'test 1') + assert( result =~ /font-family/, 'test 1') + + + html = 'invalid test' + result = Channel::EmailBuild.html_complete_check( html ) + + assert( result !~ /^<\!DOCTYPE/, 'test 2') + assert( result =~ /^.+?<\!DOCTYPE/, 'test 2') + assert( result =~ //, 'test 2') + assert( result !~ /font-family/, 'test 2') + + end +end \ No newline at end of file