projects_helper_test.rb 2.7 KB
Newer Older
1 2
# frozen_string_literal: false

3
# Redmine - project management software
jplang's avatar
jplang committed
4
# Copyright (C) 2006-2017  Jean-Philippe Lang
5 6 7 8 9
#
# 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.
10
#
11 12 13 14
# 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.
15
#
16 17 18 19
# 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.

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

jplang's avatar
jplang committed
22
class ProjectsHelperTest < Redmine::HelperTest
23 24
  include ApplicationHelper
  include ProjectsHelper
jplang's avatar
jplang committed
25
  include ERB::Util
26
  include Rails.application.routes.url_helpers
27

28 29 30 31 32 33 34
  fixtures :projects, :trackers, :issue_statuses, :issues,
           :enumerations, :users, :issue_categories,
           :versions,
           :projects_trackers,
           :member_roles,
           :members,
           :groups_users,
jplang's avatar
jplang committed
35
           :enabled_modules
36 37 38 39

  def test_link_to_version_within_project
    @project = Project.find(2)
    User.current = User.find(1)
jplang's avatar
jplang committed
40
    assert_equal '<a title="07/01/2006" href="/versions/5">Alpha</a>', link_to_version(Version.find(5))
41 42 43 44
  end

  def test_link_to_version
    User.current = User.find(1)
45
    assert_equal '<a title="07/01/2006" href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5))
46 47 48 49 50 51
  end

  def test_link_to_version_without_effective_date
    User.current = User.find(1)
    version = Version.find(5)
    version.effective_date = nil
52
    assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(version)
53 54 55
  end

  def test_link_to_private_version
56
    assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5))
57 58 59 60 61
  end

  def test_link_to_version_invalid_version
    assert_equal '', link_to_version(Object)
  end
62

63 64 65 66
  def test_format_version_name_within_project
    @project = Project.find(1)
    assert_equal "0.1", format_version_name(Version.find(1))
  end
67

68
  def test_format_version_name
69
    assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
70 71
  end

72 73
  def test_format_version_name_for_system_version
    assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7))
74
  end
75

76 77
  def test_version_options_for_select_with_no_versions
    assert_equal '', version_options_for_select([])
78
    assert_equal '', version_options_for_select([], Version.find(1))
79
  end
80
end