Project

General

Profile

Patch #37664 » 0002-Add-integration-test.patch

Takashi Kato, 2022-10-06 01:05

View differences:

test/integration/lib/redmine/plugin_test.rb
# 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-2/2)