article_test.rb
3.74 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require_relative '../test_helper'
require 'benchmark'
class ArticleTest < ActiveSupport::TestCase
def setup
@profile = fast_create(Community)
@article = fast_create(TextArticle, :profile_id => profile.id)
@environment = Environment.default
@environment.enable_plugin(CommentParagraphPlugin)
end
attr_reader :article, :environment, :profile
should 'return paragraph comments from article' do
comment1 = fast_create(Comment, :paragraph_uuid => 1, :source_id => article.id)
comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id)
assert_equal [comment1], article.paragraph_comments
end
should 'allow save if comment paragraph macro is not removed for paragraph with comments' do
article.body = "<div class=\"macro\" data-macro-paragraph_uuid=0></div>"
comment1 = fast_create(Comment, :paragraph_uuid => 0, :source_id => article.id)
assert article.save
end
should 'not parse html if the plugin is not enabled' do
article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
environment.disable_plugin(CommentParagraphPlugin)
assert !environment.plugin_enabled?(CommentParagraphPlugin)
article.save!
assert_equal "<p>paragraph 1</p><p>paragraph 2</p>", article.body
end
should 'parse html if the plugin is not enabled' do
article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
article.comment_paragraph_plugin_activate = true
article.save!
assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
end
should 'do not remove macro div when disable comment paragraph' do
article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
article.comment_paragraph_plugin_activate = true
article.save!
assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
article.comment_paragraph_plugin_activate = false
article.save!
assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
end
should 'parse html when activate comment paragraph' do
article.body = "<p>paragraph 1</p><p>paragraph 2</p>"
article.comment_paragraph_plugin_activate = false
article.save!
assert_equal "<p>paragraph 1</p><p>paragraph 2</p>", article.body
article.comment_paragraph_plugin_activate = true
article.save!
assert_match /data-macro="comment_paragraph_plugin\/allow_comment"/, article.body
end
should 'be enabled if plugin is enabled and article is a kind of TextArticle' do
assert article.comment_paragraph_plugin_enabled?
end
should 'not be enabled if plugin is not enabled' do
environment.disable_plugin(CommentParagraphPlugin)
assert !article.comment_paragraph_plugin_enabled?
end
should 'not be enabled if article if not a kind of TextArticle' do
article = fast_create(Article, :profile_id => profile.id)
assert !article.comment_paragraph_plugin_enabled?
end
should 'not be activated by default' do
article = fast_create(TextArticle, :profile_id => profile.id)
assert !article.comment_paragraph_plugin_activated?
end
should 'be activated by default if it is enabled and activation mode is auto' do
settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin)
settings.activation_mode = 'auto'
settings.save!
article = TextArticle.create!(:profile => profile, :name => 'title')
assert article.comment_paragraph_plugin_activated?
end
should 'be activated when forced' do
article.comment_paragraph_plugin_activate = true
assert article.comment_paragraph_plugin_activated?
end
should 'not be activated if plugin is not enabled' do
article.comment_paragraph_plugin_activate = true
environment.disable_plugin(CommentParagraphPlugin)
assert !article.comment_paragraph_plugin_enabled?
end
end