diff --git a/app/controllers/admin/environment_themes_controller.rb b/app/controllers/admin/environment_themes_controller.rb
new file mode 100644
index 0000000..49cfe24
--- /dev/null
+++ b/app/controllers/admin/environment_themes_controller.rb
@@ -0,0 +1,11 @@
+class EnvironmentThemesController < ThemesController
+
+ protect 'edit_appearance', :environment
+
+ no_design_blocks
+
+ def target
+ @target = environment
+ end
+
+end
diff --git a/app/controllers/my_profile/profile_themes_controller.rb b/app/controllers/my_profile/profile_themes_controller.rb
new file mode 100644
index 0000000..ccb0761
--- /dev/null
+++ b/app/controllers/my_profile/profile_themes_controller.rb
@@ -0,0 +1,75 @@
+class ProfileThemesController < ThemesController
+
+ needs_profile
+
+ protect 'edit_appearance', :profile
+
+ no_design_blocks
+
+ def target
+ @target = profile
+ end
+
+ def new
+ if !request.xhr?
+ id = params[:name] ? params[:name].to_slug : 'my-theme'
+ t = Theme.new(id, :name => params[:name], :owner => profile, :public => false)
+ t.save
+ redirect_to :action => 'index'
+ else
+ render :action => 'new', :layout => false
+ end
+ end
+
+ def edit
+ @theme = profile.find_theme(params[:id])
+ @css_files = @theme.css_files
+ @image_files = @theme.image_files
+ end
+
+ def add_css
+ @theme = profile.find_theme(params[:id])
+ if request.xhr?
+ render :action => 'add_css', :layout => false
+ else
+ @theme.add_css(params[:css])
+ redirect_to :action => 'edit', :id => @theme.id
+ end
+ end
+
+ def css_editor
+ @theme = profile.find_theme(params[:id])
+ @css = params[:css]
+
+ @code = @theme.read_css(@css)
+ render :action => 'css_editor', :layout => false
+ end
+
+ post_only :update_css
+ def update_css
+ @theme = profile.find_theme(params[:id])
+ @theme.update_css(params[:css], params[:csscode])
+ redirect_to :action => 'edit', :id => @theme.id
+ end
+
+ def add_image
+ @theme = profile.find_theme(params[:id])
+ if request.xhr?
+ render :action => 'add_image', :layout => false
+ else
+ @theme.add_image(params[:image].original_filename, params[:image].read)
+ redirect_to :action => 'edit', :id => @theme.id
+ end
+ end
+
+ def start_test
+ session[:theme] = params[:id]
+ redirect_to :controller => 'content_viewer', :profile => profile.identifier, :action => 'view_page'
+ end
+
+ def stop_test
+ session[:theme] = nil
+ redirect_to :action => 'index'
+ end
+
+end
diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb
deleted file mode 100644
index f5a4570..0000000
--- a/app/controllers/my_profile/themes_controller.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-class ThemesController < MyProfileController
-
- protect 'edit_appearance', :profile
- no_design_blocks
-
- def set
- profile.update_theme(params[:id])
- redirect_to :action => 'index'
- end
-
- def unset
- profile.update_theme(nil)
- redirect_to :action => 'index'
- end
-
- def index
- @themes = profile.environment.themes + Theme.approved_themes(profile)
- @current_theme = profile.theme
-
- @layout_templates = LayoutTemplate.all
- @current_template = profile.layout_template
- end
-
- def new
- if !request.xhr?
- id = params[:name] ? params[:name].to_slug : 'my-theme'
- t = Theme.new(id, :name => params[:name], :owner => profile, :public => false)
- t.save
- redirect_to :action => 'index'
- else
- render :action => 'new', :layout => false
- end
- end
-
- def edit
- @theme = profile.find_theme(params[:id])
- @css_files = @theme.css_files
- @image_files = @theme.image_files
- end
-
- def add_css
- @theme = profile.find_theme(params[:id])
- if request.xhr?
- render :action => 'add_css', :layout => false
- else
- @theme.add_css(params[:css])
- redirect_to :action => 'edit', :id => @theme.id
- end
- end
-
- def css_editor
- @theme = profile.find_theme(params[:id])
- @css = params[:css]
-
- @code = @theme.read_css(@css)
- render :action => 'css_editor', :layout => false
- end
-
- post_only :update_css
- def update_css
- @theme = profile.find_theme(params[:id])
- @theme.update_css(params[:css], params[:csscode])
- redirect_to :action => 'edit', :id => @theme.id
- end
-
- def add_image
- @theme = profile.find_theme(params[:id])
- if request.xhr?
- render :action => 'add_image', :layout => false
- else
- @theme.add_image(params[:image].original_filename, params[:image].read)
- redirect_to :action => 'edit', :id => @theme.id
- end
- end
-
- def start_test
- session[:theme] = params[:id]
- redirect_to :controller => 'content_viewer', :profile => profile.identifier, :action => 'view_page'
- end
-
- def stop_test
- session[:theme] = nil
- redirect_to :action => 'index'
- end
-
- def set_layout_template
- profile.update_layout_template(params[:id])
- redirect_to :action => 'index'
- end
-
-end
diff --git a/app/controllers/themes_controller.rb b/app/controllers/themes_controller.rb
new file mode 100644
index 0000000..20b7f94
--- /dev/null
+++ b/app/controllers/themes_controller.rb
@@ -0,0 +1,42 @@
+class ThemesController < ApplicationController
+
+ before_filter :login_required
+
+ no_design_blocks
+
+ # attr_reader :target
+
+ def target
+ @target
+ end
+
+ def index
+ @environment = environment
+ @themes = environment.themes + Theme.approved_themes(target)
+
+ @current_theme = target.theme
+
+ @layout_templates = LayoutTemplate.all
+ @current_template = target.layout_template
+ end
+
+ def set
+ target.update_theme(params[:id])
+ redirect_to :action => 'index'
+ end
+
+ def unset
+ if target.kind_of?(Environment)
+ target.update_theme('default')
+ else
+ target.update_theme(nil)
+ end
+ redirect_to :action => 'index'
+ end
+
+ def set_layout_template
+ target.update_layout_template(params[:id])
+ redirect_to :action => 'index'
+ end
+
+end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 23d1754..af15dff 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -26,7 +26,8 @@ class Environment < ActiveRecord::Base
'manage_environment_users' => N_('Manage environment users'),
'manage_environment_templates' => N_('Manage environment templates'),
'manage_environment_licenses' => N_('Manage environment licenses'),
- 'manage_environment_trusted_sites' => N_('Manage environment trusted sites')
+ 'manage_environment_trusted_sites' => N_('Manage environment trusted sites'),
+ 'edit_appearance' => N_('Edit appearance'),
}
module Roles
@@ -677,6 +678,14 @@ class Environment < ActiveRecord::Base
end
end
+ def update_theme(theme)
+ self.update_attribute(:theme, theme)
+ end
+
+ def update_layout_template(template)
+ self.update_attribute(:layout_template, template)
+ end
+
before_create do |env|
env.settings[:themes] ||= %w[
aluminium
diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml
index 8f69b87..c1072a0 100644
--- a/app/views/admin_panel/index.rhtml
+++ b/app/views/admin_panel/index.rhtml
@@ -6,6 +6,7 @@
<%= link_to _('Environment settings'), :action => 'site_info' %> |
<%= link_to _('Features'), :controller => 'features' %> |
<%= link_to _('Plugins'), :controller => 'plugins' %> |
+ <%= link_to _('Appearance'), :controller =>'environment_themes' %> |
<%= link_to _('Sideboxes'), :controller => 'environment_design'%> |
<%= link_to _('Homepage'), :action => 'set_portal_community' %> |
<%= link_to _('Licenses'), :controller =>'licenses' %> |
diff --git a/app/views/environment_themes/index.rhtml b/app/views/environment_themes/index.rhtml
new file mode 100644
index 0000000..4d0a6e0
--- /dev/null
+++ b/app/views/environment_themes/index.rhtml
@@ -0,0 +1,8 @@
+<%= render :partial => 'themes/select_template' %>
+<%= render :partial => 'themes/select_theme' %>
+
+
+
+<% button_bar do %>
+ <%= button(:back, _('Back'), :controller => 'admin_panel', :action => 'index') %>
+<% end %>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 0fc6b89..d900158 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -22,7 +22,7 @@
<%= control_panel_button(_('Edit sideboxes'), 'blocks', :controller => 'profile_design', :action => 'index') %>
- <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'themes', :action => 'index') %>
+ <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'profile_themes', :action => 'index') %>
<%= control_panel_button(_('Edit Header and Footer'), 'header-and-footer', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin?(environment) %>
diff --git a/app/views/profile_themes/add_css.rhtml b/app/views/profile_themes/add_css.rhtml
new file mode 100644
index 0000000..0517856
--- /dev/null
+++ b/app/views/profile_themes/add_css.rhtml
@@ -0,0 +1,11 @@
+<%= _('Add a CSS file') %>
+
+<% form_tag do %>
+ <%= labelled_form_field(_('File name'), text_field_tag('css')) %>
+
+ <% button_bar do %>
+ <%= submit_button(:add, _('Add')) %>
+ <%= lightbox_close_button(_('Cancel')) %>
+ <% end %>
+
+<% end %>
diff --git a/app/views/profile_themes/add_image.rhtml b/app/views/profile_themes/add_image.rhtml
new file mode 100644
index 0000000..0a31980
--- /dev/null
+++ b/app/views/profile_themes/add_image.rhtml
@@ -0,0 +1,6 @@
+<% form_tag({:action => 'add_image', :id => @theme.id}, :multipart => true) do %>
+ <%= labelled_form_field(_('Choose the image file'), file_field_tag(:image)) %>
+ <% button_bar do %>
+ <%= submit_button(:add, _('Add image')) %>
+ <% end %>
+<% end %>
diff --git a/app/views/profile_themes/css_editor.rhtml b/app/views/profile_themes/css_editor.rhtml
new file mode 100644
index 0000000..0f84624
--- /dev/null
+++ b/app/views/profile_themes/css_editor.rhtml
@@ -0,0 +1,13 @@
+<%= _('CSS code: "%s"') % @css %>
+
+<% form_tag({:action => 'update_css', :id => @theme.id }, :name => 'csscode_form') do %>
+ <%= hidden_field_tag('css', @css) %>
+ <%= text_area_tag('csscode', @code, :id => "codepressWindow", :class => 'codepress css') %>
+ <% button_bar do %>
+ <%= submit_button(:save, _('Save')) %>
+ <% end %>
+<% end %>
+
+
+
+
diff --git a/app/views/profile_themes/edit.rhtml b/app/views/profile_themes/edit.rhtml
new file mode 100644
index 0000000..b282c99
--- /dev/null
+++ b/app/views/profile_themes/edit.rhtml
@@ -0,0 +1,41 @@
+
+
+
+
+
<%= _('CSS files') %>
+
+ <% for css in @css_files %>
+ - <%= link_to_remote(css, :url => { :action => 'css_editor', :id => @theme.id, :css => css }, :update => { :success => 'css-code' }) %>
+ <% end %>
+
+ <% button_bar do %>
+ <%= lightbox_button(:add, _('New CSS'), :action => 'add_css', :id => @theme.id) %>
+ <% end %>
+
+
+
+
<%= _('Images') %>
+
+ <% for image in @image_files %>
+ - <%= image_tag("/user_themes/#{@theme.id}/images/#{image}") %>
+ <% end %>
+
+ <% button_bar do %>
+ <%= lightbox_button(:add, _('Add image'), :action => 'add_image', :id => @theme.id) %>
+ <% end %>
+
+
+
+
+ <%= _('Select a CSS file to edit') %>
+
+
+
+<%# javascript_include_tag 'codepress/codepress' %>
diff --git a/app/views/profile_themes/index.rhtml b/app/views/profile_themes/index.rhtml
new file mode 100644
index 0000000..55c25ad
--- /dev/null
+++ b/app/views/profile_themes/index.rhtml
@@ -0,0 +1,48 @@
+<%= render :partial => 'themes/select_template' %>
+<%= render :partial => 'themes/select_theme' %>
+
+<% if environment.enabled?('user_themes') %>
+
+
+
<%= _('My themes') %>
+
+ <% for themes in profile.themes.in_groups_of(3) %>
+
+ <% for theme in themes %><%=
+ if theme
+
+ selected = theme.id == @current_theme
+ sel_html = selected ?
+ content_tag('big', _('(current)') ) :
+ link_to(_('Use this theme'), :action => 'set', :id => theme.id)
+
+ content_tag( 'div',
+ image_tag(
+ '/images/icons-app/design-editor.png',
+ :alt => (_('The "%s" theme.') % theme.name)) +
+ '
' +
+ content_tag('strong', theme.name, :class => 'name') +
+ '
'+ sel_html +'
' +
+ link_to(_('Edit this theme'), :action => 'edit', :id => theme.id) +
+ '
' +
+ link_to(_('Test this theme'), :action => 'start_test', :id => theme.id) +
+ '
',
+ :class => 'theme-opt list-opt' + (selected ? ' selected' : '')
+ )
+
+ end
+ %><% end %>
+
+ <% end %>
+
+
+<% end %>
+
+
+
+<% button_bar do %>
+ <% if environment.enabled?('user_themes') %>
+ <%= lightbox_button(:add, _('New theme ...'), :action => 'new') %>
+ <% end %>
+ <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %>
+<% end %>
diff --git a/app/views/profile_themes/new.rhtml b/app/views/profile_themes/new.rhtml
new file mode 100644
index 0000000..fb77600
--- /dev/null
+++ b/app/views/profile_themes/new.rhtml
@@ -0,0 +1,10 @@
+<%= _('Create new theme') %>
+
+<% form_tag(:action => 'new') do %>
+
+ <%= labelled_form_field(_('Name of the new theme:'), text_field_tag(:name)) %>
+
+ <% button_bar do %>
+ <%= submit_button(:save, _('Create')) %>
+ <% end %>
+<% end %>
diff --git a/app/views/shared/theme_test_panel.rhtml b/app/views/shared/theme_test_panel.rhtml
index d198822..ce51487 100644
--- a/app/views/shared/theme_test_panel.rhtml
+++ b/app/views/shared/theme_test_panel.rhtml
@@ -6,8 +6,8 @@
<%= _('You can move this window away to have a better visualization of specific parts of screen.') %>
<% button_bar do %>
- <%= button(:ok, _('Finished testing'), :controller => 'themes', :profile => theme_owner, :action => 'stop_test', :id => current_theme) %>
- <%= button(:edit, _('Edit theme'), :controller => 'themes', :profile => theme_owner, :action => 'edit', :id => current_theme) %>
+ <%= button(:ok, _('Finished testing'), :controller => 'profile_themes', :profile => theme_owner, :action => 'stop_test', :id => current_theme) %>
+ <%= button(:edit, _('Edit theme'), :controller => 'profile_themes', :profile => theme_owner, :action => 'edit', :id => current_theme) %>
<% end %>
<%= draggable_element('theme-test-panel') %>
diff --git a/app/views/themes/_select_template.rhtml b/app/views/themes/_select_template.rhtml
new file mode 100644
index 0000000..c7bac9b
--- /dev/null
+++ b/app/views/themes/_select_template.rhtml
@@ -0,0 +1,35 @@
+<%= _('Editing Appearance') %>
+
+
+
+
<%= _('Select template') %>
+
+<% for templates in @layout_templates.in_groups_of(3) %>
+
+ <% for template in templates %><%=
+ if template
+ base_content = image_tag(
+ "/designs/templates/#{template.id}/thumbnail.png",
+ :alt => _('The "%s" template')) +
+ '
'.html_safe +
+ content_tag('strong', template.name, :class => 'name') +
+ '
'.html_safe
+
+ if @current_template == template.id # selected
+ content_tag( 'div',
+ base_content + content_tag('big', _('(current)') ) +'
'.html_safe,
+ :class => 'template-opt list-opt selected')
+ else # Not selected
+ link_to(
+ base_content +'
'.html_safe,
+ { :action => 'set_layout_template', :id => template.id },
+ :class => 'template-opt list-opt')
+ end
+
+ end
+ %><% end %>
+
+<% end %>
+
+
+
diff --git a/app/views/themes/_select_theme.rhtml b/app/views/themes/_select_theme.rhtml
new file mode 100644
index 0000000..2c102cf
--- /dev/null
+++ b/app/views/themes/_select_theme.rhtml
@@ -0,0 +1,37 @@
+<% if !@themes.empty? %>
+
+
+
<%= _('Select theme') %>
+<%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %>
+
+<% for themes in @themes.in_groups_of(3) %>
+
+ <% for theme in themes %><%=
+ if theme
+
+ base_content = image_tag(
+ "/designs/themes/#{theme.id}/preview.png",
+ :alt => (_('The "%s" theme.') % theme.name)) +
+ '
'.html_safe +
+ content_tag('strong', theme.name, :class => 'name') +
+ '
'.html_safe
+
+ if theme.id == @current_theme # selected
+ content_tag( 'div',
+ base_content + content_tag('big', _('(current)') ) +'
'.html_safe,
+ :class => 'theme-opt list-opt selected')
+ else # Not selected
+ link_to(
+ base_content + '
'.html_safe,
+ { :action => 'set', :id => theme.id },
+ :class => 'theme-opt list-opt')
+ end
+
+ end
+ %><% end %>
+
+<% end %>
+
+
+<% end %>
+
diff --git a/app/views/themes/add_css.rhtml b/app/views/themes/add_css.rhtml
deleted file mode 100644
index 0517856..0000000
--- a/app/views/themes/add_css.rhtml
+++ /dev/null
@@ -1,11 +0,0 @@
-<%= _('Add a CSS file') %>
-
-<% form_tag do %>
- <%= labelled_form_field(_('File name'), text_field_tag('css')) %>
-
- <% button_bar do %>
- <%= submit_button(:add, _('Add')) %>
- <%= lightbox_close_button(_('Cancel')) %>
- <% end %>
-
-<% end %>
diff --git a/app/views/themes/add_image.rhtml b/app/views/themes/add_image.rhtml
deleted file mode 100644
index 0a31980..0000000
--- a/app/views/themes/add_image.rhtml
+++ /dev/null
@@ -1,6 +0,0 @@
-<% form_tag({:action => 'add_image', :id => @theme.id}, :multipart => true) do %>
- <%= labelled_form_field(_('Choose the image file'), file_field_tag(:image)) %>
- <% button_bar do %>
- <%= submit_button(:add, _('Add image')) %>
- <% end %>
-<% end %>
diff --git a/app/views/themes/css_editor.rhtml b/app/views/themes/css_editor.rhtml
deleted file mode 100644
index 0f84624..0000000
--- a/app/views/themes/css_editor.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= _('CSS code: "%s"') % @css %>
-
-<% form_tag({:action => 'update_css', :id => @theme.id }, :name => 'csscode_form') do %>
- <%= hidden_field_tag('css', @css) %>
- <%= text_area_tag('csscode', @code, :id => "codepressWindow", :class => 'codepress css') %>
- <% button_bar do %>
- <%= submit_button(:save, _('Save')) %>
- <% end %>
-<% end %>
-
-
-
-
diff --git a/app/views/themes/edit.rhtml b/app/views/themes/edit.rhtml
deleted file mode 100644
index b282c99..0000000
--- a/app/views/themes/edit.rhtml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
<%= _('CSS files') %>
-
- <% for css in @css_files %>
- - <%= link_to_remote(css, :url => { :action => 'css_editor', :id => @theme.id, :css => css }, :update => { :success => 'css-code' }) %>
- <% end %>
-
- <% button_bar do %>
- <%= lightbox_button(:add, _('New CSS'), :action => 'add_css', :id => @theme.id) %>
- <% end %>
-
-
-
-
<%= _('Images') %>
-
- <% for image in @image_files %>
- - <%= image_tag("/user_themes/#{@theme.id}/images/#{image}") %>
- <% end %>
-
- <% button_bar do %>
- <%= lightbox_button(:add, _('Add image'), :action => 'add_image', :id => @theme.id) %>
- <% end %>
-
-
-
-
- <%= _('Select a CSS file to edit') %>
-
-
-
-<%# javascript_include_tag 'codepress/codepress' %>
diff --git a/app/views/themes/index.rhtml b/app/views/themes/index.rhtml
deleted file mode 100644
index 4d8dfbc..0000000
--- a/app/views/themes/index.rhtml
+++ /dev/null
@@ -1,120 +0,0 @@
-<%= _('Editing Appearance') %>
-
-
-
-
<%= _('Select template') %>
-
-<% for templates in @layout_templates.in_groups_of(3) %>
-
- <% for template in templates %><%=
- if template
- base_content = image_tag(
- "/designs/templates/#{template.id}/thumbnail.png",
- :alt => _('The "%s" template')) +
- '
'.html_safe +
- content_tag('strong', template.name, :class => 'name') +
- '
'.html_safe
-
- if @current_template == template.id # selected
- content_tag( 'div',
- base_content + content_tag('big', _('(current)') ) +'
'.html_safe,
- :class => 'template-opt list-opt selected')
- else # Not selected
- link_to(
- base_content +'
'.html_safe,
- { :action => 'set_layout_template', :id => template.id },
- :class => 'template-opt list-opt')
- end
-
- end
- %><% end %>
-
-<% end %>
-
-
-
-
-<% if !@themes.empty? %>
-
-
-
<%= _('Select theme') %>
-<%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %>
-
-<% for themes in @themes.in_groups_of(3) %>
-
- <% for theme in themes %><%=
- if theme
-
- base_content = image_tag(
- "/designs/themes/#{theme.id}/preview.png",
- :alt => (_('The "%s" theme.') % theme.name)) +
- '
'.html_safe +
- content_tag('strong', theme.name, :class => 'name') +
- '
'.html_safe
-
- if theme.id == @current_theme # selected
- content_tag( 'div',
- base_content + content_tag('big', _('(current)') ) +'
'.html_safe,
- :class => 'theme-opt list-opt selected')
- else # Not selected
- link_to(
- base_content + '
'.html_safe,
- { :action => 'set', :id => theme.id },
- :class => 'theme-opt list-opt')
- end
-
- end
- %><% end %>
-
-<% end %>
-
-
-<% end %>
-
-
-
-<% if environment.enabled?('user_themes') %>
-
-
-
<%= _('My themes') %>
-
- <% for themes in profile.themes.in_groups_of(3) %>
-
- <% for theme in themes %><%=
- if theme
-
- selected = theme.id == @current_theme
- sel_html = selected ?
- content_tag('big', _('(current)') ) :
- link_to(_('Use this theme'), :action => 'set', :id => theme.id)
-
- content_tag( 'div',
- image_tag(
- '/images/icons-app/design-editor.png',
- :alt => (_('The "%s" theme.') % theme.name)) +
- '
' +
- content_tag('strong', theme.name, :class => 'name') +
- '
'+ sel_html +'
' +
- link_to(_('Edit this theme'), :action => 'edit', :id => theme.id) +
- '
' +
- link_to(_('Test this theme'), :action => 'start_test', :id => theme.id) +
- '
',
- :class => 'theme-opt list-opt' + (selected ? ' selected' : '')
- )
-
- end
- %><% end %>
-
- <% end %>
-
-
-<% end %>
-
-
-
-<% button_bar do %>
- <% if environment.enabled?('user_themes') %>
- <%= lightbox_button(:add, _('New theme ...'), :action => 'new') %>
- <% end %>
- <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %>
-<% end %>
diff --git a/app/views/themes/new.rhtml b/app/views/themes/new.rhtml
deleted file mode 100644
index fb77600..0000000
--- a/app/views/themes/new.rhtml
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= _('Create new theme') %>
-
-<% form_tag(:action => 'new') do %>
-
- <%= labelled_form_field(_('Name of the new theme:'), text_field_tag(:name)) %>
-
- <% button_bar do %>
- <%= submit_button(:save, _('Create')) %>
- <% end %>
-<% end %>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index b8b6db3..1650353 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -4319,7 +4319,7 @@ h1#agenda-title {
padding-left: 0px;
list-style-type: none;
}
-/* ==> public/stylesheets/controller_themes.css <== */
+/* ==> public/stylesheets/profile_controller_themes.css <== */
.action-themes-index .button-bar {
padding-top: 20px;
@@ -4393,23 +4393,23 @@ h1#agenda-title {
#user-themes a:hover {
text-decoration: underline;
}
-.controller-themes .template-preview-cell {
+.controller-profile_themes .template-preview-cell {
text-align: center;
}
-.controller-themes .theme-preview {
+.controller-profile_themes .theme-preview {
border: 1px solid #BBB;
}
-.controller-themes #css-files-list h2, .controller-themes #image-files-list h2 {
+.controller-profile_themes #css-files-list h2, .controller-profile_themes #image-files-list h2 {
margin-top: 0px;
}
-.controller-themes #css-files-list ul, .controller-themes #image-files-list ul, .controller-themes #css-code textarea {
+.controller-profile_themes #css-files-list ul, .controller-profile_themes #image-files-list ul, .controller-profile_themes #css-code textarea {
height: 280px;
}
-.controller-themes #css-files-list ul, .controller-themes #image-files-list ul {
+.controller-profile_themes #css-files-list ul, .controller-profile_themes #image-files-list ul {
overflow: auto;
}
/* header stuff */
-.controller-themes #theme-name input {
+.controller-profile_themes #theme-name input {
font-size: 18px;
border: 1px solid black;
background: white;
@@ -4418,78 +4418,78 @@ h1#agenda-title {
}
/* files list */
-.controller-themes #css-files-list {
+.controller-profile_themes #css-files-list {
width: 200px;
float: left;
margin-left: 10px;
}
-.controller-themes #css-files-list ul {
+.controller-profile_themes #css-files-list ul {
margin: 0px;
padding-left: 0px;
background: white;
border: 1px solid #bbb;
}
-.controller-themes #css-files-list li {
+.controller-profile_themes #css-files-list li {
list-style: none;
margin-bottom: 5px;
border-bottom: 1px solid #bbb;
}
-.controller-themes #css-files-list li a {
+.controller-profile_themes #css-files-list li a {
display: block;
padding: 1px 5px;
}
-.controller-themes #css-files-list a:hover {
+.controller-profile_themes #css-files-list a:hover {
color: red;
}
/* images list */
-.controller-themes #image-files-list {
+.controller-profile_themes #image-files-list {
width: 200px;
float: right;
margin-right: 10px;
}
-.controller-themes #image-files-list ul {
+.controller-profile_themes #image-files-list ul {
background: white;
border: 1px solid #bbb;
}
-.controller-themes #image-files-list ul, .controller-themes #image-files-list li {
+.controller-profile_themes #image-files-list ul, .controller-profile_themes #image-files-list li {
padding: 0px;
margin: 0px;
list-style: none;
}
-.controller-themes #image-files-list li {
+.controller-profile_themes #image-files-list li {
border-bottom: 1px solid #bbb;
padding: 5px 0px;
text-align: center;
}
-.controller-themes #image-files-list img {
+.controller-profile_themes #image-files-list img {
max-width: 98%;
max-height: 40px;
}
-.controller-themes .msie6 #image-files-list img {
+.controller-profile_themes .msie6 #image-files-list img {
width: 50%;
height: 40px;
}
-.controller-themes #image-files-list li span {
+.controller-profile_themes #image-files-list li span {
display: block;
width: 100%;
overflow: hidden;
}
/* textbox */
-.controller-themes #css-code {
+.controller-profile_themes #css-code {
margin-left: 220px;
margin-right: 220px;
}
-.controller-themes .msie6 #css-code {
+.controller-profile_themes .msie6 #css-code {
float: left;
margin-left: 20px;
margin-right: 240px;
}
-.controller-themes #css-code textarea {
+.controller-profile_themes #css-code textarea {
width: 100%;
}
-.controller-themes .msie6 #css-code textarea {
+.controller-profile_themes .msie6 #css-code textarea {
width: 500px;
}
/* highlights block stuff */
diff --git a/test/factories.rb b/test/factories.rb
index c395abb..6715ed2 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -55,7 +55,7 @@ module Noosfero::Factory
###### old stuff to be rearranged
def create_admin_user(env)
admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env)
- admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses'])
+ admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance'])
RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
admin_user.login
end
diff --git a/test/functional/environment_themes_controller_test.rb b/test/functional/environment_themes_controller_test.rb
new file mode 100644
index 0000000..a81f3df
--- /dev/null
+++ b/test/functional/environment_themes_controller_test.rb
@@ -0,0 +1,138 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class EnvironmentThemesController; def rescue_action(e) raise e end; end
+
+class EnvironmentThemesControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = EnvironmentThemesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
+
+ @env = Environment.default
+ login = create_admin_user(@env)
+ login_as(login)
+ @profile = User.find_by_login(login).person
+ end
+
+ def teardown
+ FileUtils.rm_rf(TMP_THEMES_DIR)
+ end
+
+ TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/environment_themes_controller'
+
+ should 'display themes that can be applied' do
+ env = Environment.default
+ Theme.stubs(:approved_themes).with(@env).returns([])
+ t1 = 't1'
+ t2 = 't2'
+ t3 = 't3'
+ env.themes = [t1, t2]
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2), Theme.new(t3)])
+ get :index
+
+ %w[ t1 t2 ].each do |item|
+ assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/#{item}" }
+ end
+
+ assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/t3" }
+ end
+
+ should 'highlight current theme' do
+ env = Environment.default
+ t1 = 'one'
+ t2 = 'two'
+ env.themes = [t1, t2]
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
+ env.update_theme(t1)
+ get :index
+
+ assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
+ assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/one" }
+ end
+
+ should 'save selection of theme' do
+ get :set, :id => 'onetheme'
+ env = Environment.default
+ assert_equal 'onetheme', env.theme
+ end
+
+
+ should 'unset selection of theme' do
+ get :unset
+ env = Environment.default
+ assert_equal 'default', env.theme
+ end
+
+ should 'display link to use the default theme' do
+ env = Environment.default
+ env.themes = ['new-theme']
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
+
+ get :index
+ assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/unset" }
+ end
+
+ should 'point back to admin panel' do
+ get :index
+ assert_tag :tag => 'a', :attributes => { :href => '/admin' }, :content => 'Back'
+ end
+
+ should 'list templates' do
+ all = LayoutTemplate.all
+
+ LayoutTemplate.expects(:all).returns(all)
+ get :index
+ assert_same all, assigns(:layout_templates)
+ end
+
+ should 'display links to set template' do
+ env = Environment.default
+ env.update_attributes!(:layout_template => 'rightbar')
+ t1 = LayoutTemplate.find('default')
+ t2 = LayoutTemplate.find('leftbar')
+ LayoutTemplate.expects(:all).returns([t1, t2])
+
+ get :index
+ assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"}
+ assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/leftbar"}
+ end
+
+ should 'highlight current template' do
+ env = Environment.default
+ env.update_attributes!(:layout_template => 'default')
+
+ t1 = LayoutTemplate.find('default')
+ t2 = LayoutTemplate.find('leftbar')
+ LayoutTemplate.expects(:all).returns([t1, t2])
+
+ get :index
+ assert_tag :attributes => { :class => 'template-opt list-opt selected' }
+ assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"}
+ end
+
+ should 'set template' do
+ env = Environment.default
+ post :set_layout_template, :id => 'leftbar'
+ env.reload
+ assert_equal 'leftbar', env.layout_template
+ assert_redirected_to :action => 'index'
+ end
+
+ should 'not display the "Select themes" section if there are no themes to choose from' do
+ env = Environment.default
+ env.themes = []; env.save!
+ Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
+ get :index
+ assert_no_tag :content => "Select theme"
+ end
+
+end
diff --git a/test/functional/profile_themes_controller_test.rb b/test/functional/profile_themes_controller_test.rb
new file mode 100644
index 0000000..9bca83d
--- /dev/null
+++ b/test/functional/profile_themes_controller_test.rb
@@ -0,0 +1,311 @@
+require File.dirname(__FILE__) + '/../test_helper'
+# require 'profile_themes_controller'
+
+class ProfileThemesController; def rescue_action(e) raise e end; end
+
+class ProfileThemesControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = ProfileThemesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
+
+ @profile = create_user('testinguser').person
+ login_as('testinguser')
+
+ @env = Environment.default
+ @env.enable('user_themes')
+ @env.save!
+ end
+ attr_reader :profile, :env
+
+ def teardown
+ FileUtils.rm_rf(TMP_THEMES_DIR)
+ end
+
+ TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/profile_themes_controller'
+
+ should 'display themes that can be applied' do
+ env = Environment.default
+ Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')])
+ t2 = 't2'
+ t3 = 't3'
+ env.themes = [t2]
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)])
+ get :index, :profile => 'testinguser'
+
+ %w[ t1 t2 ].each do |item|
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/#{item}" }
+ end
+
+ assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/t3" }
+ end
+
+ should 'highlight current theme' do
+ env = Environment.default
+ t1 = 'one'
+ t2 = 'two'
+ env.themes = [t1, t2]
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
+ profile.update_theme(t1)
+ get :index, :profile => 'testinguser'
+
+ assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
+ assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set/one" }
+ end
+
+ should 'display list of my themes for edition' do
+ Theme.create('three', :owner => profile)
+ Theme.create('four', :owner => profile)
+
+ get :index, :profile => 'testinguser'
+
+ %w[ three four ].each do |item|
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/edit/#{item}" }
+ end
+ end
+
+ should 'save selection of theme' do
+ get :set, :profile => 'testinguser', :id => 'onetheme'
+ profile = Profile.find(@profile.id)
+ assert_equal 'onetheme', profile.theme
+ end
+
+ should 'save selection of theme even if model is invalid' do
+ @profile.sex = nil
+ @profile.save!
+ @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
+
+ get :set, :profile => 'testinguser', :id => 'onetheme'
+ profile = Profile.find(@profile.id)
+ assert_equal 'onetheme', profile.theme
+ end
+
+ should 'unset selection of theme' do
+ get :unset, :profile => 'testinguser'
+ assert_equal nil, profile.theme
+ end
+
+ should 'display link to use the default theme' do
+ env = Environment.default
+ env.themes = ['new-theme']
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
+
+ get :index, :profile => 'testinguser'
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/unset" }
+ end
+
+ should 'point back to control panel' do
+ get :index, :profile => 'testinguser'
+ assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back'
+ end
+
+ should 'display screen for creating new theme' do
+ @request.expects(:xhr?).returns(true).at_least_once
+ get :new, :profile => 'testinguser'
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/new', :method => /post/i }, :descendant => { :tag => 'input', :attributes => { :type => 'text', :name => 'name' } }
+ end
+
+ should 'create a new theme' do
+ post :new, :profile => 'testinguser', :name => 'My theme'
+
+ ok('theme should be created') do
+ profile.themes.first.id == 'my-theme'
+ end
+ end
+
+ should 'edit a theme' do
+ theme = Theme.create('mytheme', :owner => profile)
+ get :edit, :profile => 'testinguser', :id => 'mytheme'
+
+ assert_equal theme, assigns(:theme)
+ end
+
+ should 'list CSS files in theme' do
+ theme = Theme.create('mytheme', :owner => profile)
+ theme.add_css('one.css')
+ theme.add_css('two.css')
+
+ get :edit, :profile => 'testinguser', :id => 'mytheme'
+
+ %w[ one.css two.css ].each do |item|
+ assert_includes assigns(:css_files), item
+ assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => item}
+ end
+ end
+
+ should 'display dialog for creating new CSS' do
+ theme = Theme.create('mytheme', :owner => profile)
+ @request.stubs(:xhr?).returns(true)
+ get :add_css, :profile => 'testinguser', :id => 'mytheme'
+
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/add_css/mytheme', :method => /post/i}
+ assert_tag :tag => 'input', :attributes => { :name => 'css', :type => 'text' }
+ assert_tag :tag => 'input', :attributes => { :type => 'submit' }
+ end
+
+ should 'be able to add new CSS to theme' do
+ theme = Theme.create('mytheme', :owner => profile)
+ post :add_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
+
+ assert_response :redirect
+
+ reloaded_theme = Theme.find('mytheme')
+ assert_includes reloaded_theme.css_files, 'test.css'
+ end
+
+ should 'load code from a given CSS file' do
+ theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
+ get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
+
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'textarea', :content => '/* sample code */' }
+ end
+
+ should 'be able to save CSS code' do
+ theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
+ get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
+
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'submit' } }
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'hidden', :name => 'css', :value => 'test.css' } }
+ end
+
+ should 'update css code when saving' do
+ theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
+ post :update_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css', :csscode => 'body { background: white; }'
+ assert_equal 'body { background: white; }', theme.read_css('test.css')
+ end
+
+ should 'list image files in theme' do
+ theme = Theme.create('mytheme', :owner => profile)
+ theme.add_image('one.png', 'FAKE IMAGE DATA 1')
+ theme.add_image('two.png', 'FAKE IMAGE DATA 2')
+
+ get :edit, :profile => 'testinguser', :id => 'mytheme'
+
+ assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/one.png' }
+ assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/two.png' }
+ end
+
+ should 'display "add image" button' do
+ theme = Theme.create('mytheme', :owner => profile)
+ get :edit, :profile => 'testinguser', :id => 'mytheme'
+
+ assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/add_image/mytheme' }
+ end
+
+ should 'display the "add image" dialog' do
+ theme = Theme.create('mytheme', :owner => profile)
+ @request.stubs(:xhr?).returns(true)
+
+ get :add_image, :profile => 'testinguser', :id => 'mytheme'
+ assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/profile_themes/add_image/mytheme', :method => /post/i, :enctype => 'multipart/form-data' }, :descendant => { :tag => 'input', :attributes => { :name => 'image', :type => 'file' } }
+ end
+
+ should 'be able to add new image to theme' do
+ theme = Theme.create('mytheme', :owner => profile)
+ @request.stubs(:xhr?).returns(false)
+
+ post :add_image, :profile => 'testinguser', :id => 'mytheme', :image => fixture_file_upload('/files/rails.png', 'image/png', :binary)
+ assert_redirected_to :action => "edit", :id => 'mytheme'
+ assert theme.image_files.include?('rails.png')
+ assert(system('diff', RAILS_ROOT + '/test/fixtures/files/rails.png', TMP_THEMES_DIR + '/mytheme/images/rails.png'), 'should put the correct uploaded file in the right place')
+ end
+
+ should 'link to "test theme"' do
+ Theme.create('one', :owner => profile)
+ Theme.create('two', :owner => profile)
+ get :index, :profile => 'testinguser'
+
+ %w[ one two ].each do |item|
+ assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/start_test/' + item }
+ end
+ end
+
+ should 'start testing theme' do
+ theme = Theme.create('theme-under-test', :owner => profile)
+ post :start_test, :profile => 'testinguser', :id => 'theme-under-test'
+
+ assert_equal 'theme-under-test', session[:theme]
+ assert_redirected_to :controller => 'content_viewer', :profile => 'testinguser', :action => 'view_page'
+ end
+
+ should 'stop testing theme' do
+ theme = Theme.create('theme-under-test', :owner => profile)
+ post :stop_test, :profile => 'testinguser', :id => 'theme-under-test'
+
+ assert_nil session[:theme]
+ assert_redirected_to :action => 'index'
+ end
+
+ should 'list templates' do
+ all = LayoutTemplate.all
+
+ LayoutTemplate.expects(:all).returns(all)
+ get :index, :profile => 'testinguser'
+ assert_same all, assigns(:layout_templates)
+ end
+
+ should 'display links to set template' do
+ profile.update_attributes!(:layout_template => 'rightbar')
+ t1 = LayoutTemplate.find('default')
+ t2 = LayoutTemplate.find('leftbar')
+ LayoutTemplate.expects(:all).returns([t1, t2])
+
+ get :index, :profile => 'testinguser'
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/default"}
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/leftbar"}
+ end
+
+ should 'highlight current template' do
+ profile.update_attributes!(:layout_template => 'default')
+
+ t1 = LayoutTemplate.find('default')
+ t2 = LayoutTemplate.find('leftbar')
+ LayoutTemplate.expects(:all).returns([t1, t2])
+
+ get :index, :profile => 'testinguser'
+ assert_tag :attributes => { :class => 'template-opt list-opt selected' }
+ assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/profile_themes/set_layout_template/default"}
+ end
+
+ should 'set template' do
+ post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
+ profile = Profile.find(@profile.id)
+ assert_equal 'leftbar', profile.layout_template
+ assert_redirected_to :action => 'index'
+ end
+
+ should 'set template even if the model is invalid' do
+ @profile.sex = nil
+ @profile.save!
+ @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
+
+ post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
+ profile = Profile.find(@profile.id)
+ assert_equal 'leftbar', profile.layout_template
+ assert_redirected_to :action => 'index'
+ end
+
+ should 'not display "new theme" button when user themes are disabled' do
+ env.disable('user_themes')
+ env.save!
+ get :index, :profile => 'testinguser'
+ assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/new' }
+ end
+
+ should 'not display the "Select themes" section if there are no themes to choose from' do
+ env.themes = []; env.save!
+ Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
+ get :index, :profile => "testinguser"
+ assert_no_tag :content => "Select theme"
+ end
+
+end
diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb
deleted file mode 100644
index 6574fd1..0000000
--- a/test/functional/themes_controller_test.rb
+++ /dev/null
@@ -1,311 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require 'themes_controller'
-
-class ThemesController; def rescue_action(e) raise e end; end
-
-class ThemesControllerTest < ActionController::TestCase
-
- def setup
- @controller = ThemesController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR)
-
- @profile = create_user('testinguser').person
- login_as('testinguser')
-
- @env = Environment.default
- @env.enable('user_themes')
- @env.save!
- end
- attr_reader :profile, :env
-
- def teardown
- FileUtils.rm_rf(TMP_THEMES_DIR)
- end
-
- TMP_THEMES_DIR = RAILS_ROOT + '/test/tmp/themes_controller'
-
- should 'display themes that can be applied' do
- env = Environment.default
- Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')])
- t2 = 't2'
- t3 = 't3'
- env.themes = [t2]
- env.save
-
- Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)])
- get :index, :profile => 'testinguser'
-
- %w[ t1 t2 ].each do |item|
- assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/#{item}" }
- end
-
- assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/t3" }
- end
-
- should 'highlight current theme' do
- env = Environment.default
- t1 = 'one'
- t2 = 'two'
- env.themes = [t1, t2]
- env.save
-
- Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
- profile.update_theme(t1)
- get :index, :profile => 'testinguser'
-
- assert_tag :attributes => { :class => 'theme-opt list-opt selected' }
- assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/one" }
- end
-
- should 'display list of my themes for edition' do
- Theme.create('three', :owner => profile)
- Theme.create('four', :owner => profile)
-
- get :index, :profile => 'testinguser'
-
- %w[ three four ].each do |item|
- assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/edit/#{item}" }
- end
- end
-
- should 'save selection of theme' do
- get :set, :profile => 'testinguser', :id => 'onetheme'
- profile = Profile.find(@profile.id)
- assert_equal 'onetheme', profile.theme
- end
-
- should 'save selection of theme even if model is invalid' do
- @profile.sex = nil
- @profile.save!
- @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
-
- get :set, :profile => 'testinguser', :id => 'onetheme'
- profile = Profile.find(@profile.id)
- assert_equal 'onetheme', profile.theme
- end
-
- should 'unset selection of theme' do
- get :unset, :profile => 'testinguser'
- assert_equal nil, profile.theme
- end
-
- should 'display link to use the default theme' do
- env = Environment.default
- env.themes = ['new-theme']
- env.save
-
- Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
-
- get :index, :profile => 'testinguser'
- assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/unset" }
- end
-
- should 'point back to control panel' do
- get :index, :profile => 'testinguser'
- assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back'
- end
-
- should 'display screen for creating new theme' do
- @request.expects(:xhr?).returns(true).at_least_once
- get :new, :profile => 'testinguser'
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/new', :method => /post/i }, :descendant => { :tag => 'input', :attributes => { :type => 'text', :name => 'name' } }
- end
-
- should 'create a new theme' do
- post :new, :profile => 'testinguser', :name => 'My theme'
-
- ok('theme should be created') do
- profile.themes.first.id == 'my-theme'
- end
- end
-
- should 'edit a theme' do
- theme = Theme.create('mytheme', :owner => profile)
- get :edit, :profile => 'testinguser', :id => 'mytheme'
-
- assert_equal theme, assigns(:theme)
- end
-
- should 'list CSS files in theme' do
- theme = Theme.create('mytheme', :owner => profile)
- theme.add_css('one.css')
- theme.add_css('two.css')
-
- get :edit, :profile => 'testinguser', :id => 'mytheme'
-
- %w[ one.css two.css ].each do |item|
- assert_includes assigns(:css_files), item
- assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => item}
- end
- end
-
- should 'display dialog for creating new CSS' do
- theme = Theme.create('mytheme', :owner => profile)
- @request.stubs(:xhr?).returns(true)
- get :add_css, :profile => 'testinguser', :id => 'mytheme'
-
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/add_css/mytheme', :method => /post/i}
- assert_tag :tag => 'input', :attributes => { :name => 'css', :type => 'text' }
- assert_tag :tag => 'input', :attributes => { :type => 'submit' }
- end
-
- should 'be able to add new CSS to theme' do
- theme = Theme.create('mytheme', :owner => profile)
- post :add_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
-
- assert_response :redirect
-
- reloaded_theme = Theme.find('mytheme')
- assert_includes reloaded_theme.css_files, 'test.css'
- end
-
- should 'load code from a given CSS file' do
- theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
- get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
-
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'textarea', :content => '/* sample code */' }
- end
-
- should 'be able to save CSS code' do
- theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
- get :css_editor, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css'
-
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'submit' } }
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/update_css/mytheme' }, :descendant => { :tag => 'input', :attributes => { :type => 'hidden', :name => 'css', :value => 'test.css' } }
- end
-
- should 'update css code when saving' do
- theme = Theme.create('mytheme', :owner => profile); theme.update_css('test.css', '/* sample code */')
- post :update_css, :profile => 'testinguser', :id => 'mytheme', :css => 'test.css', :csscode => 'body { background: white; }'
- assert_equal 'body { background: white; }', theme.read_css('test.css')
- end
-
- should 'list image files in theme' do
- theme = Theme.create('mytheme', :owner => profile)
- theme.add_image('one.png', 'FAKE IMAGE DATA 1')
- theme.add_image('two.png', 'FAKE IMAGE DATA 2')
-
- get :edit, :profile => 'testinguser', :id => 'mytheme'
-
- assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/one.png' }
- assert_tag :tag => 'img', :attributes => { :src => '/user_themes/mytheme/images/two.png' }
- end
-
- should 'display "add image" button' do
- theme = Theme.create('mytheme', :owner => profile)
- get :edit, :profile => 'testinguser', :id => 'mytheme'
-
- assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/add_image/mytheme' }
- end
-
- should 'display the "add image" dialog' do
- theme = Theme.create('mytheme', :owner => profile)
- @request.stubs(:xhr?).returns(true)
-
- get :add_image, :profile => 'testinguser', :id => 'mytheme'
- assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testinguser/themes/add_image/mytheme', :method => /post/i, :enctype => 'multipart/form-data' }, :descendant => { :tag => 'input', :attributes => { :name => 'image', :type => 'file' } }
- end
-
- should 'be able to add new image to theme' do
- theme = Theme.create('mytheme', :owner => profile)
- @request.stubs(:xhr?).returns(false)
-
- post :add_image, :profile => 'testinguser', :id => 'mytheme', :image => fixture_file_upload('/files/rails.png', 'image/png', :binary)
- assert_redirected_to :action => "edit", :id => 'mytheme'
- assert theme.image_files.include?('rails.png')
- assert(system('diff', RAILS_ROOT + '/test/fixtures/files/rails.png', TMP_THEMES_DIR + '/mytheme/images/rails.png'), 'should put the correct uploaded file in the right place')
- end
-
- should 'link to "test theme"' do
- Theme.create('one', :owner => profile)
- Theme.create('two', :owner => profile)
- get :index, :profile => 'testinguser'
-
- %w[ one two ].each do |item|
- assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/start_test/' + item }
- end
- end
-
- should 'start testing theme' do
- theme = Theme.create('theme-under-test', :owner => profile)
- post :start_test, :profile => 'testinguser', :id => 'theme-under-test'
-
- assert_equal 'theme-under-test', session[:theme]
- assert_redirected_to :controller => 'content_viewer', :profile => 'testinguser', :action => 'view_page'
- end
-
- should 'stop testing theme' do
- theme = Theme.create('theme-under-test', :owner => profile)
- post :stop_test, :profile => 'testinguser', :id => 'theme-under-test'
-
- assert_nil session[:theme]
- assert_redirected_to :action => 'index'
- end
-
- should 'list templates' do
- all = LayoutTemplate.all
-
- LayoutTemplate.expects(:all).returns(all)
- get :index, :profile => 'testinguser'
- assert_same all, assigns(:layout_templates)
- end
-
- should 'display links to set template' do
- profile.update_attributes!(:layout_template => 'rightbar')
- t1 = LayoutTemplate.find('default')
- t2 = LayoutTemplate.find('leftbar')
- LayoutTemplate.expects(:all).returns([t1, t2])
-
- get :index, :profile => 'testinguser'
- assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/default"}
- assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/leftbar"}
- end
-
- should 'highlight current template' do
- profile.update_attributes!(:layout_template => 'default')
-
- t1 = LayoutTemplate.find('default')
- t2 = LayoutTemplate.find('leftbar')
- LayoutTemplate.expects(:all).returns([t1, t2])
-
- get :index, :profile => 'testinguser'
- assert_tag :attributes => { :class => 'template-opt list-opt selected' }
- assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set_layout_template/default"}
- end
-
- should 'set template' do
- post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
- profile = Profile.find(@profile.id)
- assert_equal 'leftbar', profile.layout_template
- assert_redirected_to :action => 'index'
- end
-
- should 'set template even if the model is invalid' do
- @profile.sex = nil
- @profile.save!
- @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save!
-
- post :set_layout_template, :profile => 'testinguser', :id => 'leftbar'
- profile = Profile.find(@profile.id)
- assert_equal 'leftbar', profile.layout_template
- assert_redirected_to :action => 'index'
- end
-
- should 'not display "new theme" button when user themes are disabled' do
- env.disable('user_themes')
- env.save!
- get :index, :profile => 'testinguser'
- assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/themes/new' }
- end
-
- should 'not display the "Select themes" section if there are no themes to choose from' do
- env.themes = []; env.save!
- Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir
- get :index, :profile => "testinguser"
- assert_no_tag :content => "Select theme"
- end
-
-end
--
libgit2 0.21.2