forked from bugzilla/extensions-Testopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr_new_run.cgi
executable file
·145 lines (129 loc) · 5 KB
/
tr_new_run.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Test Runner System.
#
# The Initial Developer of the Original Code is Maciej Maczynski.
# Portions created by Maciej Maczynski are Copyright (C) 2001
# Maciej Maczynski. All Rights Reserved.
#
# Contributor(s): Greg Hendricks <[email protected]>
use strict;
use lib qw(. lib);
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Util;
use Bugzilla::User;
BEGIN { Bugzilla->extensions }
use Bugzilla::Extension::Testopia::Util;
use Bugzilla::Extension::Testopia::TestRun;
use Bugzilla::Extension::Testopia::Search;
use Bugzilla::Extension::Testopia::Constants;
###############################################################################
# tr_new_run.cgi
# Presents a webform to the user for the creation of a new test run.
#
# INTERFACE:
# plan_id: The id of the plan this run will belong to.
# If no plan_id is found, the user will first
# be presented with a form to select a plan.
#
# action: undef - Present form for new run creation
# "Add" - Form has been submitted with run data. Create the test
# run.
#
################################################################################
my $vars = {};
my $template = Bugzilla->template;
Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi;
Bugzilla->error_mode(ERROR_MODE_AJAX) if $cgi->referer() && $cgi->referer() !~ /tr_new_run/;
print $cgi->header;
my $action = $cgi->param('action') || '';
my $plan_id = $cgi->param('plan_id');
unless ($plan_id){
$vars->{'form_action'} = 'tr_new_run.cgi';
$vars->{'type'} = "Run";
$template->process("testopia/plan/choose.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
validate_test_id($plan_id, 'plan');
my $plan = Bugzilla::Extension::Testopia::TestPlan->new($plan_id);
# Users need write permission on the plan in order to create a test run for
# that plan. See tr_plan_access.cgi
ThrowUserError("testopia-create-denied", {'object' => 'Test Run', 'plan' => $plan}) unless ($plan->canedit);
if ($action eq 'add'){
my $prod_version = $cgi->param('prod_version') ? $cgi->param('prod_version') : $plan->product_version();
my $build = trim($cgi->param('build'));
my $env = trim($cgi->param('environment'));
if ($cgi->param('new_build')){
my $b = Bugzilla::Extension::Testopia::Build->create({
'name' => $cgi->param('new_build'),
'milestone' => '---',
'product_id' => $plan->product_id,
'description' => '',
'isactive' => 1,
});
$build = $b->id;
}
if ($cgi->param('new_env')){
my $e = Bugzilla::Extension::Testopia::Environment->create({
'name' => $cgi->param('new_env'),
'product_id' => $plan->product_id,
'isactive' => 1,
});
$env = $e->id;
}
my $run = Bugzilla::Extension::Testopia::TestRun->create({
'plan_id' => $plan->id,
'environment_id' => $env,
'build_id' => $build,
'product_version' => $prod_version,
'plan_text_version' => $plan->version,
'manager_id' => $cgi->param('manager'),
'summary' => $cgi->param('summary'),
'notes' => $cgi->param('notes') || '',
'target_pass' => $cgi->param('target_pass'),
'target_completion' => $cgi->param('target_completion'),
'status' => 1,
});
if ($cgi->param('getall')){
$cgi->delete_all;
$cgi->param('plan_id', $plan->id);
$cgi->param('current_tab', 'case');
$cgi->param('case_status', 'CONFIRMED');
$cgi->param('viewall', 1);
my $search = Bugzilla::Extension::Testopia::Search->new($cgi);
my $ref = Bugzilla->dbh->selectcol_arrayref($search->query);
foreach my $case_id (@$ref){
$run->add_case_run($case_id);
}
}
else {
foreach my $case_id (split(',', $cgi->param('case_ids'))){
$run->add_case_run($case_id);
}
}
print "{success: true, run_id: " . $run->id ."}";
}
####################
### Display Form ###
####################
else {
$vars->{'plan'} = $plan;
$vars->{'case'} = Bugzilla::Extension::Testopia::TestCase->new({});
$template->process("testopia/run/add.html.tmpl", $vars) ||
ThrowTemplateError($template->error());
}