admin_panel_controller_test.rb
5.54 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
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
require File.dirname(__FILE__) + '/../test_helper'
require 'admin_panel_controller'
# Re-raise errors caught by the controller.
class AdminPanelController; def rescue_action(e) raise e end; end
class AdminPanelControllerTest < Test::Unit::TestCase
all_fixtures
def setup
@controller = AdminPanelController.new
@request = ActionController::TestRequest.new
@request.stubs(:ssl?).returns(true)
@response = ActionController::TestResponse.new
login_as(create_admin_user(Environment.default))
end
def test_local_files_reference
assert_local_files_reference
end
def test_valid_xhtml
assert_valid_xhtml
end
should 'manage the correct environment' do
current = Environment.create!(:name => 'test environment', :is_default => false)
current.domains.create!(:name => 'example.com')
@request.expects(:host).returns('example.com').at_least_once
get :index
assert_equal current, assigns(:environment)
end
should 'link to site_info editing page' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/site_info' }
end
should 'link to cateogries editing' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/categories' }
end
should 'link to design editor' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/environment_design' }
end
should 'link to features editing screen' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/features' }
end
should 'link to role editing screen' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/role' }
end
should 'link to region validator screen' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/region_validators' }
end
should 'link to edit message for disabled enterprise' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/message_for_disabled_enterprise' }
end
should 'display form for editing site info' do
get :site_info
assert_template 'site_info'
assert_tag :tag => 'textarea', :attributes => { :name => 'environment[description]'}
end
should 'display form for editing message for disabled enterprise' do
get :message_for_disabled_enterprise
assert_template 'message_for_disabled_enterprise'
assert_tag :tag => 'textarea', :attributes => { :name => 'environment[message_for_disabled_enterprise]'}
end
should 'save site description' do
post :site_info, :environment => { :description => "This is my new environment" }
assert_redirected_to :action => 'index'
assert_equal "This is my new environment", Environment.default.description
end
should 'save message for disabled enterprise' do
post :site_info, :environment => { :message_for_disabled_enterprise => "This enterprise is disabled" }
assert_redirected_to :action => 'index'
assert_equal "This enterprise is disabled", Environment.default.message_for_disabled_enterprise
end
should 'sanitize description with white_list' do
post :site_info, :environment => { :description => "This <strong>is</strong> <script>alert('alow')</script>my new environment" }
assert_redirected_to :action => 'index'
assert_equal "This <strong>is</strong> my new environment", Environment.default.description
end
should 'sanitize message for disabled enterprise with white_list' do
post :site_info, :environment => { :message_for_disabled_enterprise => "This <strong>is</strong> <script>alert('alow')</script>my new environment" }
assert_redirected_to :action => 'index'
assert_equal "This <strong>is</strong> my new environment", Environment.default.message_for_disabled_enterprise
end
should 'list templates' do
get :manage_templates
assert_kind_of Array, assigns(:person_templates)
assert_kind_of Array, assigns(:community_templates)
assert_kind_of Array, assigns(:enterprise_templates)
end
should 'display environment template options' do
e = Environment.default
@controller.stubs(:environment).returns(e)
profile_template = Profile.create!(:name =>'template_test', :identifier => 'template_test', :environment => e)
e.settings[:templates_ids] = [profile_template.id]
e.save!
e.stubs(:templates).with('person').returns([profile_template])
e.stubs(:templates).with('community').returns([profile_template])
e.stubs(:templates).with('enterprise').returns([profile_template])
assert_equal [profile_template], e.templates('person')
get :manage_templates
['person_template', 'community_template', 'enterprise_template'].each do |template|
assert_tag :tag => 'select', :attributes => { :id => "environment_#{template}"}, :descendant => { :tag => 'option', :content => 'template_test'}
end
end
should 'set template' do
e = Environment.default
@controller.stubs(:environment).returns(e)
profile_template = Enterprise.create!(:name =>'template_test', :identifier => 'template_test')
post :set_template, :environment => {:enterprise_template => profile_template.id}
assert_equal profile_template, e.enterprise_template
end
should 'not use WYSWYIG if disabled' do
e = Environment.default; e.disable('wysiwyg_editor_for_environment_home'); e.save!
get :site_info
assert_no_tag :tag => "script", :content => /tinyMCE\.init/
end
should 'use WYSWYIG if enabled' do
e = Environment.default; e.enable('wysiwyg_editor_for_environment_home'); e.save!
get :site_info
assert_tag :tag => "script", :content => /tinyMCE\.init/
end
end