-
Notifications
You must be signed in to change notification settings - Fork 260
/
content_controller_test.rb
304 lines (246 loc) · 9.29 KB
/
content_controller_test.rb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
require 'test_helper'
module Cms
# This should be ported to features/content_pages.feature over time.
class ContentControllerTest < ActionController::TestCase
include Cms::ControllerTestHelper
def setup
given_there_is_a_guest_group
given_there_is_a_cmsadmin
given_there_is_a_sitemap
end
def test_show_another_page
@page = create(:page, :section => root_section, :path => "/about", :name => "Test About", :template_file_name => "default.html.erb", :publish_on_save => true)
get :show, :path => "about"
assert_select "title", "Test About"
end
def test_page_not_found_to_cms_admin
login_as_cms_admin
get :show, :path => "foo"
assert_response :not_found
assert_select "title", "Page Not Found"
assert_select "h2", "There is no page at /foo"
end
def test_show_protected_page_to_privileged_user
create_protected_page
login_as @privileged_user
get :show, :path => "secret"
assert_response :success
assert_select "title", "Shhh... It's a Secret" # Should page_title be html_safe or not?
end
def test_show_archived_page_to_user
create_archived_page
login_as_cms_admin
get :show, :path => "archived"
assert_response :success
assert_select "title", "Archived"
end
def test_show_page_route
@page_template = create(:page_template, :name => "test_show_page_route")
@page = create(:page,
:section => root_section,
:template_file_name => "test_show_page_route.html.erb")
@portlet = DynamicPortlet.create!(:name => "Test",
:template => "<h1><%= @foo %></h1>",
:connect_to_page_id => @page.id, :connect_to_container => "main")
@page_route = @page.page_routes.create(:pattern => "/foo", :code => "@foo = params[:foo]")
reset(:page)
@page.publish!
get :show_page_route, :foo => "42", :_page_route_id => @page_route.id
assert_response :success
assert_select "h1", "42"
end
def test_show_page_with_content
create_page_with_content
get :show, :path => "page_with_content"
assert_response :success
assert_select "h3", "TEST"
end
def test_is_file
assert_is_file(true, "/system/file.pdf")
assert_is_file(true, "/system/file.txt")
assert_is_file(true, "/system/file.html")
assert_is_file(false, "/system/file")
end
protected
def assert_is_file(truth, path)
@request = mock()
@controller.expects(:request).returns(@request)
@request.expects(:url).returns(path)
assert_equal truth, @controller.send(:is_file?)
end
def create_protected_user_section_group
@protected_section = create(:section, :parent => root_section)
@secret_group = create(:group, :name => "Secret")
@secret_group.sections << @protected_section
@privileged_user = create(:user, :login => "privileged")
@privileged_user.groups << @secret_group
end
def create_protected_page
create_protected_user_section_group
@page = create(:page,
:section => @protected_section,
:path => "/secret",
:name => "Shhh... It's a Secret",
:template_file_name => "default.html.erb",
:publish_on_save => true)
end
def create_file
@file = mock_file(:content_type => "text/plain")
@file_block = create(:file_block, :attachment_section => root_section, :attachment_file => @file, :attachment_file_path => "/test.txt", :publish_on_save => true)
end
def create_protected_file
create_protected_user_section_group
create_file
reset(:file_block)
@file_block.update_attributes(:attachment_section => @protected_section)
reset(:file_block)
end
def create_archived_page
@page = create(:page,
:section => root_section,
:path => "/archived",
:name => "Archived",
:archived => true,
:template_file_name => "default.html.erb",
:publish_on_save => true)
end
def create_page_with_content
@page_template = create(:page_template, :name => "testing_editting_content")
@page = create(:page,
:section => root_section,
:path => "/page_with_content",
:template_file_name => "testing_editting_content.html.erb")
@block = HtmlBlock.create!(:name => "Test",
:content => "<h3>TEST</h3>",
:connect_to_page_id => @page.id,
:connect_to_container => "main")
reset(:page)
@page.publish!
end
end
# CMS Page Caching Enabled (Production Mode)
# Logged in as guest
# mysite.com/page -> serves cached page
# cms.mysite.com/page -> redirect to mysite.com/page
#
# Logged in as a registered user
# mysite.com/page -> serves cached page
# cms.mysite.com/page -> redirect to mysite.com/page
#
# Logged in as cms user
# mysite.com/page -> serves cached page
# cms.mysite.com/page -> renders cms page editor
class ContentCachingEnabledControllerTest < ActionController::TestCase
tests Cms::ContentController
include Cms::ControllerTestHelper
def setup
given_there_is_a_guest_group
given_there_is_a_cmsadmin
given_there_is_a_sitemap
ActionController::Base.perform_caching = true
@page = create(:page, :section => root_section, :name => "Test Page", :path => "/page", :publish_on_save => true)
@registered_user = create(:user)
@registered_user.groups << Group.guest
end
def teardown
ActionController::Base.perform_caching = false
end
def test_guest_user_views_page_on_public_site
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_registered_user_views_page_on_public_site
login_as @registered_user
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_cms_user_views_page_on_public_site
login_as_cms_admin
@request.session[:page_mode] = "edit"
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
assert_select "iframe", {:count => 0}
end
def test_cms_user_views_page_on_cms_site_with_caching
login_as_cms_admin
@request.session[:page_mode] = "edit"
@request.host = "cms.mysite.com"
get :show, :path => "page", :use_route => false
assert_response :success
assert_select "title", "Test Page"
end
end
# CMS Page Caching Disabled (Development Mode)
# Logged in as guest
# mysite.com/page -> renders page
# cms.mysite.com/page -> renders page
#
# Logged in as a registered user
# mysite.com/page -> renders page
# cms.mysite.com/page -> renders page
#
# Logged in as cms user
# mysite.com/page -> renders cms page editor
# cms.mysite.com/page -> renders cms page editor
class ContentCachingDisabledControllerTest < ActionController::TestCase
tests Cms::ContentController
include Cms::ControllerTestHelper
def setup
given_there_is_a_guest_group
given_there_is_a_cmsadmin
given_there_is_a_sitemap
ActionController::Base.perform_caching = false
@page = create(:page, :section => root_section, :name => "Test Page", :path => "/page", :publish_on_save => true)
@registered_user = create(:user)
@registered_user.groups << Group.guest
end
def test_guest_user_views_page_on_public_site
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_guest_user_views_page_on_cms_site
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_registered_user_views_page_on_public_site
login_as @registered_user
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_registered_user_views_page_on_cms_site
login_as @registered_user
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_cms_user_views_page_on_public_site
login_as_cms_admin
@request.session[:page_mode] = "edit"
@request.host = "mysite.com"
get :show, :path => "page"
assert_response :success
assert_select "title", "Test Page"
end
def test_cms_user_views_page_on_cms_site
login_as_cms_admin
@request.session[:page_mode] = "edit"
@request.host = "cms.mysite.com"
get :show, :path => "page", :use_route => false
assert_response :success
assert_select "title", "Test Page"
end
end
end