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
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-2022  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require 'fileutils'
21
require File.expand_path('../../../../test_helper', __FILE__)
22

  
23
module PluginTest
24
  PLUGIN_DIR = Rails.root.join('public/plugin_assets/foo_plugin/')
25
  STYLESHEET_DIR = PLUGIN_DIR.join('stylesheets')
26

  
27
  class AssetWithContextTest < Redmine::IntegrationTest
28

  
29
    def setup
30
      Class.new(Redmine::Hook::ViewListener) do
31
        def view_layouts_base_html_head(context = {})
32
          context[:hook_caller].stylesheet_link_tag('foo', plugin: 'foo_plugin')
33
        end
34
      end
35
      FileUtils.mkdir_p STYLESHEET_DIR
36
      FileUtils.touch STYLESHEET_DIR.join('foo.css')
37
    end
38

  
39
    def teardown
40
      Redmine::Hook.clear_listeners
41
      FileUtils.rm_rf PLUGIN_DIR
42
    end
43

  
44
    def test_asset_preload
45
      get '/'
46
      assert @response.body.include?('plugin_assets/foo_plugin/stylesheets/foo.css')
47
      assert @response.header['Link'].include?('foo.css')
48
    end
49
  end
50

  
51
  class AssetWithoutContextTest < Redmine::IntegrationTest
52
    def setup
53
      Class.new(Redmine::Hook::ViewListener) do
54
        def view_layouts_base_html_head(context = {})
55
          stylesheet_link_tag('bar', plugin: 'foo_plugin')
56
        end
57
      end
58
      FileUtils.mkdir_p STYLESHEET_DIR
59
      FileUtils.touch STYLESHEET_DIR.join('bar.css')
60
    end
61

  
62
    def teardown
63
      Redmine::Hook.clear_listeners
64
      FileUtils.rm_rf PLUGIN_DIR
65
    end
66

  
67
    def test_asset_preload
68
      get '/'
69
      assert @response.body.include?('plugin_assets/foo_plugin/stylesheets/bar.css')
70
      assert_not @response.header['Link'].include?('bar.css')
71
    end
72
  end
73
end
(2-2/2)