diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml new file mode 100644 index 00000000..480e899e --- /dev/null +++ b/test/fixtures/custom_fields.yml @@ -0,0 +1,35 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +--- +cf_1: + name: Tag + min_length: 0 + regexp: "" + is_for_all: true + is_filter: true + type: DmsfFileRevisionCustomField + max_length: 0 + possible_values: + - User documentation + - Technical docuemntation + id: 21 + is_required: false + field_format: list + default_value: '' + editable: false + position: 1 diff --git a/test/fixtures/custom_values.yml b/test/fixtures/custom_values.yml new file mode 100644 index 00000000..4858d7e1 --- /dev/null +++ b/test/fixtures/custom_values.yml @@ -0,0 +1,30 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +--- +cv_1: + customized_type: DmsfFolder + custom_field_id: 21 + customized_id: 1 + id: 21 + value: 'User documentation' +cv_2: + customized_type: DmsfFileRevision + custom_field_id: 21 + customized_id: 1 + id: 22 + value: 'Technical documentation' diff --git a/test/fixtures/dmsf_file_revisions.yml b/test/fixtures/dmsf_file_revisions.yml index 9f132b23..987b132d 100644 --- a/test/fixtures/dmsf_file_revisions.yml +++ b/test/fixtures/dmsf_file_revisions.yml @@ -1,44 +1,46 @@ --- dmsf_file_revisions_001: - id: 1 - dmsf_file_id: 1 + id: 1 + dmsf_file_id: 1 source_dmsf_file_revision_id: NULL - name: "test.txt" - dmsf_folder_id: NULL - disk_filename: "test.txt" - size: 4 - mime_type: text/plain - title: "Test File" - description: NULL - workflow: NULL - minor_version: 0 - major_version: 1 - comment: NULL - deleted: 0 - deleted_by_user_id: NULL - user_id: 1 - dmsf_workflow_assigned_by: 1 + name: "test.txt" + dmsf_folder_id: NULL + disk_filename: "test.txt" + size: 4 + mime_type: text/plain + title: "Test File" + description: NULL + workflow: NULL + minor_version: 0 + major_version: 1 + comment: NULL + deleted: 0 + deleted_by_user_id: NULL + user_id: 1 + dmsf_workflow_assigned_by: 1 + dmsf_workflow_started_by: 1 #revision for file on non-enabled project dmsf_file_revisions_002: - id: 2 - dmsf_file_id: 2 + id: 2 + dmsf_file_id: 2 source_dmsf_file_revision_id: NULL - name: "test.txt" - dmsf_folder_id: NULL - disk_filename: "test.txt" - size: 4 - mime_type: text/plain - title: "Test File" - description: NULL - workflow: NULL - minor_version: 0 - major_version: 1 - comment: NULL - deleted: 0 - deleted_by_user_id: NULL - user_id: 1 - dmsf_workflow_assigned_by: 1 + name: "test.txt" + dmsf_folder_id: NULL + disk_filename: "test.txt" + size: 4 + mime_type: text/plain + title: "Test File" + description: NULL + workflow: NULL + minor_version: 0 + major_version: 1 + comment: NULL + deleted: 0 + deleted_by_user_id: NULL + user_id: 1 + dmsf_workflow_assigned_by: 1 + dmsf_workflow_started_by: 1 #revision for deleted file on dmsf-enabled project dmsf_file_revisions_003: @@ -59,3 +61,5 @@ dmsf_file_revisions_003: deleted: 1 deleted_by_user_id: 1 user_id: 1 + dmsf_workflow_assigned_by: 1 + dmsf_workflow_started_by: 1 diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index 547376d5..5dc1c7aa 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -1,6 +1,6 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2013 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,11 +16,35 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.dirname(__FILE__) + '/../test_helper' +require File.expand_path('../../test_helper', __FILE__) -class DmsfControllerTest < ActionController::TestCase - # Replace this with your real tests. - def test_truth - assert true +class DmsfControllerTest < RedmineDmsf::Test::TestCase + + fixtures :users, :dmsf_files, :dmsf_file_revisions, :dmsf_folders, + :custom_fields, :custom_values, :projects, :members, :member_roles, + :enabled_modules + + def setup + @request.session[:user_id] = 2 + @project = Project.find_by_id 1 + @folder = DmsfFolder.find_by_id 1 + @role = Role.find_by_id 1 + @custom_field = CustomField.find_by_id 21 + @custom_value_1 = CustomValue.find_by_id 21 + end + + def test_edit_folder + # Missing permissions + get :edit, :id => @project, :folder_id => @folder + assert_response 403 + + # Permissions OK + @role.add_permission! :view_dmsf_folders + @role.add_permission! :folder_manipulation + get :edit, :id => @project, :folder_id => @folder + assert_response :success + assert_select 'label', {:text => @custom_field.name} + assert_select 'option', {:value => @custom_value_1.value} end end + diff --git a/test/functional/dmsf_files_controller_test.rb b/test/functional/dmsf_files_controller_test.rb index 547376d5..64a7a166 100644 --- a/test/functional/dmsf_files_controller_test.rb +++ b/test/functional/dmsf_files_controller_test.rb @@ -1,6 +1,6 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2013 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,11 +16,40 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.dirname(__FILE__) + '/../test_helper' +require File.expand_path('../../test_helper', __FILE__) -class DmsfControllerTest < ActionController::TestCase - # Replace this with your real tests. - def test_truth - assert true +class DmsfFilesControllerTest < RedmineDmsf::Test::TestCase + + fixtures :users, :dmsf_files, :dmsf_file_revisions, :custom_fields, + :custom_values, :projects, :members, :member_roles, :enabled_modules, + :dmsf_file_revisions + + def setup + @request.session[:user_id] = 2 + @file = DmsfFolder.find_by_id 1 + @role = Role.find_by_id 1 + @custom_field = CustomField.find_by_id 21 + @custom_value_2 = CustomValue.find_by_id 22 + end + + def test_show_file + # Missing permissions + get :show, :id => @file + assert_response 403 + + # Permissions OK + @role.add_permission! :view_dmsf_files + @role.add_permission! :file_manipulation + get :show, :id => @file + assert_response :success + + # The last revision + assert_select 'label', {:text => @custom_field.name} + assert_select '.customfield', {:text => "#{@custom_field.name}: #{@custom_value_2.value}"} + + # A new revision + assert_select 'label', {:text => @custom_field.name} + assert_select 'option', {:value => @custom_value_2.value} end end + diff --git a/test/functional/dmsf_workflow_controller_test.rb b/test/functional/dmsf_workflow_controller_test.rb index d55a3ccd..3f0573b2 100644 --- a/test/functional/dmsf_workflow_controller_test.rb +++ b/test/functional/dmsf_workflow_controller_test.rb @@ -102,13 +102,13 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase def test_create assert_difference 'DmsfWorkflow.count', +1 do - post :create, :dmsf_workflow => {:name => 'wf3'}, :project_id => @project5.id + post :create, :name => 'wf3', :project_id => @project5.id end - assert_redirected_to settings_project_path(@project5, :tab => 'dmsf') + assert_redirected_to settings_project_path(@project5, :tab => 'dmsf_workflow') end def test_update - put :update, :id => @wf1.id, :dmsf_workflow => {:name => 'wf1a'} + put :update, :id => @wf1.id, :name => 'wf1a' @wf1.reload assert_equal 'wf1a', @wf1.name end @@ -118,7 +118,7 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase assert_difference 'DmsfWorkflow.count', -1 do delete :destroy, :id => @wf1.id end - assert_redirected_to settings_project_path(@project5, :tab => 'dmsf') + assert_redirected_to settings_project_path(@project5, :tab => 'dmsf_workflow') assert_equal 0, DmsfWorkflowStep.where(:dmsf_workflow_id => id).all.count end diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 803da864..1d9317e5 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -21,7 +21,7 @@ require File.expand_path('../../test_helper', __FILE__) class MyControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n - fixtures :users, :user_preferences, :dmsf_locks + fixtures :users, :user_preferences def setup @request.session[:user_id] = 2