Project

General

Profile

Defect #13119 ยป tc_redmine_defects.rb

testcases for the defect - Thomas Kohler, 2013-02-10 21:07

 
1
require File.dirname(__FILE__) + '/../test_helper.rb'
2

    
3
class TcRedmineDefects < ActiveSupport::TestCase
4
  
5
  
6
  def test_for_defect_13119_badcase1
7
    #http://www.redmine.org/issues/13119
8
    new_tracker = create_tracker("Tracker13119")
9
    new_project = create_project("Project for test defect 13119")
10
    new_user = create_user("Login13119")
11
    new_issue = create_issue("Issue for test the defect 13119", new_tracker, new_project, new_user)
12
    #create the custom field for the issue
13
    new_issue_custom_field = create_issue_custom_field("RPUID_for_bugfixtest", new_issue)
14
    #set the value
15
    the_value = "RPUID"
16
    new_issue.custom_field_values={new_issue_custom_field.id => the_value}
17
    new_issue.custom_values
18
    new_issue.save_custom_field_values
19
    #make the test
20
    assert_equal(true, !new_issue.custom_values.empty?, "bug found: http://www.redmine.org/issues/13119")
21
    cu_fi_val = new_issue.custom_field_values.detect {|cfv| cfv.custom_field == new_issue_custom_field}
22
    assert_equal(the_value, cu_fi_val.value, "Something went wrong for the value!")
23
  end
24
  
25
  def test_for_defect_13119_badcase2
26
    #http://www.redmine.org/issues/13119
27
    new_tracker = create_tracker("Tracker13119")
28
    new_project = create_project("Project for test defect 13119")
29
    new_user = create_user("Login13119")
30
    new_issue = create_issue("Issue for test the defect 13119", new_tracker, new_project, new_user)
31
    #create the custom field for the issue
32
    new_issue_custom_field = create_issue_custom_field("RPUID_for_bugfixtest", new_issue)
33
    #set the value
34
    the_value = "RPUID"
35
    new_issue.custom_field_values={new_issue_custom_field.id => the_value}
36
    new_issue.save_custom_field_values
37
    new_issue.custom_values
38
    #make the test
39
    assert_equal(true, !new_issue.custom_values.empty?, "bug found: http://www.redmine.org/issues/13119")
40
    cu_fi_val = new_issue.custom_field_values.detect {|cfv| cfv.custom_field == new_issue_custom_field}
41
    assert_equal(the_value, cu_fi_val.value, "Something went wrong for the value!")
42
  end
43
  
44
  def test_for_defect_13119_goodcase1
45
    #http://www.redmine.org/issues/13119
46
    new_tracker = create_tracker("Tracker13119")
47
    new_project = create_project("Project for test defect 13119")
48
    new_user = create_user("Login13119")
49
    new_issue = create_issue("Issue for test the defect 13119", new_tracker, new_project, new_user)
50
    #create the custom field for the issue
51
    new_issue_custom_field = create_issue_custom_field("RPUID_for_bugfixtest", new_issue)
52
    #set the value
53
    new_issue.reset_custom_values!
54
    the_value = "RPUID"
55
    new_issue.custom_field_values={new_issue_custom_field.id => the_value}
56
    new_issue.custom_values
57
    new_issue.save_custom_field_values
58
    #make the test
59
    assert_equal(true, !new_issue.custom_values.empty?, "bug found: http://www.redmine.org/issues/13119")
60
    cu_fi_val = new_issue.custom_field_values.detect {|cfv| cfv.custom_field == new_issue_custom_field}
61
    assert_equal(the_value, cu_fi_val.value, "Something went wrong for the value!")
62
  end
63
  
64
  def test_for_defect_13119_goodcase2
65
    #http://www.redmine.org/issues/13119
66
    new_tracker = create_tracker("Tracker13119")
67
    new_project = create_project("Project for test defect 13119")
68
    new_user = create_user("Login13119")
69
    new_issue = create_issue("Issue for test the defect 13119", new_tracker, new_project, new_user)
70
    #create the custom field for the issue
71
    new_issue_custom_field = create_issue_custom_field("RPUID_for_bugfixtest", new_issue)
72
    #set the value
73
    new_issue.reset_custom_values!
74
    the_value = "RPUID"
75
    new_issue.custom_field_values={new_issue_custom_field.id => the_value}
76
    new_issue.save_custom_field_values
77
    new_issue.custom_values
78
    #make the test
79
    #assert_not_nil(cu_fi_val, "bug found: http://www.redmine.org/issues/13119")
80
    assert_equal(true, !new_issue.custom_values.empty?, "bug found: http://www.redmine.org/issues/13119")
81
    cu_fi_val = new_issue.custom_field_values.detect {|cfv| cfv.custom_field == new_issue_custom_field}
82
    assert_equal(the_value, cu_fi_val.value, "Something went wrong for the value!")
83
  end
84

    
85
  private
86
    
87
  def create_tracker(the_name)
88
    new_tracker = Tracker.find_by_name(the_name)
89
    if new_tracker!=nil
90
      Tracker.find_by_id(new_tracker.id).delete
91
    end
92
    new_tracker = Tracker.create(:name=>the_name, :is_in_roadmap=>"1")
93
    Role.find(:all).each do |role|
94
      #copy workflow from first tracker:
