From 1e3fa0013aab2f0e6924ca4aaa22a31f78b845f3 Mon Sep 17 00:00:00 2001 From: Takashi Kato Date: Wed, 5 Oct 2022 22:46:45 +0000 Subject: [PATCH] Add integration test --- test/integration/lib/redmine/plugin_test.rb | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/integration/lib/redmine/plugin_test.rb diff --git a/test/integration/lib/redmine/plugin_test.rb b/test/integration/lib/redmine/plugin_test.rb new file mode 100644 index 000000000..2e484c1de --- /dev/null +++ b/test/integration/lib/redmine/plugin_test.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2022 Jean-Philippe Lang +# +# 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. + +require 'fileutils' +require File.expand_path('../../../../test_helper', __FILE__) + +module PluginTest + PLUGIN_DIR = Rails.root.join('public/plugin_assets/foo_plugin/') + STYLESHEET_DIR = PLUGIN_DIR.join('stylesheets') + + class AssetWithContextTest < Redmine::IntegrationTest + + def setup + Class.new(Redmine::Hook::ViewListener) do + def view_layouts_base_html_head(context = {}) + context[:hook_caller].stylesheet_link_tag('foo', plugin: 'foo_plugin') + end + end + FileUtils.mkdir_p STYLESHEET_DIR + FileUtils.touch STYLESHEET_DIR.join('foo.css') + end + + def teardown + Redmine::Hook.clear_listeners + FileUtils.rm_rf PLUGIN_DIR + end + + def test_asset_preload + get '/' + assert @response.body.include?('plugin_assets/foo_plugin/stylesheets/foo.css') + assert @response.header['Link'].include?('foo.css') + end + end + + class AssetWithoutContextTest < Redmine::IntegrationTest + def setup + Class.new(Redmine::Hook::ViewListener) do + def view_layouts_base_html_head(context = {}) + stylesheet_link_tag('bar', plugin: 'foo_plugin') + end + end + FileUtils.mkdir_p STYLESHEET_DIR + FileUtils.touch STYLESHEET_DIR.join('bar.css') + end + + def teardown + Redmine::Hook.clear_listeners + FileUtils.rm_rf PLUGIN_DIR + end + + def test_asset_preload + get '/' + assert @response.body.include?('plugin_assets/foo_plugin/stylesheets/bar.css') + assert_not @response.header['Link'].include?('bar.css') + end + end +end -- 2.30.2