additionals/test/unit/additionals_macro_test.rb

63 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require File.expand_path '../../test_helper', __FILE__
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
@all_macros = Redmine::WikiFormatting::Macros.available_macros.map { |macro, _macro_options| macro.to_s }
end
def test_all
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros
assert_not_equal 0, available_macros.count
end
def test_all_with_only_names
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros only_names: true
2022-10-30 19:08:52 +03:00
2022-04-11 17:12:56 +03:00
assert_includes available_macros, 'child_pages'
end
def test_with_filter
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros filtered: ['child_pages'], only_names: true
2022-10-30 19:08:52 +03:00
2022-04-11 17:31:19 +03:00
assert_not_includes available_macros, 'child_pages'
for_two_macros_selection = @all_macros - %w[child_pages collapse] + ['', 'nonexistingmacro']
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros filtered: for_two_macros_selection, only_names: true
# -1 (hello world is always removed)
assert_equal %w[child_pages collapse], available_macros
end
def test_with_filter_all
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros filtered: @all_macros, only_names: true
2022-10-30 19:08:52 +03:00
assert_equal 0, available_macros.count
end
def test_with_controller_limit
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros only_names: true, controller_only: 'issue'
2022-10-30 19:08:52 +03:00
2022-04-11 17:31:19 +03:00
assert_not_includes available_macros, 'child_pages'
2023-09-10 13:14:42 +03:00
available_macros = AdditionalsMacro.macros only_names: true, controller_only: 'wiki'
2022-10-30 19:08:52 +03:00
2022-04-11 17:12:56 +03:00
assert_includes available_macros, 'child_pages'
end
end