95
      Workflow.copy(Tracker.find(:first), role, new_tracker, role)
96
    end
97
    return new_tracker
98
  end
99
  
100
  def create_project_custom_field(the_name)
101
    new_project_custom_field = ProjectCustomField.find_by_name(the_name)
102
    if new_project_custom_field != nil
103
      ProjectCustomField.find_by_id(new_project_custom_field.id).delete
104
    end
105
    new_project_custom_field = ProjectCustomField.new 
106
    new_project_custom_field.name = the_name
107
    new_project_custom_field.field_format = "string"
108
    new_project_custom_field.default_value = ""
109
    new_project_custom_field.min_length = "0"
110
    new_project_custom_field.max_length = "0"
111
    new_project_custom_field.possible_values = ""
112
    new_project_custom_field.searchable = "1"
113
    new_project_custom_field.is_required = "0"
114
    new_project_custom_field.regexp = ""
115
    new_project_custom_field.visible = "1"
116
    assert_equal(true,new_project_custom_field.save, "new_project_custom_field not saved correctly!")
117
    return new_project_custom_field
118
  end
119
  
120
  def create_project(the_description)
121
    #create the custom field for the project (optional)
122
    new_project_custom_field = create_project_custom_field("RPUID_for_bugfixtest")
123
    #prepare the project
124
    enabled_module_names = Array.new
125
    EnabledModule.find(:all).each {|m| enabled_module_names.push(m[:name])}
126
    enabled_module_names.uniq!
127
    trackers = Tracker.find(:all)
128
    #the project itself
129
    new_project = Project.find_by_description(the_description)
130
    if new_project != nil
131
      Project.find_by_id(new_project.id).delete
132
    end      
133
    new_project = Project.new
134
    new_project.description=the_description
135
    new_project.identifier = "pft"
136
    new_project.name = "Pft name"
137
    new_project.trackers = trackers
138
    new_project.enabled_module_names = enabled_module_names
139
    new_project.issue_custom_field_ids= [""]
140
    new_project.is_public = "0"
141
    new_project.custom_field_values={new_project_custom_field.id => "{0815-13119}"}            
142
    assert_equal(true,new_project.save, "new_project not saved correctly!")
143
    return new_project
144
  end
145
  
146
  def create_user(the_login)
147
    new_user = User.find_by_login(the_login)
148
    if new_user!=nil
149
      User.find_by_id(new_user.id).delete
150
    end
151
    new_user = User.new()
152
    new_user[:login] = the_login
153
    new_user[:mail] = "usr4test@test.de"
154
    new_user[:admin] = false
155
    new_user[:firstname] = "Firstname4Test"
156
    new_user[:lastname] = "Lastname4Test"
157
    assert_equal(true, new_user.save,"new_user not saved correctly!")
158
    return new_user
159
  end
160
  
161
  def create_issue(the_subject, new_tracker, new_project, new_user)
162
    new_issue = Issue.find_by_subject(the_subject)
163
    if new_issue != nil
164
      Issue.find_by_id(new_issue.id).delete
165
    end
166
    new_issue = Issue.new
167
    new_issue.subject = the_subject
168
    new_issue.description = "Issue for test of an defect."
169
    new_issue.status = IssueStatus.default
170
    new_issue.priority = IssuePriority.default
171
    new_issue.category = IssueCategory.find(:all)[0]
172
    new_issue.author = new_user #User.current --> problems with anonymous user
173
    new_issue.done_ratio = 0
174
    new_issue.project = new_project
175
    new_issue.tracker = new_tracker
176
    assert_equal(true, new_issue.save, "new_issue not saved correctly!")
177
    return new_issue
178
  end
179
  
180
  def create_issue_custom_field(the_name, new_issue)
181
    new_issue_custom_field = IssueCustomField.find_by_name(the_name)
182
    if new_issue_custom_field != nil
183
      IssueCustomField.find_by_id(new_issue_custom_field.id).delete
184
    end
185
    new_issue_custom_field = IssueCustomField.new 
186
    new_issue_custom_field.name = the_name
187
    new_issue_custom_field.field_format = "string"
188
    new_issue_custom_field.default_value = ""
189
    new_issue_custom_field.min_length = "0"
190
    new_issue_custom_field.max_length = "0"
191
    new_issue_custom_field.possible_values = ""
192
    new_issue_custom_field.trackers = Array.new
193
    new_issue_custom_field.searchable = "1"
194
    new_issue_custom_field.is_required = "0"
195
    new_issue_custom_field.regexp = ""
196
    new_issue_custom_field.is_for_all = "0"
197
    new_issue_custom_field.is_filter = "1"
198
    assert_equal(true,new_issue_custom_field.save, "new_issue_custom_field not saved correctly!")
199
    if !new_issue_custom_field.trackers.include?(new_issue.tracker)
200
      new_issue_custom_field.trackers.push(new_issue.tracker)
201
      assert_equal(true,new_issue_custom_field.save, "new_issue_custom_field not saved correctly at trackers!")
202
    end
203
    if !new_issue_custom_field.projects.include?(new_issue.project)
204
      new_issue_custom_field.projects.push(new_issue.project)
205
      assert_equal(true,new_issue_custom_field.save, "new_issue_custom_field not saved correctly at projects!")
206
    end
207
    return new_issue_custom_field
208
  end
209
  
210
end
    (1-1/1)