2021-04-18 14:34:55 +03:00
# frozen_string_literal: true
2020-08-08 18:53:49 +03:00
require File . expand_path '../../test_helper' , __FILE__
2018-12-01 14:26:11 +03:00
class AdditionalsMacroTest < Additionals :: TestCase
fixtures :projects , :users , :members , :member_roles , :roles ,
:trackers , :projects_trackers ,
:enabled_modules ,
:issue_statuses , :issue_categories , :workflows ,
:enumerations ,
:issues , :journals , :journal_details ,
:custom_fields , :custom_fields_projects , :custom_fields_trackers , :custom_values ,
:time_entries
include Redmine :: I18n
def setup
prepare_tests
2018-12-07 04:07:12 +03:00
@all_macros = Redmine :: WikiFormatting :: Macros . available_macros . map { | macro , _macro_options | macro . to_s }
2018-12-01 14:26:11 +03:00
end
def test_all
available_macros = AdditionalsMacro . all
assert_not_equal 0 , available_macros . count
end
def test_all_with_only_names
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all only_names : true
2022-04-11 17:12:56 +03:00
assert_includes available_macros , 'child_pages'
2018-12-01 14:26:11 +03:00
end
2018-12-05 15:29:37 +03:00
def test_with_filter
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all filtered : [ 'child_pages' ] , only_names : true
2022-04-11 17:31:19 +03:00
assert_not_includes available_macros , 'child_pages'
2018-12-07 04:07:12 +03:00
for_two_macros_selection = @all_macros - %w[ child_pages collapse ] + [ '' , 'nonexistingmacro' ]
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all filtered : for_two_macros_selection , only_names : true
2018-12-07 04:07:12 +03:00
# -1 (hello world is always removed)
assert_equal %w[ child_pages collapse ] , available_macros
end
def test_with_filter_all
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all filtered : @all_macros , only_names : true
2018-12-07 04:07:12 +03:00
assert_equal 0 , available_macros . count
2018-12-01 14:26:11 +03:00
end
def test_with_controller_limit
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all only_names : true , controller_only : 'issue'
2022-04-11 17:31:19 +03:00
assert_not_includes available_macros , 'child_pages'
2018-12-01 14:26:11 +03:00
2021-04-18 14:34:55 +03:00
available_macros = AdditionalsMacro . all only_names : true , controller_only : 'wiki'
2022-04-11 17:12:56 +03:00
assert_includes available_macros , 'child_pages'
2018-12-01 14:26:11 +03:00
end
end