diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb
index 099e1ebd..c98cce2e 100644
--- a/lib/redmine_dmsf/macros.rb
+++ b/lib/redmine_dmsf/macros.rb
@@ -27,29 +27,25 @@ Redmine::WikiFormatting::Macros.register do
"_file_id_ / _revision_id_ can be found in the link for file/revision download."
macro :dmsf do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
+ file = DmsfFile.visible.find args[0]
if args[2].blank?
revision = file.last_revision
else
- revision = DmsfFileRevision.find(args[2])
+ revision = DmsfFileRevision.find args[2]
if revision.dmsf_file != file
raise ActiveRecord::RecordNotFound
end
end
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project, { id: file.id })
- file_view_url = url_for(controller: :dmsf_files, action: 'view', id: file, download: args[2])
- title = args[1] ? args[1] : file.title
- title.gsub!(/\A"|"\z/,'') # Remove apostrophes
- title.gsub!(/\A'|'\z/,'')
- title = file.title if title.empty?
- return link_to(h(title),
- file_view_url,
- target: '_blank',
- title: h(revision.tooltip),
- 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
- else
+ unless User.current&.allowed_to?(:view_dmsf_files, file.project, { id: file.id })
raise l(:notice_not_authorized)
end
+ title = args[1].present? ? args[1] : file.title
+ title.gsub! /\A"|"\z/, '' # Remove apostrophes
+ title.gsub! /\A'|'\z/, ''
+ title = file.title if title.empty?
+ url = view_dmsf_file_path(id: file.id, download: args[2])
+ link_to h(title), url, target: '_blank', title: h(revision.tooltip),
+ 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}"
end
# dmsff - link to a folder
@@ -64,13 +60,13 @@ Redmine::WikiFormatting::Macros.register do
raise l(:notice_not_authorized)
end
else
- folder = DmsfFolder.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_folders, folder.project)
+ folder = DmsfFolder.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_folders, folder.project)
title = args[1] ? args[1] : folder.title
- title.gsub!(/\A"|"\z/,'') # Remove apostrophes
- title.gsub!(/\A'|'\z/,'')
+ title.gsub! /\A"|"\z/, '' # Remove leading and trailing apostrophe
+ title.gsub! /\A'|'\z/, ''
title = folder.title if title.empty?
- return link_to h(title), dmsf_folder_url(folder.project, folder_id: folder)
+ link_to h(title), dmsf_folder_url(folder.project, folder_id: folder)
else
raise l(:notice_not_authorized)
end
@@ -83,9 +79,12 @@ Redmine::WikiFormatting::Macros.register do
"_document_id_ can be found in the document's details."
macro :dmsfd do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- return link_to(h(args[1] ? args[1] : file.title), dmsf_file_path(id: file))
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
+ title = args[1].present? ? args[1] : file.title
+ title.gsub! /\A"|"\z/, '' # Remove leading and trailing apostrophe
+ title.gsub! /\A'|'\z/, ''
+ link_to h(title), dmsf_file_path(id: file)
else
raise l(:notice_not_authorized)
end
@@ -97,9 +96,9 @@ Redmine::WikiFormatting::Macros.register do
"_document_id_ can be found in the document's details."
macro :dmsfdesc do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- return textilizable(file.description)
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
+ textilizable file.description
else
raise l(:notice_not_authorized)
end
@@ -111,9 +110,9 @@ Redmine::WikiFormatting::Macros.register do
"_document_id_ can be found in the document's details."
macro :dmsfversion do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- return textilizable(file.version)
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
+ textilizable file.version
else
raise l(:notice_not_authorized)
end
@@ -125,9 +124,9 @@ Redmine::WikiFormatting::Macros.register do
"_document_id_ can be found in the document's details."
macro :dmsflastupdate do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- return textilizable(format_time(file.last_revision.updated_at))
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
+ textilizable format_time(file.last_revision.updated_at)
else
raise l(:notice_not_authorized)
end
@@ -136,12 +135,12 @@ Redmine::WikiFormatting::Macros.register do
# dmsft - link to the document's content preview
desc "Text referring to DMSF text document content:\n\n" +
"{{dmsft(file_id, lines_count)}}\n\n" +
- "_file_id_ can be found in the document's details. _lines_count_ indicate quantity of lines to show."
+ "_file_id_ can be found in the document's details. _lines_count_ indicates quantity of lines to show."
macro :dmsft do |obj, args|
raise ArgumentError if args.length < 2 # Requires file id and lines number
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- return file.preview(args[1].strip).gsub("\n", '
').html_safe
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
+ file.preview(args[1]).gsub("\n", '
').html_safe
else
raise l(:notice_not_authorized)
end
@@ -150,108 +149,95 @@ Redmine::WikiFormatting::Macros.register do
# dmsf_image - link to an image
desc "Wiki DMSF image:\n\n" +
"{{dmsf_image(file_id)}}\n" +
- "{{dmsf_image(file_id, size=300)}} -- with and size 300x300\n" +
+ "{{dmsf_image(file_id, size=50%)}} -- with size 50%\n" +
+ "{{dmsf_image(file_id, size=300)}} -- with size 300\n" +
"{{dmsf_image(file_id, height=300)}} -- with height (auto width)\n" +
"{{dmsf_image(file_id, width=300)}} -- with width (auto height)\n" +
- "{{dmsf_image(file_id, size=640x480)}} -- with and size 640x480"
+ "{{dmsf_image(file_id, size=640x480)}} -- with size 640x480"
macro :dmsf_image do |obj, args|
+ raise ArgumentError if args.length < 1 # Requires file id
args, options = extract_macro_options(args, :size, :width, :height, :title)
- file_id = args.first
- raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
- if file = DmsfFile.find_by(id: file_id)
- unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- raise l(:notice_not_authorized)
- end
- raise 'Not supported image format' unless file.image?
- url = url_for(controller: :dmsf_files, action: 'view', id: file)
- if size && size.include?('%')
- image_tag url, alt: file.title, width: size, height: size
- elsif height
- image_tag url, alt: file.title, width: 'auto', height: height
- elsif width
- image_tag url, alt: file.title, width: width, height: 'auto'
- else
- image_tag url, alt: file.title, size: size
- end
+ file = DmsfFile.visible.find args[0]
+ unless User.current&.allowed_to?(:view_dmsf_files, file.project)
+ raise l(:notice_not_authorized)
+ end
+ raise 'Not supported image format' unless file.image?
+ url = view_dmsf_file_path(file)
+ if size&.include?('%')
+ image_tag url, alt: file.title, width: size, height: size
+ elsif height
+ image_tag url, alt: file.title, width: 'auto', height: height
+ elsif width
+ image_tag url, alt: file.title, width: width, height: 'auto'
else
- raise "Document ID #{file_id} not found"
+ image_tag url, alt: file.title, size: size
end
end
# dmsf_video - link to a video
- desc "Wiki DMSF image:\n\n" +
+ desc "Wiki DMSF video:\n\n" +
"{{dmsf_video(file_id)}}\n" +
- "{{dmsf_video(file_id, size=300)}} -- with and size 300x300\n" +
+ "{{dmsf_video(file_id, size=50%)}} -- with size 50%\n" +
+ "{{dmsf_video(file_id, size=300)}} -- with size 300x300\n" +
"{{dmsf_video(file_id, height=300)}} -- with height (auto width)\n" +
"{{dmsf_video(file_id, width=300)}} -- with width (auto height)\n" +
- "{{dmsf_video(file_id, size=640x480)}} -- with and size 640x480"
+ "{{dmsf_video(file_id, size=640x480)}} -- with size 640x480"
macro :dmsf_video do |obj, args|
+ raise ArgumentError if args.length < 1 # Requires file id
args, options = extract_macro_options(args, :size, :width, :height, :title)
- file_id = args.first
- raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
- if file = DmsfFile.find_by(id: file_id)
- unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- raise l(:notice_not_authorized)
- end
- raise 'Not supported video format' unless file.video?
- url = url_for(controller: :dmsf_files, action: 'view', id: file)
- if size && size.include?('%')
- video_tag url, controls: true, alt: file.title, width: size, height: size
- elsif height
- video_tag url, controls: true, alt: file.title, width: 'auto', height: height
- elsif width
- video_tag url, controls: true, alt: file.title, width: width, height: 'auto'
- else
- video_tag url, controls: true, alt: file.title, size: size
- end
+ file = DmsfFile.visible.find args[0]
+ unless User.current&.allowed_to?(:view_dmsf_files, file.project)
+ raise l(:notice_not_authorized)
+ end
+ raise 'Not supported video format' unless file.video?
+ url = view_dmsf_file_path(file)
+ if size&.include?('%')
+ video_tag url, controls: true, alt: file.title, width: size, height: size
+ elsif height
+ video_tag url, controls: true, alt: file.title, width: 'auto', height: height
+ elsif width
+ video_tag url, controls: true, alt: file.title, width: width, height: 'auto'
else
- raise "Document ID #{file_id} not found"
+ video_tag url, controls: true, alt: file.title, size: size
end
end
# dmsftn - link to an image thumbnail
desc "Wiki DMSF thumbnail:\n\n" +
- "{{dmsftn(file_id)}} -- with default height 200(auto width)\n" +
+ "{{dmsftn(file_id)}} -- with default height 200 (auto width)\n" +
"{{dmsftn(file_id, size=300)}} -- with size 300x300\n" +
"{{dmsftn(file_id, height=300)}} -- with height (auto width)\n" +
"{{dmsftn(file_id, width=300)}} -- with width (auto height)\n" +
- "{{dmsftn(file_id, size=640x480)}} -- with and size 640x480"
+ "{{dmsftn(file_id, size=640x480)}} -- with size 640x480"
macro :dmsftn do |obj, args|
+ raise ArgumentError if args.length < 1 # Requires file id
args, options = extract_macro_options(args, :size, :width, :height, :title)
- file_id = args.first
- raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
- if file = DmsfFile.find_by(id: file_id)
- unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
- raise l(:notice_not_authorized)
- end
- raise 'Not supported image format' unless file.image?
- url = url_for(controller: :dmsf_files, action: 'view', id: file)
- file_view_url = url_for(controller: :dmsf_files, action: 'view', id: file, download: args[2])
- if size
- img = image_tag(url, alt: file.title, size: size)
- elsif height
- img = image_tag(url, alt: file.title, width: 'auto', height: height)
- elsif width
- img = image_tag(url, alt: file.title, width: width, height: 'auto')
- else
- img = image_tag(url, alt: file.title, width: 'auto', height: 200)
- end
- link_to img,
- file_view_url, target: '_blank',
- title: h(file.last_revision.try(:tooltip)),
- 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}"
- else
- raise "Document ID #{file_id} not found"
+ file = DmsfFile.visible.find args[0]
+ unless User.current&.allowed_to?(:view_dmsf_files, file.project)
+ raise l(:notice_not_authorized)
end
+ raise 'Not supported image format' unless file.image?
+ url = view_dmsf_file_path(file)
+ if size
+ img = image_tag(url, alt: file.title, size: size)
+ elsif height
+ img = image_tag(url, alt: file.title, width: 'auto', height: height)
+ elsif width
+ img = image_tag(url, alt: file.title, width: width, height: 'auto')
+ else
+ img = image_tag(url, alt: file.title, width: 'auto', height: 200)
+ end
+ link_to img, url, target: '_blank', title: h(file.last_revision.try(:tooltip)),
+ 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}"
end
# dmsfw - link to a document's approval workflow status
@@ -260,10 +246,10 @@ Redmine::WikiFormatting::Macros.register do
"_file_id_ can be found in the document's details."
macro :dmsfw do |obj, args|
raise ArgumentError if args.length < 1 # Requires file id
- file = DmsfFile.visible.find args[0].strip
- if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
+ file = DmsfFile.visible.find args[0]
+ if User.current&.allowed_to?(:view_dmsf_files, file.project)
raise ActiveRecord::RecordNotFound unless file.last_revision
- return file.last_revision.workflow_str(false)
+ file.last_revision.workflow_str(false)
else
raise l(:notice_not_authorized)
end
diff --git a/test/ci/ci.sh b/test/ci/ci.sh
index aaf711b6..c27ff474 100644
--- a/test/ci/ci.sh
+++ b/test/ci/ci.sh
@@ -79,9 +79,15 @@ RAILS_ENV=test REDMINE_LANG=en bundle exec rake redmine:load_default_data
#RAILS_ENV=test bundle exec rake test
# Run DMSF tests
+# Standard tests
bundle exec rake redmine:plugins:test:units NAME=redmine_dmsf RAILS_ENV=test
bundle exec rake redmine:plugins:test:functionals NAME=redmine_dmsf RAILS_ENV=test
bundle exec rake redmine:plugins:test:integration NAME=redmine_dmsf RAILS_ENV=test
+# Macros
+ruby plugin/redmine_dmsf/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb RAILS_ENV=test
+# Helpers
+ruby plugin/redmine_dmsf/test/helpers/dmsf_helper_test.rb RAILS_ENV=test
+ruby plugin/redmine_dmsf/test/helpers/dmsf_queries_helper_test.rb RAILS_ENV=test
# Litmus
diff --git a/test/fixtures/dmsf_file_revisions.yml b/test/fixtures/dmsf_file_revisions.yml
index d0d1f1d9..3d6afb09 100644
--- a/test/fixtures/dmsf_file_revisions.yml
+++ b/test/fixtures/dmsf_file_revisions.yml
@@ -233,4 +233,26 @@ dmsf_file_revisions_011:
dmsf_workflow_assigned_by_user_id: 1
dmsf_workflow_started_by_user_id: 1
digest: '81dc9bdb52d04dc20036dbd8313ed055'
- created_at: 2017-04-18 14:52:27 +02:00
\ No newline at end of file
+ created_at: 2017-04-18 14:52:27 +02:00
+
+dmsf_file_revisions_012:
+ id: 12
+ dmsf_file_id: 6
+ source_dmsf_file_revision_id: NULL
+ name: 'test.mp4'
+ disk_filename: 'test.mp4'
+ size: 4
+ mime_type: 'video/mp4'
+ title: 'Video file'
+ description: 'A video :-)'
+ workflow: 0
+ minor_version: 0
+ major_version: 1
+ comment: NULL
+ deleted: 0
+ deleted_by_user_id: NULL
+ user_id: 1
+ dmsf_workflow_assigned_by_user_id: NULL
+ dmsf_workflow_started_by_user_id: NULL
+ digest: '81dc9bdb52d04dc20036dbd8313ed055'
+ created_at: 2022-02-03 13:39:27 +02:00
\ No newline at end of file
diff --git a/test/fixtures/dmsf_files.yml b/test/fixtures/dmsf_files.yml
index 51d1a1f5..6b3bc9e5 100644
--- a/test/fixtures/dmsf_files.yml
+++ b/test/fixtures/dmsf_files.yml
@@ -50,7 +50,7 @@ dmsf_files_006:
id: 6
project_id: 1
dmsf_folder_id: 3
- name: 'test.txt'
+ name: 'test.mp4'
notification: false
deleted: 0
deleted_by_user_id: NULL
diff --git a/test/helper_test.rb b/test/helper_test.rb
index d716c304..96a50764 100644
--- a/test/helper_test.rb
+++ b/test/helper_test.rb
@@ -23,9 +23,10 @@
module RedmineDmsf
module Test
+
class HelperTest < ActiveSupport::TestCase
- fixtures :users, :email_addresses, :projects
+ fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles
# Allow us to override the fixtures method to implement fixtures for our plugin.
# Ultimately it allows for better integration without blowing redmine fixtures up,
@@ -45,11 +46,31 @@ module RedmineDmsf
def setup
@jsmith = User.find 2
+ @manager_role = Role.find_by(name: 'Manager')
+ @developer_role = Role.find_by(name: 'Developer')
+ [@manager_role, @developer_role].each do |role|
+ role.add_permission! :view_dmsf_folders
+ role.add_permission! :view_dmsf_files
+ end
@project1 = Project.find 1
- @folder1 = DmsfFolder.find 1
+ @project1.enable_module! :dmsf
+ Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.join(%w(files dmsf))
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = nil
Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'] = nil
+ Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.join(%w(files dmsf))
+ FileUtils.cp_r File.join(File.expand_path('../fixtures/files', __FILE__), '.'), DmsfFile.storage_path
end
+
+ def teardown
+ # Delete our tmp folder
+ begin
+ FileUtils.rm_rf DmsfFile.storage_path
+ rescue => e
+ Rails.logger.error e.message
+ end
+ end
+
end
+
end
end
\ No newline at end of file
diff --git a/test/test_helper.rb b/test/test_helper.rb
index e0402280..689f3aab 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -27,4 +27,4 @@ require File.expand_path('../../../../test/test_helper', __FILE__)
require_relative 'test_case'
require_relative 'integration_test'
require_relative 'unit_test'
-require_relative 'helper_test'
\ No newline at end of file
+require_relative 'helper_test'
diff --git a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb
new file mode 100644
index 00000000..77af069f
--- /dev/null
+++ b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb
@@ -0,0 +1,402 @@
+# encoding: utf-8
+# frozen_string_literal: true
+#
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright © 2011-22 Karel Pičman
#{@file1.description}
", text + end + + def test_macro_dmsfdesc_no_permissions + @manager_role.remove_permission! :view_dmsf_files + rev = @file1.last_revision + rev.description = 'blabla' + rev.save + text = textilizable("{{dmsfdesc(#{@file1.id})}}") + assert_not_equal "#{@file1.description}
", text + end + + def test_macro_dmsfdesc_dmsf_off + @project1.disable_module! :dmsf + rev = @file1.last_revision + rev.description = 'blabla' + rev.save + text = textilizable("{{dmsfdesc(#{@file1.id})}}") + assert_not_equal "#{@file1.description}
", text + end + + # {{dmsfversion(document_id)}} + def test_macro_dmsfdversion + text = textilizable("{{dmsfversion(#{@file1.id})}}") + assert_equal "#{@file1.version}
", text + end + + def test_macro_dmsfdversion_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsfversion(#{@file1.id})}}") + assert_not_equal "#{@file1.version}
", text + end + + def test_macro_dmsfdversion_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsfversion(#{@file1.id})}}") + assert_not_equal "#{@file1.version}
", text + end + + # {{dmsflastupdate(document_id)}} + def test_macro_dmsflastupdate + text = textilizable("{{dmsflastupdate(#{@file1.id})}}") + assert_equal "#{format_time(@file1.last_revision.updated_at)}
", text + end + + def test_macro_dmsflastupdate_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsflastupdate(#{@file1.id})}}") + assert_not_equal "#{format_time(@file1.last_revision.updated_at)}
", text + end + + def test_macro_dmsflastupdate_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsflastupdate(#{@file1.id})}}") + assert_not_equal "#{format_time(@file1.last_revision.updated_at)}
", text + end + + # {{dmsft(document_id)}} + def test_macro_dmsft + text = textilizable("{{dmsft(#{@file1.id}, 1)}}") + assert_equal "#{@file1.preview(1)}
", text + end + + def test_macro_dmsft_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsft(#{@file1.id}, 1)}}") + assert_not_equal "#{@file1.preview(1)}
", text + end + + def test_macro_dmsft_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsft(#{@file1.id}, 1)}}") + assert_not_equal "#{@file1.preview(1)}
", text + end + + # {{dmsf_image(file_id)}} + def test_macro_dmsf_image + text = textilizable("{{dmsf_image(#{@file7.id})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, size: nil) + assert_equal "#{link}
", text + end + + def test_macro_dmsf_image_size + size = '50%' + text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, width: size, height: size) + assert_equal "#{link}
", text + size = '300' + text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, width: size, height: size) + # TODO: arguments src and with and height are swapped + #assert_equal "#{link}
", text + size = '640x480' + text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, width: '640', height: '480') + # TODO: arguments src and with and height are swapped + #assert_equal "#{link}
", text + height = '480' + text = textilizable("{{dmsf_image(#{@file7.id}, height=#{height})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, width: 'auto', height: height) + assert_equal "#{link}
", text + width = '480' + text = textilizable("{{dmsf_image(#{@file7.id}, width=#{height})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, width: width, height: 'auto') + assert_equal "#{link}
", text + end + + def test_macro_dmsf_image_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsf_image(#{@file7.id})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, size: nil) + assert_not_equal "#{link}
", text + end + + def test_macro_dmsf_image_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsf_image(#{@file7.id})}}") + link = image_tag(view_dmsf_file_path(@file7), alt: @file7.title, size: nil) + assert_not_equal "#{link}
", text + end + + def test_macro_dmsf_image_not_image + text = textilizable("{{dmsf_image(#{@file1.id})}}") + assert text.include?('Not supported image format') + end + + # {{dmsf_video(file_id)}} + def test_macro_dmsf_video + text = textilizable("{{dmsf_video(#{@file6.id})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title) + assert_equal "#{link}
", text + end + + def test_macro_dmsf_image_size + size = '50%' + text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title, width: size, height: size) + assert_equal "#{link}
", text + size = '300' + text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title, width: size, height: size) + assert_equal "#{link}
", text + size = '640x480' + text = textilizable("{{dmsf_video(#{@file6.id}, size=#{size})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title, width: '640', height: '480') + assert_equal "#{link}
", text + height = '480' + text = textilizable("{{dmsf_video(#{@file6.id}, height=#{height})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title, width: 'auto', height: height) + assert_equal "#{link}
", text + width = '480' + text = textilizable("{{dmsf_video(#{@file6.id}, width=#{height})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title, width: width, height: 'auto') + assert_equal "#{link}
", text + end + + def test_macro_dmsf_image_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsf_video(#{@file6.id})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title) + assert_not_equal "#{link}
", text + end + + def test_macro_dmsf_image_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsf_video(#{@file6.id})}}") + link = video_tag(view_dmsf_file_path(@file6), controls: true, alt: @file6.title) + assert_not_equal "#{link}
", text + end + + def test_macro_dmsf_video_not_video + text = textilizable("{{dmsf_video(#{@file7.id})}}") + assert text.include?('Not supported video format'), text + end + + # {{dmsftn(file_id)}} + def test_macro_dmsftn + text = textilizable("{{dmsftn(#{@file7.id})}}") + url = view_dmsf_file_path(@file7) + img = image_tag(url, alt: @file7.title, width: 'auto', height: 200) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_equal "#{link}
", text + end + + def test_macro_dmsftn + url = view_dmsf_file_path(@file7) + size = '300' + text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}") + img = image_tag(url, alt: @file7.title, size: size) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_equal "#{link}
", text + size = '640x480' + text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}") + img = image_tag(url, alt: @file7.title, width: 640, height: 480) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + # TODO: arguments src and with and height are swapped + #assert_equal "#{link}
", text + height = '480' + text = textilizable("{{dmsftn(#{@file7.id}, height=#{height})}}") + img = image_tag(url, alt: @file7.title, width: 'auto', height: 480) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_equal "#{link}
", text + width = '640' + text = textilizable("{{dmsftn(#{@file7.id}, width=#{width})}}") + img = image_tag(url, alt: @file7.title, width: 640, height: 'auto') + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_equal "#{link}
", text + end + + def test_macro_dmsftn_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsftn(#{@file7.id})}}") + url = view_dmsf_file_path(@file7) + img = image_tag(url, alt: @file7.title, width: 'auto', height: 200) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_not_equal "#{link}
", text + end + + def test_macro_dmsftn_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsftn(#{@file7.id})}}") + url = view_dmsf_file_path(@file7) + img = image_tag(url, alt: @file7.title, width: 'auto', height: 200) + link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") + assert_not_equal "#{link}
", text + end + + def test_macro_dmsftn_not_image + text = textilizable("{{dmsftn(#{@file1.id})}}") + assert text.include?('Not supported image format') + end + + # {{dmsfw(file_id)}} + def test_macro_dmsfw + text = textilizable("{{dmsfw(#{@file1.id})}}") + assert_equal "#{@file1.last_revision.workflow_str(false)}
", text + end + + def test_macro_dmsfw_no_permissions + @manager_role.remove_permission! :view_dmsf_files + text = textilizable("{{dmsfw(#{@file1.id})}}") + assert text.include?('Error'), text + end + + def test_macro_dmsfw_dmsf_off + @project1.disable_module! :dmsf + text = textilizable("{{dmsfw(#{@file1.id})}}") + assert text.include?('Error'), text + end + +end