tiny_mce_article_test.rb
3.41 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class TinyMceArticleTest < Test::Unit::TestCase
def setup
Article.rebuild_index
@profile = create_user('zezinho').person
end
attr_reader :profile
# this test can be removed when we get real tests for TinyMceArticle
should 'be an article' do
assert_subclass TextArticle, TinyMceArticle
end
should 'define description' do
assert_kind_of String, TinyMceArticle.description
end
should 'define short description' do
assert_kind_of String, TinyMceArticle.short_description
end
should 'be found when searching for articles by query' do
tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => profile)
assert_includes TinyMceArticle.find_by_contents('article'), tma
assert_includes Article.find_by_contents('article'), tma
end
should 'not sanitize target attribute' do
article = TinyMceArticle.create!(:name => 'open link in new window', :body => "open <a href='www.invalid.com' target='_blank'>link</a> in new window", :profile => profile)
assert_tag_in_string article.body, :tag => 'a', :attributes => {:target => '_blank'}
end
should 'not translate & to amp; over times' do
article = TinyMceArticle.create!(:name => 'link', :body => "<a href='www.invalid.com?param1=value¶m2=value'>link</a>", :profile => profile)
assert article.save
assert_no_match(/&amp;/, article.body)
assert_match(/&/, article.body)
end
should 'not escape comments from tiny mce article body' do
article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!-- comment --> article ...")
assert_equal "the <!-- comment --> article ...", article.body
end
should 'convert entities characters to UTF-8 instead of ISO-8859-1' do
article = TinyMceArticle.create!(:profile => profile, :name => 'teste ' + Time.now.to_s, :body => '<a title="informática">link</a>')
assert(article.body.is_utf8?, "%s expected to be valid UTF-8 content" % article.body.inspect)
end
should 'fix tinymce mess with itheora comments for IE from tiny mce article body' do
article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!--–-[if IE]--> just for ie... <!--[endif]-->")
assert_equal "the <!–-[if IE]> just for ie... <![endif]-–>", article.body
end
should 'not mess with <iframe and </iframe if it is from itheora' do
article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://itheora.org'></iframe>")
assert_equal "<iframe src=\"http://itheora.org\"></iframe>", article.body
end
should 'remove iframe if it is not from itheora' do
article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='anything'></iframe>")
assert_equal "", article.body
end
#TinymMCE convert config={"key":(.*)} in config={"key":(.*)}
should 'not replace " with &quot; when adding an Archive.org video' do
article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<embed flashvars='config={"key":"\#$b6eb72a0f2f1e29f3d4"}'> </embed>")
assert_equal "<embed flashvars=\"config={"key":"\#$b6eb72a0f2f1e29f3d4"}\"> </embed>", article.body
end
end